Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest testing #133

Merged
merged 24 commits into from
Oct 1, 2018
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ccce11f
moved all the existing tests to Jest
didoo Sep 14, 2018
6ca983c
finalised Jest tests for “utils” removing assert dependency
didoo Sep 14, 2018
b8ca175
finalised Jest tests for “register” removing assert dependency + move…
didoo Sep 14, 2018
a6ea89e
finalised Jest tests for “transform” removing assert dependency + mov…
didoo Sep 14, 2018
0d76f8a
updated path for “service” files/folders
didoo Sep 14, 2018
145d51b
removed output folder
didoo Sep 14, 2018
04df754
updated the paths to ignore in the Jest config in package.json
didoo Sep 14, 2018
14693b0
finalised Jest tests for “clean” removing assert dependency + other s…
didoo Sep 14, 2018
cca0487
added “__output” to the list of folders ignored by Jest
didoo Sep 14, 2018
149982a
some tunings + more tests
didoo Sep 14, 2018
1682ec0
more tests cleanup
didoo Sep 14, 2018
a3ecf3e
fixed test for exportPlatform
didoo Sep 15, 2018
82ab444
fixed last tests, and now all tests are green!
didoo Sep 15, 2018
cc4eea0
Added first snapshot tests! Yay!
didoo Sep 15, 2018
c73d1d8
added mock for dates to avoid failing snapshots tests
didoo Sep 15, 2018
e42201f
updated tests
didoo Sep 15, 2018
5b86080
first attempt to fix the UTC date problem on CI
didoo Sep 28, 2018
990f913
second attempt to fix the UTC date problem on CI
didoo Sep 28, 2018
5b60aba
removed the TZ=UTC env environment to test if is really needed
didoo Sep 28, 2018
a0f4cd3
updated all the occurrences of new Date in the templates
didoo Sep 28, 2018
2845396
restored linting before running the tests suite
didoo Sep 28, 2018
9aaaa34
code style fix
didoo Sep 28, 2018
20ddb54
fixed wrong porting of the test for buildAllPlatforms
didoo Sep 28, 2018
598142c
Merge branch 'jest' into jest-testing
dbanksdesign Oct 1, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions test/configs/test.json → __tests__/__configs/test.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"source": ["test/properties/**/*.json"],
"source": ["__tests__/__properties/**/*.json"],
"platforms": {
"web": {
"transformGroup": "web",
"prefix": "smop",
"buildPath": "test/output/web/",
"buildPath": "__tests__/__output/web/",
"files": [
{
"destination": "_icons.css",
Expand All @@ -21,7 +21,7 @@
"scss": {
"transformGroup": "scss",
"prefix": "smop",
"buildPath": "test/output/scss/",
"buildPath": "__tests__/__output/scss/",
"files": [
{
"destination": "_icons.scss",
Expand All @@ -35,7 +35,7 @@
"less": {
"transformGroup": "less",
"prefix": "smop",
"buildPath": "test/output/less/",
"buildPath": "__tests__/__output/less/",
"files": [
{
"destination": "_icons.less",
Expand All @@ -48,7 +48,7 @@
},
"android": {
"transformGroup": "android",
"buildPath": "test/output/",
"buildPath": "__tests__/__output/",
"files": [
{
"destination": "android/colors.xml",
Expand All @@ -67,7 +67,7 @@
},
"ios": {
"transformGroup": "ios",
"buildPath": "test/output/ios/",
"buildPath": "__tests__/__output/ios/",
"files": [
{
"destination": "style_dictionary.plist",
Expand Down
2 changes: 1 addition & 1 deletion test/helpers.js → __tests__/__helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var fs = require('fs-extra');

module.exports = {
clearOutput: function() {
fs.emptyDirSync('test/output');
fs.emptyDirSync('__tests__/__output');
},

fileToJSON: function(path) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions __tests__/__properties/font.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"asset": {
"font": {
"icon": {
"value": "./test/__assets/fonts/scapp_icons-regular.ttf"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be "./tests/__assets/fonts/scapp_icons-regular.ttf" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmm. not sure exactly what that prop refers to. I can't find tests that use it or that TTF file. do you remember something about this test?

}
}
}
}
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions __tests__/__properties/images/flags/us.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"asset": {
"image": {
"flag": {
"us": {
"mdpi": {
"value": "__tests__/__assets/images/mdpi/flag_us_base.png"
},
"hdpi": {
"value": "__tests__/__assets/images/hdpi/flag_us_base.png"
},
"xhdpi": {
"value": "__tests__/__assets/images/xhdpi/flag_us_base.png"
},
"xxhdpi": {
"value": "__tests__/__assets/images/xxhdpi/flag_us_base.png"
}
}
}
}
}
}
File renamed without changes.
File renamed without changes.
40 changes: 40 additions & 0 deletions __tests__/buildAllPlatforms.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

var helpers = require('./__helpers');
var StyleDictionary = require('../index');

describe('buildAllPlatforms', () => {

beforeEach(() => {
helpers.clearOutput();
});

afterEach(() => {
helpers.clearOutput();
});

it('should work with json config', () => {
var StyleDictionaryExtended = StyleDictionary.extend(__dirname + '/__configs/test.json');
StyleDictionaryExtended.buildAllPlatforms();
expect(helpers.fileExists('./__tests__/__output/web/_icons.css')).toBeTruthy();
expect(helpers.fileExists('./__tests__/__output/android/colors.xml')).toBeTruthy();
});

it('should work with js config', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test isn't doing what it is intending to I don't think. We should be extending style dictionary with a js config file, like in the current test file: https://github.com/amzn/style-dictionary/blob/master/test/buildAllPlatforms.js

Copy link
Contributor Author

@didoo didoo Sep 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you're right. I didn't notice it was doing two different tests, one for a JSON and one for a JS config file.

I have fixed it in an upcoming commit, please check if it's ok now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

var StyleDictionaryExtended = StyleDictionary.extend(__dirname + '/__configs/test.js');
StyleDictionaryExtended.buildAllPlatforms();
expect(helpers.fileExists('./__tests__/__output/web/_icons.css')).toBeTruthy();
expect(helpers.fileExists('./__tests__/__output/android/colors.xml')).toBeTruthy();
});
});
59 changes: 59 additions & 0 deletions __tests__/buildFile.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

var buildFile = require('../lib/buildFile');
var helpers = require('./__helpers');

function format() {
return "hi";
}

describe('buildFile', () => {

beforeEach(() => {
helpers.clearOutput();
});

afterEach(() => {
helpers.clearOutput();
});

it('should error if format doesnt exist or isnt a function', () => {
expect(
buildFile.bind(null, '__tests__/__output/test.txt', {}, {}, {})
).toThrow('Please enter a valid file format');
expect(
buildFile.bind(null, '__tests__/__output/test.txt', [], {}, {})
).toThrow('Please enter a valid file format');
expect(
buildFile.bind(null, '__tests__/__output/test.txt', null, {}, {})
).toThrow('Please enter a valid file format');
});

it('should error if destination doesnt exist or isnt a string', () => {
expect(
buildFile.bind(null, {}, format, {}, {})
).toThrow('Please enter a valid destination');
expect(
buildFile.bind(null, [], format, {}, {})
).toThrow('Please enter a valid destination');
expect(
buildFile.bind(null, null, format, {}, {})
).toThrow('Please enter a valid destination');
});

it('should write to a file properly', () => {
buildFile('test.txt', format, {buildPath: '__tests__/__output/'}, {});
expect(helpers.fileExists('./__tests__/__output/test.txt')).toBeTruthy();
});
});
66 changes: 35 additions & 31 deletions test/buildFiles.js → __tests__/buildFiles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
* and limitations under the License.
*/

var assert = require('chai').assert,
expect = require('chai').expect,
helpers = require('./helpers'),
buildFiles = require('../lib/buildFiles');
var buildFiles = require('../lib/buildFiles');
var helpers = require('./__helpers');
var _ = require('lodash');

var dictionary = {
properties: {
Expand All @@ -26,7 +25,7 @@ var dictionary = {
var platform = {
files: [
{
destination: 'test/output/test.json',
destination: '__tests__/__output/test.json',
format: function(dictionary) {
return JSON.stringify(dictionary.properties)
}
Expand All @@ -35,7 +34,7 @@ var platform = {
};

var platformWithBuildPath = {
buildPath: 'test/output/',
buildPath: '__tests__/__output/',
files: [
{
destination: 'test.json',
Expand All @@ -47,7 +46,7 @@ var platformWithBuildPath = {
};

var platformWithFilter = {
buildPath: 'test/output/',
buildPath: '__tests__/__output/',
files: [
{
destination: 'test.json',
Expand All @@ -62,7 +61,7 @@ var platformWithFilter = {
};

var platformWithoutFormatter = {
buildPath: 'test/output/',
buildPath: '__tests__/__output/',
files: [
{
destination: 'test.json',
Expand All @@ -71,7 +70,7 @@ var platformWithoutFormatter = {
};

var platformWithBadBuildPath = {
buildPath: 'test/output',
buildPath: '__tests__/__output',
files: [
{
destination: 'test.json',
Expand All @@ -82,42 +81,47 @@ var platformWithBadBuildPath = {
]
};

describe('buildFiles', function() {
beforeEach(function() {
describe('buildFiles', () => {

beforeEach(() => {
helpers.clearOutput();
});

it('should throw if build path doesn\'t have a trailing slash', function() {
assert.throws(
afterEach(() => {
helpers.clearOutput();
});

it('should throw if build path doesn\'t have a trailing slash', () => {
expect(
buildFiles.bind(null, dictionary, platformWithBadBuildPath),
Error,
'Build path must end in a trailing slash or you will get weird file names.'
);
).toThrow('Build path must end in a trailing slash or you will get weird file names.');
});

it('should throw if template or formatter missing', function() {
assert.throws(
it('should throw if template or formatter missing', () => {
expect(
buildFiles.bind(null, dictionary, platformWithoutFormatter),
Error,
'Please supply a template or formatter'
);
).toThrow('Please supply a template or formatter');
});

it('should work without buildPath', function() {
it('should work without buildPath', () => {
buildFiles( dictionary, platform );
assert(helpers.fileExists('./test/output/test.json'));
expect(helpers.fileExists('./__tests__/__output/test.json')).toBeTruthy();
});

it('should work with buildPath', function() {
it('should work with buildPath', () => {
buildFiles( dictionary, platformWithBuildPath );
assert(helpers.fileExists('./test/output/test.json'));
expect(helpers.fileExists('./__tests__/__output/test.json')).toBeTruthy();
});

it('should work with a filter', function() {
buildFiles( dictionary, platformWithFilter );
assert(helpers.fileExists('./test/output/test.json'));
var output = require("./output/test.json")
expect(output).to.not.have.any.keys("foo")
expect(output).to.have.all.keys("bingo")
it('should work with a filter', () => {
buildFiles(dictionary, platformWithFilter);
expect(helpers.fileExists('./__tests__/__output/test.json')).toBeTruthy();
var output = require("./__output/test.json")
expect(output).toHaveProperty('bingo');
expect(output).not.toHaveProperty('foo');
_.each(output, function(property) {
expect(property.value).toBe('bango');
});
});

});
Loading