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

Merge Jest Branch #169

Merged
merged 9 commits into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["env"]
}
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
File renamed without changes.
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.
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"
}
}
}
}
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', () => {
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