Skip to content

Commit

Permalink
Merge Jest Branch (#169)
Browse files Browse the repository at this point in the history
* Jest testing (#133)

* moved all the existing tests to Jest
* finalised Jest tests for “utils” removing assert dependency
* finalised Jest tests for “register” removing assert dependency + moved tests under correct folder
* finalised Jest tests for “transform” removing assert dependency + moved tests under correct folder + removed extra file
* updated path for “service” files/folders
* removed output folder
* updated the paths to ignore in the Jest config in package.json
* finalised Jest tests for “clean” removing assert dependency + other small changes
* added “__output” to the list of folders ignored by Jest
* some tunings + more tests
* more tests cleanup
* fixed test for exportPlatform
* fixed last tests, and now all tests are green!
* Added first snapshot tests! Yay!
* added mock for dates to avoid failing snapshots tests
* updated tests
* first attempt to fix the UTC date problem on CI (reference: boblauer/MockDate#9)
* second attempt to fix the UTC date problem on CI
* removed the TZ=UTC env environment to test if is really needed
* updated all the occurrences of new Date in the templates
* restored linting before running the tests suite
* code style fix
* fixed wrong porting of the test for buildAllPlatforms

* test(all): Fix for all tests to match the date and remove of mockdate (#148)

inspiration jestjs/jest#2234

* test(javascript/es6): Add test for es6 (#149)

* test: add registerTemplate (#147)

* add tests for transform object (#151)

* add tests for transform object
* split up complex test in multiple smaller tests

* Jest flatten props (#163)

* Adding tests for lib/utils/flattenProperties.js (#146)

* Adding tests for lib/utils/flattenProperties.js

* update to use lodash sortby function

* update to use lodash sortby function

* Add babel-jest (#173)
  • Loading branch information
chazzmoney committed Oct 19, 2018
1 parent aa19668 commit 15c876d
Show file tree
Hide file tree
Showing 119 changed files with 10,938 additions and 6,096 deletions.
3 changes: 3 additions & 0 deletions .babelrc
@@ -0,0 +1,3 @@
{
"presets": ["env"]
}
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.
12 changes: 6 additions & 6 deletions test/configs/test.json → __tests__/__configs/test.json
@@ -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
File renamed without changes.
2 changes: 1 addition & 1 deletion test/helpers.js → __tests__/__helpers.js
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.
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.
File renamed without changes.
9 changes: 9 additions & 0 deletions __tests__/__properties/font.json
@@ -0,0 +1,9 @@
{
"asset": {
"font": {
"icon": {
"value": "./test/__assets/fonts/scapp_icons-regular.ttf"
}
}
}
}
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions __tests__/__properties/images/flags/us.json
@@ -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.
File renamed without changes.
40 changes: 40 additions & 0 deletions __tests__/buildAllPlatforms.test.js
@@ -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', () => {
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
@@ -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
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');
});
});

});

0 comments on commit 15c876d

Please sign in to comment.