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

chore(tests): add eslint-jst and fix lint errors #486

Merged
merged 2 commits into from
Dec 1, 2020
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
9 changes: 7 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"parserOptions": {
"ecmaVersion": 6
},
"plugins": ["jest"],
"env": {
"node": true,
"mocha": true,
Expand All @@ -11,11 +12,15 @@
"Buffer": true,
"escape": true
},
"extends": "eslint:recommended",
"extends": [
"eslint:recommended",
"plugin:jest/recommended"
],
"rules": {
"no-console": 0,
"no-unused-vars": 1,
"comma-dangle": 0,
"no-prototype-builtins": 0
"no-prototype-builtins": 0,
"jest/valid-title": 0
}
}
8 changes: 2 additions & 6 deletions __tests__/common/transforms.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,11 @@ describe('common', () => {
expect(value).toBe("#aaaaaaff");
});

it('should handle rgb colors', () => {
it('should handle rgba colors', () => {
var value = transforms["color/hex8"].transformer({
value: "rgb(170,170,170)"
});
var value2 = transforms["color/hex8"].transformer({
value: "rgba(170,170,170,0.6)"
});
expect(value).toBe("#aaaaaaff");
expect(value2).toBe("#aaaaaa99");
expect(value).toBe("#aaaaaa99");
});
});

