From e11030886200d225e46e7588486024e2fd3dedea Mon Sep 17 00:00:00 2001 From: Danny Banks Date: Sun, 4 Dec 2016 19:38:02 -0800 Subject: [PATCH] Adding eslint, chai, removing should, fixing tests, fixing eslint errors --- .editorconfig | 13 ++++ .eslintrc.json | 15 +++++ CHANGELOG.md | 0 CONTRIBUTING.md | 7 +++ NOTICE | 2 + index.js | 4 +- lib/buildFile.js | 8 +-- lib/common/actions.js | 4 +- lib/common/formats.js | 37 ++++------- lib/common/templates.js | 14 ++--- lib/common/transformGroups.js | 12 ++-- lib/common/transforms.js | 37 ++++++----- lib/transform/config.js | 13 ++-- lib/utils/deepExtend.js | 2 +- lib/utils/resolveObject.js | 17 +++-- package.json | 34 +++++++--- test/buildAllPlatforms.js | 7 +-- test/buildFile.js | 17 +++-- test/buildFiles.js | 108 +++++++++++++++----------------- test/buildPlatform.js | 25 ++++---- test/configs/test.json | 3 - test/extend.js | 49 ++++++++------- test/index.js | 6 ++ test/performAction.js | 5 +- test/property.js | 11 ++-- test/propertySetup.js | 47 ++++++-------- test/registerAction.js | 111 ++++++++++++++++++--------------- test/registerFormat.js | 93 +++++++++++++++------------ test/registerTransform.js | 58 ++++++++--------- test/registerTransformGroup.js | 81 +++++++++++------------- test/test.js | 8 --- test/transforms.js | 35 +++++------ test/utils/combineJSON.js | 32 ++++------ test/utils/convertToBase64.js | 13 ++-- test/utils/deepExtend.js | 23 ++++--- test/utils/resolveObject.js | 104 ++++++++++++++++-------------- 36 files changed, 536 insertions(+), 519 deletions(-) create mode 100644 .editorconfig create mode 100644 .eslintrc.json create mode 100644 CHANGELOG.md create mode 100644 CONTRIBUTING.md create mode 100644 NOTICE create mode 100644 test/index.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..da0310f51 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +# editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 000000000..79f1739be --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,15 @@ +{ + "env": { + "node": true, + "mocha": true + }, + "globals": { + "Buffer": true, + "escape": true + }, + "extends": "eslint:recommended", + "rules": { + "no-console": 0, + "no-unused-vars": 1 + } +} diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..e69de29bb diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..2669fe4da --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,7 @@ +# Contributing to the Style Dictionary + +TBD + +# What transforms/transform groups/formats/templates should be included? + +TBD diff --git a/NOTICE b/NOTICE new file mode 100644 index 000000000..b63bf988e --- /dev/null +++ b/NOTICE @@ -0,0 +1,2 @@ +Style Dictionary +Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. \ No newline at end of file diff --git a/index.js b/index.js index 6a6fd893b..a1ca51343 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ module.exports = { properties: {}, allProperties: [], defaultBuildPath: 'build/', - + transform: require('./lib/common/transforms'), transformGroup: require('./lib/common/transformGroups'), format: require('./lib/common/formats'), @@ -20,4 +20,4 @@ module.exports = { buildAllPlatforms: require('./lib/buildAllPlatforms'), extend: require('./lib/extend') -}; +}; \ No newline at end of file diff --git a/lib/buildFile.js b/lib/buildFile.js index 6e6de6ca8..90a94c97c 100644 --- a/lib/buildFile.js +++ b/lib/buildFile.js @@ -18,10 +18,10 @@ function buildFile(destination, format, platform, dictionary) { if (!destination) throw new Error('Please enter a valid destination'); - // platform.buildPath should always exist, - // if it is not defined in the config, a default - // one is added to the platform config. - destination = platform.buildPath + destination; + // if there is a build path, prepend the destination with it + if (platform.buildPath) { + destination = platform.buildPath + destination; + } var dirname = path.dirname(destination); if (!fs.existsSync(dirname)) diff --git a/lib/common/actions.js b/lib/common/actions.js index 27469aeeb..3964ec749 100644 --- a/lib/common/actions.js +++ b/lib/common/actions.js @@ -3,7 +3,7 @@ var _ = require('lodash'), module.exports = { - "android/copyImages": function(dictionary, config) { + 'android/copyImages': function(dictionary, config) { var imagesDir = config.buildPath + 'android/main/res/drawable-'; _.each(dictionary.allProperties, function(prop) { if (prop.attributes.category === 'asset' && prop.attributes.type === 'image') { @@ -13,7 +13,7 @@ module.exports = { }); }, - "copy_assets": function(dictionary, config) { + 'copy_assets': function(dictionary, config) { console.log('Copying assets directory'); fs.copySync('assets', config.buildPath + 'assets'); } diff --git a/lib/common/formats.js b/lib/common/formats.js index fa38f2c8b..b58b6b04c 100644 --- a/lib/common/formats.js +++ b/lib/common/formats.js @@ -1,11 +1,8 @@ -var _ = require('lodash'), - convertToBase64 = require('../utils/convertToBase64'); -var font_before = "@font-face {font-family: 'scapp_iconsregular'; src: url(data:application/x-font-ttf;charset=utf-8;base64,"; -var font_after = ") format('truetype'); font-weight: normal; font-style: normal; }"; -var module_def = "module.exports = "; +var _ = require('lodash'); +var module_def = 'module.exports = '; module.exports = { - "scss/variables": function(dictionary) { + 'scss/variables': function(dictionary) { var to_ret; return _.map(dictionary.allProperties, function (prop) { if (prop.attributes.category !== 'asset') { @@ -18,7 +15,7 @@ module.exports = { }).join('\n'); }, - "scss/icons": function(dictionary, config) { + 'scss/icons': function(dictionary, config) { return _.chain(dictionary.allProperties) .filter(function(prop) { return prop.attributes.category === 'content' && prop.attributes.type === 'icon'; @@ -32,23 +29,11 @@ module.exports = { .value().join('\n'); }, - "scss/font": function(dictionary) { - return _.chain(dictionary.allProperties) - .filter(function(prop) { - return prop.attributes.category === 'asset' && prop.attributes.type === 'font'; - }) - .map(function(prop) { - return font_before + convertToBase64(prop.value) + font_after; - }) - .value().join('\n'); - }, - - - "javascript/module": function(dictionary) { + 'javascript/module': function(dictionary) { return module_def + JSON.stringify(dictionary.properties) + ';'; }, - "javascript/object": function(dictionary, config) { + 'javascript/object': function(dictionary, config) { return 'var ' + config.jsVariableName + ' = ' + @@ -56,18 +41,18 @@ module.exports = { ';'; }, - "json": function(dictionary) { + 'json': function(dictionary) { return JSON.stringify(dictionary.properties, null, 2); }, - "json/asset": function(dictionary) { + 'json/asset': function(dictionary) { return JSON.stringify({asset: dictionary.properties.asset}, null, 2); }, - "sketch/palette": function(dictionary, config) { + 'sketch/palette': function(dictionary) { var to_ret = { - "compatibleVersion":"1.0", - "pluginVersion":"1.1" + 'compatibleVersion':'1.0', + 'pluginVersion':'1.1' }; to_ret.colors = _.chain(dictionary.allProperties) .filter(function(prop) { diff --git a/lib/common/templates.js b/lib/common/templates.js index 77310b123..95eb48d22 100644 --- a/lib/common/templates.js +++ b/lib/common/templates.js @@ -10,11 +10,11 @@ var androidColors = fs.readFileSync(__dirname + '/templates/android/colors.t iosPlist = fs.readFileSync(__dirname + '/templates/ios/plist.template'); module.exports = { - "android/colors": _.template(androidColors), - "android/dimens": _.template(androidDimens), - "android/fontDimens": _.template(androidFontDimens), - "android/integers": _.template(androidIntegers), - "android/strings": _.template(androidStrings), - "ios/headers": _.template(iosHeaders), - "ios/plist": _.template(iosPlist) + 'android/colors': _.template(androidColors), + 'android/dimens': _.template(androidDimens), + 'android/fontDimens': _.template(androidFontDimens), + 'android/integers': _.template(androidIntegers), + 'android/strings': _.template(androidStrings), + 'ios/headers': _.template(iosHeaders), + 'ios/plist': _.template(iosPlist) }; diff --git a/lib/common/transformGroups.js b/lib/common/transformGroups.js index 4a6c9d51b..b81711c78 100644 --- a/lib/common/transformGroups.js +++ b/lib/common/transformGroups.js @@ -1,35 +1,35 @@ module.exports = { - "web": [ + 'web': [ 'attribute/cti', 'name/cti/kebab', 'size/px' ], - "scss": [ + 'scss': [ 'attribute/cti', 'name/cti/kebab', 'time/seconds', 'content/icon', 'size/px' ], - "html": [ + 'html': [ 'attribute/cti', 'attribute/color', 'name/human' ], - "android": [ + 'android': [ 'attribute/cti', 'name/cti/snake', 'color/hex', 'size/sp', 'size/dp' ], - "ios": [ + 'ios': [ 'attribute/cti', 'attribute/color', 'name/cti/constant', 'color/rgb_array' ], - "assets": [ + 'assets': [ 'attribute/cti' ] }; diff --git a/lib/common/transforms.js b/lib/common/transforms.js index 58ad7f966..6c50bcfa8 100644 --- a/lib/common/transforms.js +++ b/lib/common/transforms.js @@ -1,7 +1,6 @@ var Color = require('color'), _ = require('lodash'), - path = require('path'), - convertToBase64 = require('../utils/convertToBase64'); + convertToBase64 = require('../utils/convertToBase64'), UNICODE_PATTERN = /\&\#x([^;]+)\;/g; function isColor(prop) { @@ -9,7 +8,7 @@ function isColor(prop) { } module.exports = { - "attribute/color": { + 'attribute/color': { type: 'attribute', matcher: function (prop) { return prop.attributes.category === 'color' && prop.value.indexOf('{') < 0; @@ -28,7 +27,7 @@ module.exports = { } }, - "attribute/cti": { + 'attribute/cti': { type: 'attribute', matcher: function() { return true; }, transformer: function(prop) { @@ -42,7 +41,7 @@ module.exports = { } }, - "name/human": { + 'name/human': { type: 'name', transformer: function(prop) { return [ @@ -52,35 +51,35 @@ module.exports = { } }, - "name/cti/camel": { + 'name/cti/camel': { type: 'name', transformer: function(prop, options) { return _.camelCase( [options.prefix].concat(prop.path).join(' ') ); } }, - "name/cti/kebab": { + 'name/cti/kebab': { type: 'name', transformer: function(prop, options) { return _.kebabCase([options.prefix].concat(prop.path).join(' ')); } }, - "name/cti/snake": { + 'name/cti/snake': { type: 'name', transformer: function(prop, options) { return _.snakeCase( [options.prefix].concat(prop.path).join(' ') ); } }, - "name/cti/constant": { + 'name/cti/constant': { type: 'name', transformer: function(prop, options) { return _.snakeCase( [options.prefix].concat(prop.path).join(' ') ).toUpperCase(); } }, - "color/rgb": { + 'color/rgb': { type: 'value', matcher: isColor, transformer: function (prop) { @@ -88,7 +87,7 @@ module.exports = { } }, - "color/rgb_array": { + 'color/rgb_array': { type: 'value', matcher: isColor, transformer: function (prop) { @@ -96,7 +95,7 @@ module.exports = { } }, - "color/hex": { + 'color/hex': { type: 'value', matcher: isColor, transformer: function (prop) { @@ -104,7 +103,7 @@ module.exports = { } }, - "size/sp": { + 'size/sp': { type: 'value', matcher: function(prop) { return prop.attributes.category === 'size' && @@ -115,7 +114,7 @@ module.exports = { } }, - "size/dp": { + 'size/dp': { type: 'value', matcher: function(prop) { return prop.attributes.category === 'size' && @@ -127,7 +126,7 @@ module.exports = { } }, - "size/px": { + 'size/px': { type: 'value', matcher: function(prop) { return prop.attributes.category === 'size'; @@ -137,19 +136,19 @@ module.exports = { } }, - "content/icon": { + 'content/icon': { type: 'value', matcher: function (prop) { return prop.attributes.category === 'content' && prop.attributes.type === 'icon'; }, transformer: function (prop) { return prop.original.value.replace(UNICODE_PATTERN, function (match, variable) { - return "'\\" + variable + "'"; + return '\'\\' + variable + '\''; }); } }, - "time/seconds": { + 'time/seconds': { type: 'value', matcher: function(prop) { return prop.attributes.category === 'time'; @@ -160,7 +159,7 @@ module.exports = { }, - "asset/base64": { + 'asset/base64': { type: 'value', matcher: function(prop) { return prop.attributes.category === 'asset'; diff --git a/lib/transform/config.js b/lib/transform/config.js index fe14d727d..32677a5e3 100644 --- a/lib/transform/config.js +++ b/lib/transform/config.js @@ -18,11 +18,11 @@ function transformConfig(config, dictionary) { // Transforms are an array of strings that map to functions on // the StyleDictionary module. We need to map the strings to // the actual functions. - to_ret.transforms = _.map(transforms, function(name){ + to_ret.transforms = _.map(transforms, function(name) { return dictionary.transform[name]; }); - to_ret.files = _.map(config.files, function(file){ + to_ret.files = _.map(config.files, function(file) { if (file.template) { return _.extend({}, file, {template: dictionary.template[file.template]}); } else if (file.format) { @@ -30,16 +30,11 @@ function transformConfig(config, dictionary) { } }); - to_ret.actions = _.map(config.actions, function(action){ + to_ret.actions = _.map(config.actions, function(action) { return dictionary.action[action]; }); - - // Add the default build path if one is not provided - if (!to_ret.buildPath) { - to_ret.buildPath = dictionary.defaultBuildPath; - } return to_ret; } -module.exports = transformConfig; \ No newline at end of file +module.exports = transformConfig; diff --git a/lib/utils/deepExtend.js b/lib/utils/deepExtend.js index 998ef9a84..9df33c3ee 100644 --- a/lib/utils/deepExtend.js +++ b/lib/utils/deepExtend.js @@ -12,7 +12,7 @@ function deepExtend(object) { length = arguments.length; // Handle case when target is a string or something (possible in deep copy) - if ( typeof target !== "object" ) { + if ( typeof target !== 'object' ) { target = {}; } diff --git a/lib/utils/resolveObject.js b/lib/utils/resolveObject.js index f74628739..b1c8375a6 100644 --- a/lib/utils/resolveObject.js +++ b/lib/utils/resolveObject.js @@ -6,13 +6,12 @@ var defaults = { closing_character: '}', separator: '.' }; -var original_object, updated_object, regex, options; +var updated_object, regex, options; function resolveObject(object, opts) { options = _.extend({}, defaults, opts); - original_object = object; // Keep the original object just in case updated_object = _.clone(object); // This object will be edited regex = new RegExp( @@ -40,10 +39,10 @@ function traverseObj(obj) { for (key in obj) { if (obj.hasOwnProperty(key)) { current_context.push(key); - if (typeof obj[key] === "object") { + if (typeof obj[key] === 'object') { traverseObj( obj[key] ); } else { - if (typeof obj[key] === "string" && obj[key].indexOf('{') > -1 ) { + if (typeof obj[key] === 'string' && obj[key].indexOf('{') > -1 ) { obj[key] = compile_value( obj[key] ); } } @@ -52,7 +51,7 @@ function traverseObj(obj) { } return obj; -}; +} @@ -61,7 +60,7 @@ function compile_value(value) { // Replace the reference inline, but don't replace the whole string because // references can be part of the value such as "1px solid {color.border.light}" - value.replace(regex, function(match, variable){ + value.replace(regex, function(match, variable) { // Find what the value is referencing ref = selfRef(variable, updated_object); @@ -86,7 +85,7 @@ function compile_value(value) { }); return to_ret; -}; +} function selfRef(string, obj) { @@ -113,11 +112,11 @@ function selfRef(string, obj) { var test = options.opening_character + context + options.closing_character; if (typeof ref === 'string' && ref.indexOf(test) > -1) { - throw new Error("Circular definition: " + context + ' | ' + string); + throw new Error('Circular definition: ' + context + ' | ' + string); } else { return ref; } -}; +} module.exports = resolveObject; diff --git a/package.json b/package.json index df5157306..16b6a144c 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,23 @@ "name": "style-dictionary", "version": "1.0.0", "description": "A node module to build a style dictionary package. A style dictionary consists of JSON files with the definitions of style properties like colors, typography, sizes, icons, etc. The style dictionary package also consists of a config.json which explains how to transform values (px -> pt, hex -> rgb, etc.) as well as what files to build.", + "keywords": [ + "style dictionary", + "style", + "dictionary", + "amazon", + "css", + "design", + "properties", + "tokens", + "sass", + "scss", + "iOS", + "Android", + "react", + "react native", + "style guide" + ], "main": "index.js", "bin": { "style-dictionary": "./bin/style-dictionary" @@ -17,23 +34,25 @@ "NOTICE" ], "scripts": { - "test": "mocha --recursive -c" + "lint": "eslint index.js lib/**/*.js test/**/*.js", + "test": "npm run lint && mocha --recursive -c" }, "repository": { "type": "git", - "url": "git+https://github.com/dbanksdesign/Style-Dictionary.git" + "url": "git://github.com/amznlabs/style-dictionary.git" }, - "author": "", + "author": "Amazon Labs", "license": "Apache-2.0", "bugs": { - "url": "https://github.com/dbanksdesign/Style-Dictionary/issues" + "url": "https://github.com/amznlabs/style-dictionary/issues" }, "contributors": [ "Yuliya Baran ", "Charles Dorner ", + "Dustin Boudreau ", "Danny Banks " ], - "homepage": "https://github.com/dbanksdesign/Style-Dictionary#readme", + "homepage": "https://github.com/amznlabs/style-dictionary", "dependencies": { "color": "^0.11.3", "commander": "^2.9.0", @@ -42,7 +61,8 @@ "lodash": "^4.16.4" }, "devDependencies": { - "mocha": "^3.1.2", - "should": "^11.1.1" + "chai": "^3.5.0", + "eslint": "^3.11.1", + "mocha": "^3.1.2" } } diff --git a/test/buildAllPlatforms.js b/test/buildAllPlatforms.js index 346f8bd92..d13eee325 100644 --- a/test/buildAllPlatforms.js +++ b/test/buildAllPlatforms.js @@ -1,5 +1,4 @@ -var assert = require('assert'), - should = require('should'), +var assert = require('chai').assert, helpers = require('./helpers'), StyleDictionary = require('../index'); @@ -14,7 +13,7 @@ describe('buildAllPlatforms', function() { it('should work', function() { test.buildAllPlatforms(); - helpers.fileExists('./test/output/web/_icons.scss').should.be.true; - helpers.fileExists('./test/output/android/colors.xml').should.be.true; + assert(helpers.fileExists('./test/output/web/_icons.scss')); + assert(helpers.fileExists('./test/output/android/colors.xml')); }); }); diff --git a/test/buildFile.js b/test/buildFile.js index 1c5086d73..4f319a591 100644 --- a/test/buildFile.js +++ b/test/buildFile.js @@ -1,5 +1,4 @@ -var assert = require('assert'), - should = require('should'), +var assert = require('chai').assert, helpers = require('./helpers'), buildFile = require('../lib/buildFile'); @@ -13,19 +12,19 @@ describe('buildFile', function() { }); it('should error if format doesnt exist or isnt a function', function() { - buildFile.bind('test/output/test.txt', {}, {}, {}).should.throw(); - buildFile.bind('test/output/test.txt', [], {}, {}).should.throw(); - buildFile.bind('test/output/test.txt', null, {}, {}).should.throw(); + assert.throws(buildFile.bind('test/output/test.txt', {}, {}, {})); + assert.throws(buildFile.bind('test/output/test.txt', [], {}, {})); + assert.throws(buildFile.bind('test/output/test.txt', null, {}, {})); }); it('should error if destination doesnt exist or isnt a string', function() { - buildFile.bind({}, format, {}, {}).should.throw(); - buildFile.bind([], format, {}, {}).should.throw(); - buildFile.bind(null, format, {}, {}).should.throw(); + assert.throws(buildFile.bind({}, format, {}, {})); + assert.throws(buildFile.bind([], format, {}, {})); + assert.throws(buildFile.bind(null, format, {}, {})); }); it('should write to a file properly', function() { buildFile('test.txt', format, {buildPath: 'test/output/'}, {}); - helpers.fileExists('./test/output/test.txt').should.be.true; + assert(helpers.fileExists('./test/output/test.txt')); }); }); diff --git a/test/buildFiles.js b/test/buildFiles.js index 8aa206ed5..99cc2f6b3 100644 --- a/test/buildFiles.js +++ b/test/buildFiles.js @@ -1,59 +1,49 @@ -//var assert = require('assert'), -// should = require('should'), -// helpers = require('./helpers'), -// StyleDictionary = require('../index'); -// -//// Test configs -//var config = helpers.fileToJSON('test/configs/test.json'); -//var test = StyleDictionary.create(config); -//var test2 = StyleDictionary.create({ -// "source": ["test/properties/**/*.json"], -// "platforms": { -// "web": { -// "transformGroup": "web", -// "prefix": "smop", -// "buildPath": "test/output/web/", -// "files": [ -// { -// "destination": "_icons.scss", -// "format": "scss/icons" -// },{ -// "destination": "_variables.scss", -// "format": "scss/variables" -// },{ -// "destination": "_icon_font.scss", -// "format": "scss/font" -// },{ -// "destination": "_styles.js", -// "format": "javascript/module" -// } -// ] -// } -// } -//}); -// -// -//describe('buildFiles', function() { -// beforeEach(function() { -// helpers.clearOutput(); -// }); -// -// -// it('should work', function() { -// //console.log(test); -// test.buildFiles( test.options.platforms.web, { -// properties: test.properties, -// allProperties: StyleDictionary.utils.flattenProperties( test.properties ) -// }); -// //helpers.fileExists('./test/output/web/_icons.scss').should.be.true; -// //helpers.fileExists('./test/output/web/_icon_font.scss').should.be.true; -// //helpers.fileExists('./test/output/web/_variables.scss').should.be.true; -// }); -// -// it('should work with buildPath', function() { -// //test2.buildFiles( test2.options.platforms.web, test ); -// //helpers.fileExists('./test/output/web/_icons.scss').should.be.true; -// //helpers.fileExists('./test/output/web/_icon_font.scss').should.be.true; -// //helpers.fileExists('./test/output/web/_variables.scss').should.be.true; -// }); -//}); +var assert = require('chai').assert, + helpers = require('./helpers'), + buildFiles = require('../lib/buildFiles'); + +var dictionary = { + properties: { + foo: 'bar' + } +}; + +var platform = { + files: [ + { + destination: 'test/output/test.json', + format: function(dictionary) { + return JSON.stringify(dictionary.properties) + } + } + ] +}; + +var platformWithBuildPath = { + buildPath: 'test/output/', + files: [ + { + destination: 'test.json', + format: function(dictionary) { + return JSON.stringify(dictionary.properties) + } + } + ] +}; + +describe('buildFiles', function() { + beforeEach(function() { + helpers.clearOutput(); + }); + + + it('should work without buildPath', function() { + buildFiles( dictionary, platform ); + assert(helpers.fileExists('./test/output/test.json')); + }); + + it('should work with buildPath', function() { + buildFiles( dictionary, platformWithBuildPath ); + assert(helpers.fileExists('./test/output/test.json')); + }); +}); diff --git a/test/buildPlatform.js b/test/buildPlatform.js index 1673ba75b..6de866ab5 100644 --- a/test/buildPlatform.js +++ b/test/buildPlatform.js @@ -1,6 +1,4 @@ -var assert = require('assert'), - should = require('should'), - fs = require('fs-extra'), +var assert = require('chai').assert, helpers = require('./helpers'), StyleDictionary = require('../index'); @@ -15,24 +13,23 @@ describe('buildPlatform', function() { it('should build the proper files', function() { test.buildPlatform('web'); - helpers.fileExists('./test/output/web/_icons.scss').should.be.true; - helpers.fileExists('./test/output/web/_icon_font.scss').should.be.true; - helpers.fileExists('./test/output/web/_styles.js').should.be.true; - helpers.fileExists('./test/output/web/_variables.scss').should.be.true; + assert(helpers.fileExists('./test/output/web/_icons.scss')); + assert(helpers.fileExists('./test/output/web/_styles.js')); + assert(helpers.fileExists('./test/output/web/_variables.scss')); }); it('should do android stuff', function() { test.buildPlatform('android'); - helpers.fileExists('./test/output/android/main/res/drawable-hdpi/flag_us.png').should.be.true; - helpers.fileExists('./test/output/android/main/res/drawable-xhdpi/flag_us.png').should.be.true; - helpers.fileExists('./test/output/android/colors.xml').should.be.true; - helpers.fileExists('./test/output/android/dimens.xml').should.be.true; - helpers.fileExists('./test/output/android/font_dimen.xml').should.be.true; + assert(helpers.fileExists('./test/output/android/main/res/drawable-hdpi/flag_us.png')); + assert(helpers.fileExists('./test/output/android/main/res/drawable-xhdpi/flag_us.png')); + assert(helpers.fileExists('./test/output/android/colors.xml')); + assert(helpers.fileExists('./test/output/android/dimens.xml')); + assert(helpers.fileExists('./test/output/android/font_dimen.xml')); }); it('should do ios stuff', function() { test.buildPlatform('ios'); - helpers.fileExists('./test/output/ios/style_dictionary.plist').should.be.true; - helpers.fileExists('./test/output/ios/style_dictionary.h').should.be.true; + assert(helpers.fileExists('./test/output/ios/style_dictionary.plist')); + assert(helpers.fileExists('./test/output/ios/style_dictionary.h')); }); }); diff --git a/test/configs/test.json b/test/configs/test.json index 1256c32c5..2903c458c 100644 --- a/test/configs/test.json +++ b/test/configs/test.json @@ -12,9 +12,6 @@ },{ "destination": "_variables.scss", "format": "scss/variables" - },{ - "destination": "_icon_font.scss", - "format": "scss/font" },{ "destination": "_styles.js", "format": "javascript/module" diff --git a/test/extend.js b/test/extend.js index 79fb39062..03b24d223 100644 --- a/test/extend.js +++ b/test/extend.js @@ -1,6 +1,6 @@ -var assert = require('assert'), - should = require('should'), +var assert = require('chai').assert, helpers = require('./helpers'), + _ = require('lodash'), StyleDictionary = require('../index'); var test_props = { @@ -16,14 +16,13 @@ describe('extend', function() { describe('method signature', function() { it('should accept a string as a path to a JSON file', function () { var test = StyleDictionary.extend(__dirname + '/configs/test.json'); - var platforms = helpers.fileToJSON(__dirname + '/configs/test.json').platforms; - test.platforms.should.have.properties(platforms); + assert.property(test.platforms, 'web'); }); it('should accept an object as options', function () { var config = helpers.fileToJSON(__dirname + '/configs/test.json'); var test = StyleDictionary.extend(config); - test.platforms.should.have.properties( config.platforms ); + assert.property(test.platforms, 'web'); }); it('should override attributes', function () { @@ -32,34 +31,36 @@ describe('extend', function() { foo: 'bar' } }); - test.properties.foo.should.eql('bar'); + assert.equal(test.properties.foo, 'bar'); }); - it('should return a copy of itself', function() { + it('should have all same properties', function() { var test = StyleDictionary.extend({}); - test.should.have.properties( StyleDictionary ); + _.each(_.keys(StyleDictionary), function(property) { + assert.property(test, property) + }); }); }); describe('includes', function() { it('should throw if include isnt an array', function() { - StyleDictionary.extend.bind({ - include: {} - }).should.throw(); + assert.throws( + StyleDictionary.extend.bind({include: {}}) + ); }); it('should throw if a path in the includes array doesnt resolve', function() { - StyleDictionary.extend.bind({ - include: ['foo'] - }).should.throw(); + assert.throws( + StyleDictionary.extend.bind({include: ['foo']}) + ); }); it('should update properties if there are includes', function () { var test = StyleDictionary.extend({ include: [__dirname + '/configs/include.json'] }); - test.properties.size.padding.tiny.should.be.and.Object; + assert.isObject(test.properties.size.padding.tiny); }); it('should override existing properties if there are includes', function () { @@ -67,29 +68,29 @@ describe('extend', function() { properties: test_props, include: [__dirname + '/configs/include.json'] }); - test.properties.size.padding.tiny.value.should.eql('3'); + assert.equal(test.properties.size.padding.tiny.value, '3'); }); }); describe('source', function() { it('should throw if source isnt an array', function() { - StyleDictionary.extend.bind({ - source: {} - }).should.throw(); + assert.throws( + StyleDictionary.extend.bind({source: {}}) + ); }); it('should throw if a path in the source array doesnt resolve', function() { - StyleDictionary.extend.bind({ - include: ['foo'] - }).should.throw(); + assert.throws( + StyleDictionary.extend.bind({include: ['foo']}) + ); }); it('should build the properties object if a source is given', function() { var test = StyleDictionary.extend({ "source": [__dirname + "/properties/paddings.json"] }); - test.properties.should.eql( helpers.fileToJSON(__dirname + "/properties/paddings.json") ); + assert.deepEqual(test.properties, helpers.fileToJSON(__dirname + "/properties/paddings.json")); }); it('should override existing properties source is given', function() { @@ -97,7 +98,7 @@ describe('extend', function() { properties: test_props, source: [__dirname + "/properties/paddings.json"] }); - test.properties.should.eql( helpers.fileToJSON(__dirname + "/properties/paddings.json") ); + assert.deepEqual(test.properties, helpers.fileToJSON(__dirname + "/properties/paddings.json")); }); }); diff --git a/test/index.js b/test/index.js new file mode 100644 index 000000000..a6066f58a --- /dev/null +++ b/test/index.js @@ -0,0 +1,6 @@ +var helpers = require('./helpers'); + +after(function() { + // runs after all tests + helpers.clearOutput(); +}); diff --git a/test/performAction.js b/test/performAction.js index 50e8ae51a..c9af48ebf 100644 --- a/test/performAction.js +++ b/test/performAction.js @@ -1,5 +1,4 @@ -var assert = require('assert'), - should = require('should'), +var assert = require('chai').assert, helpers = require('./helpers'), fs = require('fs-extra'), StyleDictionary = require('../index'); @@ -27,7 +26,7 @@ describe('buildPlatform', function() { it('should write to a file properly', function() { test.buildPlatform('android'); - fs.existsSync('./test/output/action.txt').should.be.true; + assert(helpers.fileExists('./test/output/action.txt')); }); }); }); diff --git a/test/property.js b/test/property.js index 06b6a66a3..2b990c395 100644 --- a/test/property.js +++ b/test/property.js @@ -1,7 +1,6 @@ -var assert = require('assert'), - should = require('should'), - helpers = require('./helpers'), - transformProperty = require('../lib/transform/property'); +var assert = require('chai').assert, + helpers = require('./helpers'), + transformProperty = require('../lib/transform/property'); var options = { @@ -29,8 +28,8 @@ var options = { describe('transformProperty', function() { it('should work', function() { var test = transformProperty({attributes:{baz:'blah'}}, options); - test.attributes.bar.should.eql('foo'); - test.name.should.eql('hello'); + assert.equal(test.attributes.bar, 'foo'); + assert.equal(test.name, 'hello'); }); // Add more tests diff --git a/test/propertySetup.js b/test/propertySetup.js index 9375d0c6d..b9be85a1a 100644 --- a/test/propertySetup.js +++ b/test/propertySetup.js @@ -1,31 +1,24 @@ -var assert = require('assert'), - should = require('should'), - propertySetup = require('../lib/transform/propertySetup'); +var assert = require('chai').assert, + propertySetup = require('../lib/transform/propertySetup'); describe('propertySetup', function() { it('should error if property is not an object', function() { - propertySetup.bind( - null, - 'foo', - [] - ).should.throw(); + assert.throws( + propertySetup.bind(null, 'foo', []) + ); }); it('should error if name in not a string', function() { - propertySetup.bind( - {}, - null, - [] - ).should.throw(); + assert.throws( + propertySetup.bind({}, null, []) + ); }); it('should error path is not an array', function() { - propertySetup.bind( - {}, - 'name', - null - ).should.throw(); + assert.throws( + propertySetup.bind({}, 'name', null) + ); }); @@ -35,11 +28,11 @@ describe('propertySetup', function() { "white", ["color","base"] ); - test.should.be.an.Object; - test.should.have.property('value').and.be.a.String; - test.should.have.property('original').and.be.an.Object; - test.should.have.property('attributes').and.be.an.Object; - test.should.have.property('path').and.be.an.Array; + assert.isObject(test); + assert.property(test, 'value'); + assert.property(test, 'original'); + assert.property(test, 'attributes'); + assert.property(test, 'path'); }); @@ -50,7 +43,7 @@ describe('propertySetup', function() { "white", ["color","base"] ); - test.should.eql(original); + assert.deepEqual(test, original); }); it('should use attributes if already set', function() { @@ -60,7 +53,7 @@ describe('propertySetup', function() { "white", ["color","base"] ); - test.attributes.should.eql(attributes); + assert.deepEqual(test.attributes, attributes); }); it('should use the name on the property if set', function() { @@ -70,7 +63,7 @@ describe('propertySetup', function() { 'white', ["color","base"] ); - test.name.should.eql(name); + assert.equal(test.name, name); }); it('should use the name passed in if not set on the property', function() { @@ -79,6 +72,6 @@ describe('propertySetup', function() { 'white', ["color","base"] ); - test.name.should.eql('white'); + assert.equal(test.name, 'white'); }); }); diff --git a/test/registerAction.js b/test/registerAction.js index a41d15f1d..f8e9a1ae3 100644 --- a/test/registerAction.js +++ b/test/registerAction.js @@ -1,54 +1,71 @@ -var assert = require('assert'), - should = require('should'), - StyleDictionary = require('../index'); +var assert = require('chai').assert, + StyleDictionary = require('../index').extend({}); describe('registerAction', function() { it('should error if name is not a string', function() { - StyleDictionary.registerAction.bind({ - action: function() {} - }).should.throw(); + assert.throws( + StyleDictionary.registerAction.bind({ + action: function() {} + }) + ); - StyleDictionary.registerAction.bind({ - name: 1, - action: function() {} - }).should.throw(); + assert.throws( + StyleDictionary.registerAction.bind({ + name: 1, + action: function() {} + }) + ); - StyleDictionary.registerAction.bind({ - name: [], - action: function() {} - }).should.throw(); + assert.throws( + StyleDictionary.registerAction.bind({ + name: [], + action: function() {} + }) + ); - StyleDictionary.registerAction.bind({ - name: {}, - action: function() {} - }).should.throw(); + assert.throws( + StyleDictionary.registerAction.bind({ + name: {}, + action: function() {} + }) + ); }); it('should error if formatter is not a function', function() { - StyleDictionary.registerAction.bind({ - name: 'test' - }).should.throw(); + assert.throws( + StyleDictionary.registerAction.bind({ + name: 'test' + }) + ); - StyleDictionary.registerAction.bind({ - name: 'test', - action: 1 - }).should.throw(); + assert.throws( + StyleDictionary.registerAction.bind({ + name: 'test', + action: 1 + }) + ); - StyleDictionary.registerAction.bind({ - name: 'test', - action: 'name' - }).should.throw(); + assert.throws( + StyleDictionary.registerAction.bind({ + name: 'test', + action: 'name' + }) + ); - StyleDictionary.registerAction.bind({ - name: 'test', - action: [] - }).should.throw(); + assert.throws( + StyleDictionary.registerAction.bind({ + name: 'test', + action: [] + }) + ); - StyleDictionary.registerAction.bind({ - name: 'test', - action: {} - }).should.throw(); + assert.throws( + StyleDictionary.registerAction.bind({ + name: 'test', + action: {} + }) + ); }); it('should work if name and formatter are good', function() { @@ -57,21 +74,11 @@ describe('registerAction', function() { action: function() {} }); - StyleDictionary.action['scss'].should.be.a.Function; + assert.isFunction(StyleDictionary.action['scss']); }); - - // it('should properly pass the registered action to instances', function() { - // var test = StyleDictionary.create({}); - // test.action['scss'].should.be.a.Function; - // }); - // - // it('should work on the instance as well', function() { - // var test = StyleDictionary.create({}); - // test.registerAction({ - // name: 'foo', - // action: function() {} - // }); - // test.action['foo'].should.be.a.Function; - // }); + it('should properly pass the registered format to instances', function() { + var test = StyleDictionary.extend({}); + assert.isFunction(test.action['scss']); + }); }); diff --git a/test/registerFormat.js b/test/registerFormat.js index 34e319fc9..35658a1c7 100644 --- a/test/registerFormat.js +++ b/test/registerFormat.js @@ -1,54 +1,69 @@ -var assert = require('assert'), - should = require('should'), - StyleDictionary = require('../index'); +var assert = require('chai').assert, + StyleDictionary = require('../index').extend({}); describe('registerFormat', function() { it('should error if name is not a string', function() { - StyleDictionary.registerFormat.bind({ - formatter: function() {} - }).should.throw(); + assert.throws( + StyleDictionary.registerFormat.bind({formatter: function() {}}) + ); - StyleDictionary.registerFormat.bind({ - name: 1, - formatter: function() {} - }).should.throw(); + assert.throws( + StyleDictionary.registerFormat.bind({ + name: 1, + formatter: function() {} + }) + ); - StyleDictionary.registerFormat.bind({ - name: [], - formatter: function() {} - }).should.throw(); + assert.throws( + StyleDictionary.registerFormat.bind({ + name: [], + formatter: function() {} + }) + ); - StyleDictionary.registerFormat.bind({ - name: {}, - formatter: function() {} - }).should.throw(); + assert.throws( + StyleDictionary.registerFormat.bind({ + name: {}, + formatter: function() {} + }) + ); }); it('should error if formatter is not a function', function() { - StyleDictionary.registerFormat.bind({ - name: 'test' - }).should.throw(); + assert.throws( + StyleDictionary.registerFormat.bind({ + name: 'test' + }) + ); - StyleDictionary.registerFormat.bind({ - name: 'test', - formatter: 1 - }).should.throw(); + assert.throws( + StyleDictionary.registerFormat.bind({ + name: 'test', + formatter: 1 + }) + ); - StyleDictionary.registerFormat.bind({ - name: 'test', - formatter: 'name' - }).should.throw(); + assert.throws( + StyleDictionary.registerFormat.bind({ + name: 'test', + formatter: 'name' + }) + ); - StyleDictionary.registerFormat.bind({ - name: 'test', - formatter: [] - }).should.throw(); + assert.throws( + StyleDictionary.registerFormat.bind({ + name: 'test', + formatter: [] + }) + ); - StyleDictionary.registerFormat.bind({ - name: 'test', - formatter: {} - }).should.throw(); + assert.throws( + StyleDictionary.registerFormat.bind({ + name: 'test', + formatter: {} + }) + ); }); it('should work if name and formatter are good', function() { @@ -57,11 +72,11 @@ describe('registerFormat', function() { formatter: function() {} }); - StyleDictionary.format['scss'].should.be.a.Function; + assert.isFunction(StyleDictionary.format['scss']); }); it('should properly pass the registered format to instances', function() { var test = StyleDictionary.extend({}); - test.format['scss'].should.be.a.Function; + assert.isFunction(test.format['scss']); }); }); diff --git a/test/registerTransform.js b/test/registerTransform.js index e44968abd..2f2232b16 100644 --- a/test/registerTransform.js +++ b/test/registerTransform.js @@ -1,40 +1,40 @@ -var assert = require('assert'), - should = require('should'), - StyleDictionary = require('../index'); +var assert = require('chai').assert, + StyleDictionary = require('../index').extend({}); describe('registerTransform', function() { it('should error if type is not a string', function() { - StyleDictionary.registerTransform.bind({ - type: 3 - }).should.throw(); + assert.throws( + StyleDictionary.registerTransform.bind({type: 3}) + ); }); it('should error if type is not a valid type', function() { - StyleDictionary.registerTransform.bind({ - type: 'foo' - }).should.throw(); + assert.throws( + StyleDictionary.registerTransform.bind({type: 'foo'}) + ); }); it('should error if name is not a string', function() { - StyleDictionary.registerTransform.bind({ - type: 'name' - }).should.throw(); + assert.throws( + StyleDictionary.registerTransform.bind({type: 'name'}) + ); }); it('should error if matcher is not a function', function() { - StyleDictionary.registerTransform.bind({ - type: 'name', - matcher: 'foo' - }).should.throw(); + assert.throws( + StyleDictionary.registerTransform.bind({type: 'name', matcher: 'foo'}) + ); }); it('should error if transformer is not a function', function() { - StyleDictionary.registerTransform.bind({ - type: 'name', - matcher: function() { return true; }, - transformer: 'foo' - }).should.throw(); + assert.throws( + StyleDictionary.registerTransform.bind({ + type: 'name', + matcher: function() { return true; }, + transformer: 'foo' + }) + ); }); it('should work if type, matcher, and transformer are all proper', function() { @@ -44,18 +44,18 @@ describe('registerTransform', function() { matcher: function() { return true; }, transformer: function() { return true; } }); - StyleDictionary.transform.foo.should.be.an.Object; - StyleDictionary.transform.foo.type.should.eql('name'); - StyleDictionary.transform.foo.matcher.should.be.a.Function; - StyleDictionary.transform.foo.transformer.should.be.a.Function; + assert.isObject(StyleDictionary.transform.foo); + assert.equal(StyleDictionary.transform.foo.type, 'name'); + assert.isFunction(StyleDictionary.transform.foo.matcher); + assert.isFunction(StyleDictionary.transform.foo.transformer); }); it('should properly pass the registered transform to instances', function() { var test = StyleDictionary.extend({}); - test.transform.foo.should.be.an.Object; - test.transform.foo.type.should.eql('name'); - test.transform.foo.matcher.should.be.a.Function; - test.transform.foo.transformer.should.be.a.Function; + assert.isObject(test.transform.foo); + assert.equal(test.transform.foo.type, 'name'); + assert.isFunction(test.transform.foo.matcher); + assert.isFunction(test.transform.foo.transformer); }); }); diff --git a/test/registerTransformGroup.js b/test/registerTransformGroup.js index ae73efe8e..05b3f7d37 100644 --- a/test/registerTransformGroup.js +++ b/test/registerTransformGroup.js @@ -1,61 +1,52 @@ -var assert = require('assert'), - should = require('should'), - StyleDictionary = require('../index'); +var assert = require('chai').assert, + StyleDictionary = require('../index').extend({}); describe('registerTransformGroup', function() { it('should error if name is not a string', function() { - StyleDictionary.registerTransformGroup.bind({ - transforms: ['foo'] - }).should.throw(); + assert.throws( + StyleDictionary.registerTransformGroup.bind({transforms: ['foo']}) + ); - StyleDictionary.registerTransformGroup.bind({ - name: 1, - transforms: ['foo'] - }).should.throw(); + assert.throws( + StyleDictionary.registerTransformGroup.bind({name: 1, transforms: ['foo']}) + ); - StyleDictionary.registerTransformGroup.bind({ - name: [], - transforms: ['foo'] - }).should.throw(); + assert.throws( + StyleDictionary.registerTransformGroup.bind({name: [], transforms: ['foo']}) + ); - StyleDictionary.registerTransformGroup.bind({ - name: {}, - transforms: ['foo'] - }).should.throw(); + assert.throws( + StyleDictionary.registerTransformGroup.bind({name: {}, transforms: ['foo']}) + ); - StyleDictionary.registerTransformGroup.bind({ - name: function() {}, - transforms: ['foo'] - }).should.throw(); + assert.throws( + StyleDictionary.registerTransformGroup.bind({name: function() {}, transforms: ['foo']}) + ); }); it('should error if transforms isnt an array', function() { - StyleDictionary.registerTransformGroup.bind({ - name: 'foo' - }).should.throw(); + assert.throws( + StyleDictionary.registerTransformGroup.bind({name: 'foo'}) + ); - StyleDictionary.registerTransformGroup.bind({ - name: 'foo', - transforms: 'foo' - }).should.throw(); + assert.throws( + StyleDictionary.registerTransformGroup.bind({name: 'foo', transforms: 'foo'}) + ); - StyleDictionary.registerTransformGroup.bind({ - name: 'foo', - transforms: {} - }).should.throw(); + assert.throws( + StyleDictionary.registerTransformGroup.bind({name: 'foo', transforms: {}}) + ); - StyleDictionary.registerTransformGroup.bind({ - name: 'foo', - transforms: function() {} - }).should.throw(); + assert.throws( + StyleDictionary.registerTransformGroup.bind({name: 'foo', transforms: function() {}}) + ); }); it('should error if transforms arent registered', function() { - StyleDictionary.registerTransformGroup.bind({ - name: 'foo', - transforms: ['bar'] - }).should.throw(); + assert.throws( + StyleDictionary.registerTransformGroup.bind({name: 'foo', transforms: ['bar']}) + ); }); it('should work if everything is good', function() { @@ -64,13 +55,13 @@ describe('registerTransformGroup', function() { transforms: ['foo'] }); - StyleDictionary.transformGroup.foo.should.be.an.Array; - StyleDictionary.transformGroup.foo[0].should.be.a.String; + assert.isArray(StyleDictionary.transformGroup.foo); + assert.isString(StyleDictionary.transformGroup.foo[0]); }); it('should properly pass the registered format to instances', function() { var test = StyleDictionary.extend({}); - test.transformGroup.foo.should.be.an.Array; - test.transformGroup.foo[0].should.be.a.String; + assert.isArray(test.transformGroup.foo); + assert.isString(test.transformGroup.foo[0]); }); }); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index fc19a682a..000000000 --- a/test/test.js +++ /dev/null @@ -1,8 +0,0 @@ -var assert = require('assert'), - should = require('should'), - helpers = require('./helpers'); - -after(function() { - // runs after all tests - helpers.clearOutput(); -}); diff --git a/test/transforms.js b/test/transforms.js index 93c6edc40..d2dc948aa 100644 --- a/test/transforms.js +++ b/test/transforms.js @@ -1,5 +1,4 @@ -var assert = require('assert'), - should = require('should'), +var assert = require('chai').assert, helpers = require('./helpers'), transforms = require('../lib/common/transforms'); @@ -7,86 +6,86 @@ var assert = require('assert'), describe('transforms', function() { describe('name/cti/camel', function() { it('should handle prefix', function() { - transforms["name/cti/camel"].transformer( + assert.equal(transforms["name/cti/camel"].transformer( { path: ['one','two','three'] },{ prefix: 'prefix' } - ).should.eql('prefixOneTwoThree'); + ), 'prefixOneTwoThree'); }); it('should handle no prefix', function() { - transforms["name/cti/camel"].transformer( + assert.equal(transforms["name/cti/camel"].transformer( { path: ['one','two','three'] },{ } - ).should.eql('oneTwoThree'); + ), 'oneTwoThree'); }); }); describe('name/cti/kebab', function() { it('should handle prefix', function() { - transforms["name/cti/kebab"].transformer( + assert.equal(transforms["name/cti/kebab"].transformer( { path: ['one','two','three'] },{ prefix: 'prefix' } - ).should.eql('prefix-one-two-three'); + ), 'prefix-one-two-three'); }); it('should handle no prefix', function() { - transforms["name/cti/kebab"].transformer( + assert.equal(transforms["name/cti/kebab"].transformer( { path: ['one','two','three'] },{ } - ).should.eql('one-two-three'); + ), 'one-two-three'); }); }); describe('name/cti/snake', function() { it('should handle prefix', function() { - transforms["name/cti/snake"].transformer( + assert.equal(transforms["name/cti/snake"].transformer( { path: ['one','two','three'] },{ prefix: 'prefix' } - ).should.eql('prefix_one_two_three'); + ), 'prefix_one_two_three'); }); it('should handle no prefix', function() { - transforms["name/cti/snake"].transformer( + assert.equal(transforms["name/cti/snake"].transformer( { path: ['one','two','three'] },{ } - ).should.eql('one_two_three'); + ), 'one_two_three'); }); }); describe('name/cti/constant', function() { it('should handle prefix', function() { - transforms["name/cti/constant"].transformer( + assert.equal(transforms["name/cti/constant"].transformer( { path: ['one','two','three'] },{ prefix: 'prefix' } - ).should.eql('PREFIX_ONE_TWO_THREE'); + ), 'PREFIX_ONE_TWO_THREE'); }); it('should handle no prefix', function() { - transforms["name/cti/constant"].transformer( + assert.equal(transforms["name/cti/constant"].transformer( { path: ['one','two','three'] },{ } - ).should.eql('ONE_TWO_THREE'); + ), 'ONE_TWO_THREE'); }); }); }); diff --git a/test/utils/combineJSON.js b/test/utils/combineJSON.js index 61b11ab32..9a6f6a52f 100644 --- a/test/utils/combineJSON.js +++ b/test/utils/combineJSON.js @@ -1,40 +1,32 @@ -var assert = require('assert'), - should = require('should'), - fs = require('fs'), - helpers = require('../helpers'), +var assert = require('chai').assert, combineJSON = require('../../lib/utils/combineJSON'); describe('combineJSON', function() { it('should return an object', function () { var test = combineJSON(["test/json_files/*.json"]); - test.should.be.an.instanceOf(Object); - }); - - it('should return null if no files are found', function () { - var test = combineJSON(["test/json_files/*.foo"]); - test.should.be.empty; + assert.isObject(test); }); it('should handle wildcards', function () { var test = combineJSON(["test/json_files/*.json"]); - test.should.be.an.instanceOf(Object); + assert.isObject(test); }); it('should do a deep merge', function() { var test = combineJSON(["test/json_files/shallow/*.json"], true); - (test.a).should.eql(2); - (test.b).should.eql({"a":1, "c":2}); - (test.d.e.f.g).should.eql(1); - (test.d.e.f.h).should.eql(2); + assert.equal(test.a, 2); + assert.deepEqual(test.b, {"a":1, "c":2}); + assert.equal(test.d.e.f.g, 1); + assert.equal(test.d.e.f.h, 2); }); it('should do a shallow merge', function() { var test = combineJSON(["test/json_files/shallow/*.json"]); - (test.a).should.equal(2); - (test.b).should.eql({"c":2}); - (test.c).should.eql([3,4]); - (test.d.e.f.h).should.equal(2); - (!!test.d.e.f.g).should.be.false; + assert.equal(test.a, 2); + assert.deepEqual(test.b, {"c":2}); + assert.deepEqual(test.c, [3,4]); + assert(!test.d.e.f.g); + assert.equal(test.d.e.f.h, 2); }); }); diff --git a/test/utils/convertToBase64.js b/test/utils/convertToBase64.js index 7b5351ce1..e3b12228b 100644 --- a/test/utils/convertToBase64.js +++ b/test/utils/convertToBase64.js @@ -1,19 +1,18 @@ -var assert = require('assert'), - should = require('should'), +var assert = require('chai').assert, convertToBase64 = require('../../lib/utils/convertToBase64.js'); describe('base64', function() { it('should error if filePath isnt a string', function() { - convertToBase64.bind().should.throw(); - convertToBase64.bind([]).should.throw(); - convertToBase64.bind({}).should.throw(); + assert.throws(convertToBase64); + assert.throws(convertToBase64.bind([])); + assert.throws(convertToBase64.bind({})); }); it('should error if filePath isnt a file', function() { - convertToBase64.bind('foo').should.throw(); + assert.throws(convertToBase64.bind('foo')); }); it('should return a string', function() { - convertToBase64('test/configs/test.json').should.be.a.String; + assert.isString(convertToBase64('test/configs/test.json')); }); }); diff --git a/test/utils/deepExtend.js b/test/utils/deepExtend.js index 6a326e3a7..f0612218a 100644 --- a/test/utils/deepExtend.js +++ b/test/utils/deepExtend.js @@ -1,38 +1,37 @@ -var assert = require('assert'), - should = require('should'), +var assert = require('chai').assert, deepExtend = require('../../lib/utils/deepExtend'); describe('deepExtend', function() { it('should return an object', function () { var test = deepExtend(); - test.should.be.an.Object; + assert.isObject(test); }); it('should override properties from right to left', function () { var test = deepExtend({foo:'bar'}, {foo:'baz'}); - test.foo.should.eql('baz'); + assert.equal(test.foo, 'baz'); var test2 = deepExtend({foo:'bar'}, {foo:'baz'}, {foo:'blah'}); - test2.foo.should.eql('blah'); + assert.equal(test2.foo, 'blah'); }); it('should override nested properties', function () { var test = deepExtend({foo: {foo:'bar'}}, {foo: {foo:'baz'}}); - test.foo.foo.should.eql('baz'); + assert.equal(test.foo.foo, 'baz'); var test2 = deepExtend({foo:{foo:'bar'}}, {foo:{foo:'baz'}}, {foo:{foo:'blah'}}); - test2.foo.foo.should.eql('blah'); + assert.equal(test2.foo.foo, 'blah'); }); it('should override nested properties', function () { var test = deepExtend({foo: {bar:'bar'}}, {foo: {baz:'baz'}}); - test.foo.baz.should.eql('baz'); - test.foo.bar.should.eql('bar'); + assert.equal(test.foo.baz, 'baz'); + assert.equal(test.foo.bar, 'bar'); var test2 = deepExtend({foo:{bar:'bar'}}, {foo:{baz:'baz'}}, {foo:{blah:'blah'}}); - test2.foo.baz.should.eql('baz'); - test2.foo.bar.should.eql('bar'); - test2.foo.blah.should.eql('blah'); + assert.equal(test2.foo.baz, 'baz'); + assert.equal(test2.foo.bar, 'bar'); + assert.equal(test2.foo.blah, 'blah'); }); }); diff --git a/test/utils/resolveObject.js b/test/utils/resolveObject.js index 1ce033bf5..3ad4a6d75 100644 --- a/test/utils/resolveObject.js +++ b/test/utils/resolveObject.js @@ -1,95 +1,103 @@ -var assert = require('assert'), - should = require('should'), - fs = require('fs'), +var assert = require('chai').assert, helpers = require('../helpers'), resolveObject = require('../../lib/utils/resolveObject'); describe('resolveObject', function() { it('should error on non-objects', function() { - resolveObject.bind('foo').should.throw(); - resolveObject.bind().should.throw(); - resolveObject.bind(0).should.throw(); + assert.throws(resolveObject.bind('foo')); + assert.throws(resolveObject); + assert.throws(resolveObject.bind(0)); }); it('should do simple references', function() { - var test1 = resolveObject( helpers.fileToJSON(__dirname + '/../json_files/simple.json') ); - (test1.bar).should.equal('bar'); + var test = resolveObject( helpers.fileToJSON(__dirname + '/../json_files/simple.json') ); + assert.equal(test.bar, 'bar'); }); it('should do nested references', function() { var obj = helpers.fileToJSON('test/json_files/nested_references.json'); var test = resolveObject( obj ); - (test.i).should.equal(2); - (test.a.b.d).should.equal(2); - (test.e.f.h).should.equal(1); + assert.equal(test.i, 2); + assert.equal(test.a.b.d, 2); + assert.equal(test.e.f.h, 1); }); it('should handle nested pointers', function() { var test = resolveObject( helpers.fileToJSON(__dirname + '/../json_files/nested_pointers.json') ); - (test.b).should.equal(1); - (test.c).should.equal(1); + assert.equal(test.b, 1); + assert.equal(test.c, 1); }); it('should handle deep nested pointers', function() { var test = resolveObject( helpers.fileToJSON(__dirname + '/../json_files/nested_pointers_2.json') ); - (test.a).should.equal(1); - (test.b).should.equal(1); - (test.c).should.equal(1); - (test.d).should.equal(1); - (test.e).should.equal(1); - (test.f).should.equal(1); - (test.g).should.equal(1); + assert.equal(test.a, 1); + assert.equal(test.b, 1); + assert.equal(test.c, 1); + assert.equal(test.d, 1); + assert.equal(test.e, 1); + assert.equal(test.f, 1); + assert.equal(test.g, 1); }); it('should handle deep nested pointers with string interpolation', function() { var test = resolveObject( helpers.fileToJSON(__dirname + '/../json_files/nested_pointers_3.json') ); - (test.a).should.equal('foo bon bee bae boo bla baz bar'); - (test.b).should.equal('foo bon bee bae boo bla baz'); - (test.c).should.equal('foo bon bee bae boo bla'); - (test.d).should.equal('foo bon bee bae boo'); - (test.e).should.equal('foo bon bee bae'); - (test.f).should.equal('foo bon bee'); - (test.g).should.equal('foo bon'); + assert.equal(test.a, 'foo bon bee bae boo bla baz bar'); + assert.equal(test.b, 'foo bon bee bae boo bla baz'); + assert.equal(test.c, 'foo bon bee bae boo bla'); + assert.equal(test.d, 'foo bon bee bae boo'); + assert.equal(test.e, 'foo bon bee bae'); + assert.equal(test.f, 'foo bon bee'); + assert.equal(test.g, 'foo bon'); }); it('should handle deep nested pointers and nested references', function() { var test = resolveObject( helpers.fileToJSON(__dirname + '/../json_files/nested_pointers_4.json') ); - (test.a.a.a).should.equal(1); - (test.b.b.b).should.equal(1); - (test.c.c.c).should.equal(1); - (test.d.d.d).should.equal(1); - (test.e.e.e).should.equal(1); - (test.f.f.f).should.equal(1); - (test.g.g.g).should.equal(1); + assert.equal(test.a.a.a, 1); + assert.equal(test.b.b.b, 1); + assert.equal(test.c.c.c, 1); + assert.equal(test.d.d.d, 1); + assert.equal(test.e.e.e, 1); + assert.equal(test.f.f.f, 1); + assert.equal(test.g.g.g, 1); }); it('should keep the type of the referenced property', function() { var test = resolveObject( helpers.fileToJSON(__dirname + '/../json_files/reference_type.json') ); - (test.d).should.equal(1); - (test.d).should.be.a.Number; - (test.e).should.be.an.Object; - (test.g).should.be.an.Array; - (test.e.c).should.be.equal(2); + assert.equal(test.d, 1); + assert.isNumber(test.d); + assert.isObject(test.e); + assert.isArray(test.g); + assert.equal(test.e.c, 2); }); it('should handle and evaluate items in an array', function() { var test = resolveObject( helpers.fileToJSON(__dirname + '/../json_files/array.json') ); - (test.d[0]).should.equal(2); - (test.d[1]).should.equal(1); - (test.e[0].a).should.equal(1); - (test.e[1].a).should.equal(2); + assert.equal(test.d[0], 2); + assert.equal(test.d[1], 1); + assert.equal(test.e[0].a, 1); + assert.equal(test.e[1].a, 2); }); it('should throw if pointers don\'t exist', function() { - resolveObject.bind( helpers.fileToJSON(__dirname + '/../json_files/non_existent.json') ).should.throw(); + assert.throws( + resolveObject.bind( helpers.fileToJSON(__dirname + '/../json_files/non_existent.json')) + ); }); it('should gracefully handle circular references', function() { - resolveObject.bind( helpers.fileToJSON(__dirname + '/../json_files/circular.json') ).should.throw(); - resolveObject.bind( helpers.fileToJSON(__dirname + '/../json_files/circular_2.json') ).should.throw(); - resolveObject.bind( helpers.fileToJSON(__dirname + '/../json_files/circular_3.json') ).should.throw(); - resolveObject.bind( helpers.fileToJSON(__dirname + '/../json_files/circular_4.json') ).should.throw(); + assert.throws( + resolveObject.bind(helpers.fileToJSON(__dirname + '/../json_files/circular.json')) + ); + assert.throws( + resolveObject.bind( helpers.fileToJSON(__dirname + '/../json_files/circular_2.json')) + ); + assert.throws( + resolveObject.bind( helpers.fileToJSON(__dirname + '/../json_files/circular_3.json')) + ); + assert.throws( + resolveObject.bind( helpers.fileToJSON(__dirname + '/../json_files/circular_4.json')) + ); }); });