Expand Down
12 changes: 5 additions & 7 deletions __tests__/formats/javascriptObject.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ var formatter = formats['javascript/object'].bind(file);
describe('formats', () => {
describe('javascript/object', () => {

it('should be valid JS syntax', done => {
try {
vm.runInNewContext(formatter(dictionary, {}, file))
return done();
} catch (err) {
return done(new Error(err));
}
it('should be valid JS syntax', () => {
const script = new vm.Script(formatter(dictionary, {}, file));
const context = {};
script.runInNewContext(context);
expect(context.foo.color.red.value).toEqual(dictionary.properties.color.red.value);
});

});
Expand Down
7 changes: 3 additions & 4 deletions __tests__/formats/lessIcons.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,13 @@ var formatter = formats['less/icons'].bind(file);
describe('formats', () => {
describe('less/icons', () => {

it('should have a valid less syntax', done => {
less.render(formatter(dictionary, config, file))
it('should have a valid less syntax', () => {
return less.render(formatter(dictionary, config, file))
.then(function(output) {
expect(output).toBeDefined();
done();
})
.catch(function(err) {
done(new Error(err))
throw new Error(err);
});
});

Expand Down
7 changes: 3 additions & 4 deletions __tests__/formats/lessVariables.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,13 @@ var formatter = formats['less/variables'].bind(file);
describe('formats', () => {
describe('less/variables', () => {

it('should have a valid less syntax', done => {
less.render(formatter(dictionary, {}, file))
it('should have a valid less syntax', () => {
return less.render(formatter(dictionary, {}, file))
.then(function(output) {
expect(output).toBeDefined();
done();
})
.catch(function(err) {
done(new Error(err))
throw new Error(err);
});
});

Expand Down
11 changes: 3 additions & 8 deletions __tests__/formats/scssIcons.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,11 @@ var formatter = formats['scss/icons'].bind(file);
describe('formats', () => {
describe('scss/icons', () => {

it('should have a valid scss syntax', done => {
scss.render({
it('should have a valid scss syntax', () => {
const result = scss.renderSync({
data: formatter(dictionary, config, file),
}, function(err, result) {
if(err) {
return done(new Error(err));
}
expect(result.css).toBeDefined();
return done();
});
expect(result.css).toBeDefined();
});

});
Expand Down
11 changes: 3 additions & 8 deletions __tests__/formats/scssMaps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,11 @@ describe('formats', () => {
expect(typeof output).toBe('string');
});

it('should have a valid scss syntax', done => {
scss.render({
it('should have a valid scss syntax', () => {
const result = scss.renderSync({
data: output,
}, function(err, result) {
if(err) {
return done(new Error(err));
}
expect(result.css).toBeDefined();
return done();
});
expect(result.css).toBeDefined();
});

it(key + ' snapshot', () => {
Expand Down
11 changes: 3 additions & 8 deletions __tests__/formats/scssVariables.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,11 @@ var formatter = formats['scss/variables'].bind(file);
describe('formats', () => {
describe('scss/variables', () => {

it('should have a valid scss syntax', done => {
scss.render({
it('should have a valid scss syntax', () => {
const result = scss.renderSync({
data: formatter(dictionary, {}, file),
}, function(err, result) {
if(err) {
return done(new Error(err));
}
expect(result.css).toBeDefined();
return done();
});
expect(result.css).toBeDefined();
});

it('should optionally use !default', () => {
Expand Down
20 changes: 11 additions & 9 deletions __tests__/register/format.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,68 +18,70 @@ describe('register', () => {
describe('format', () => {

it('should error if name is not a string', () => {
const errorMessage = `Can't register format; format.name must be a string`
expect(
StyleDictionaryExtended.registerFormat.bind(null, {
formatter: function() {}
})
).toThrow('Can\'t register format; format.name must be a string');
).toThrow(errorMessage);

expect(
StyleDictionaryExtended.registerFormat.bind(null, {
name: 1,
formatter: function() {}
})
).toThrow('Can\'t register format; format.name must be a string');
).toThrow(errorMessage);

expect(
StyleDictionaryExtended.registerFormat.bind(null, {
name: [],
formatter: function() {}
})
);
).toThrow(errorMessage);

expect(
StyleDictionaryExtended.registerFormat.bind(null, {
name: {},
formatter: function() {}
})
).toThrow('Can\'t register format; format.name must be a string');
).toThrow(errorMessage);
});

it('should error if format is not a function', () => {
const errorMessage = `Can't register format; format.formatter must be a function`
expect(
StyleDictionaryExtended.registerFormat.bind(null, {
name: 'test'
})
).toThrow('Can\'t register format; format.formatter must be a function');
).toThrow(errorMessage);

expect(
StyleDictionaryExtended.registerFormat.bind(null, {
name: 'test',
formatter: 1
})
).toThrow('Can\'t register format; format.formatter must be a function');
).toThrow(errorMessage);

expect(
StyleDictionaryExtended.registerFormat.bind(null, {
name: 'test',
formatter: 'name'
})
).toThrow('Can\'t register format; format.formatter must be a function');
).toThrow(errorMessage);

expect(
StyleDictionaryExtended.registerFormat.bind(null, {
name: 'test',
formatter: []
})
).toThrow('Can\'t register format; format.formatter must be a function');
).toThrow(errorMessage);

expect(
StyleDictionaryExtended.registerFormat.bind(null, {
name: 'test',
formatter: {}
})
).toThrow('Can\'t register format; format.formatter must be a function');
).toThrow(errorMessage);
});

it('should work if name and format are good', () => {
Expand Down
1 change: 0 additions & 1 deletion __tests__/transform/propertySetup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ describe('transform', () => {
["color","base"]
);
expect(typeof test).toBe('object');
expect(test);
expect(test).toHaveProperty('value');
expect(test).toHaveProperty('original');
expect(test).toHaveProperty('attributes');
Expand Down
4 changes: 2 additions & 2 deletions __tests__/utils/combineJSON.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ describe('utils', () => {
const testOutput = { test: 'test' };
const parsers = [{
pattern: /.json$/,
parse: (content) => {
parse: () => {
return { test: 'foo' }
}
},{
pattern: /.json$/,
parse: (content) => {
parse: () => {
return testOutput
}
}];
Expand Down
4 changes: 2 additions & 2 deletions __tests__/utils/deepExtend.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ describe('utils', () => {
expect(test2).toHaveProperty('foo', 'blah');
});

it('should override nested properties', () => {
it('overrides nested properties', () => {
var test = deepExtend([{foo: {foo:'bar'}}, {foo: {foo:'baz'}}]);
expect(test).toHaveProperty('foo.foo', 'baz');

var test2 = deepExtend([{foo:{foo:'bar'}}, {foo:{foo:'baz'}}, {foo:{foo:'blah'}}]);
expect(test2).toHaveProperty('foo.foo', 'blah');
});

it('should override nested properties', () => {
it('properly merges nested properties', () => {
var test = deepExtend([{foo: {bar:'bar'}}, {foo: {baz:'baz'}}]);
expect(test).toHaveProperty('foo.baz', 'baz');
expect(test).toHaveProperty('foo.bar', 'bar');
Expand Down
3 changes: 1 addition & 2 deletions lib/common/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
*/

var _ = require('lodash'),
fs = require('fs-extra'),
chalk = require('chalk');
fs = require('fs-extra');

/**
* @namespace Actions
Expand Down
4 changes: 2 additions & 2 deletions lib/common/formats.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ module.exports = {
* $color-background-alt: #eeeeee !default;
* ```
*/
'scss/variables': function(dictionary, config, file) {
'scss/variables': function(dictionary) {
return fileHeader(this.options, 'short') + formattedVariables('sass', dictionary.allProperties);
},

Expand Down Expand Up @@ -245,7 +245,7 @@ module.exports = {
* \@color-background-alt: #eeeeee;
* ```
*/
'less/variables': function(dictionary, config, file) {
'less/variables': function(dictionary) {
return fileHeader(this.options, 'short') + formattedVariables('less', dictionary.allProperties);
},

Expand Down
1 change: 0 additions & 1 deletion lib/register/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
var chalk = require('chalk');

/**
* Adds a custom action to the style property builder. Custom
Expand Down
Loading