Skip to content

Commit ab98a6b

Browse files
Replace mocha, nyc and chai with jest (stylelint#40)
1 parent 56c88a6 commit ab98a6b

12 files changed

+6588
-3235
lines changed

package-lock.json

Lines changed: 6388 additions & 3002 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,14 @@
2626
"*.js"
2727
],
2828
"scripts": {
29-
"debug": "npm run mocha -- --inspect-brk",
3029
"format": "prettier . --write",
3130
"lint": "npm-run-all --parallel lint:*",
3231
"lint:formatting": "prettier . --check",
3332
"lint:js": "eslint . --cache --max-warnings=0",
3433
"lint:md": "remark . --quiet --frail",
35-
"mocha": "mocha --no-timeouts",
3634
"release": "np",
37-
"test": "nyc npm run mocha",
38-
"watch": "mocha --watch"
35+
"test": "jest",
36+
"watch": "jest --watch"
3937
},
4038
"husky": {
4139
"hooks": {
@@ -69,18 +67,16 @@
6967
"@stylelint/remark-preset"
7068
]
7169
},
72-
"nyc": {
73-
"all": true,
74-
"cache": true,
75-
"check-coverage": true,
76-
"exclude": [
77-
"coverage/**",
78-
"test{,s}/**",
79-
"**/.{prettier,eslint,mocha}rc.{js,cjs}"
70+
"jest": {
71+
"collectCoverage": true,
72+
"collectCoverageFrom": [
73+
"**/*.js",
74+
"!coverage/**",
75+
"!test{,s}/**",
76+
"!**/.{prettier,eslint,mocha}rc.{js,cjs}"
8077
],
81-
"reporter": [
82-
"lcov",
83-
"text"
78+
"testMatch": [
79+
"**/test/*.js"
8480
]
8581
},
8682
"dependencies": {
@@ -90,18 +86,16 @@
9086
"@stylelint/prettier-config": "^2.0.0",
9187
"@stylelint/remark-preset": "^1.0.0",
9288
"autoprefixer": "^9.7.6",
93-
"chai": "^4.2.0",
9489
"codecov": "^3.6.5",
9590
"eslint": "^6.8.0",
9691
"eslint-config-prettier": "^6.10.1",
9792
"eslint-config-stylelint": "^12.0.0",
9893
"husky": "^4.2.5",
94+
"jest": "^26.1.0",
9995
"json5": "^2.1.3",
10096
"lint-staged": "^10.1.3",
101-
"mocha": "^7.1.1",
10297
"np": "^6.3.2",
10398
"npm-run-all": "^4.1.5",
104-
"nyc": "^15.0.1",
10599
"postcss": ">=7.0.27",
106100
"postcss-parser-tests": "^6.5.0",
107101
"postcss-safe-parser": "^4.0.2",

test/camel-case.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
const camelCase = require('../camel-case');
4-
const expect = require('chai').expect;
54
const unCamelCase = require('../un-camel-case');
65

76
const data = {
@@ -42,13 +41,13 @@ const symbols = Array.from('@*:;\n,(){} ');
4241
describe('camelCase', () => {
4342
testCases.forEach((testCase) => {
4443
it(`${testCase.unCamel} => ${testCase.camel}`, () => {
45-
expect(camelCase(testCase.unCamel)).to.equal(testCase.camel);
44+
expect(camelCase(testCase.unCamel)).toBe(testCase.camel);
4645
});
4746
});
4847
describe('symbols', () => {
4948
symbols.forEach((symbol) => {
5049
it(JSON.stringify(symbol), () => {
51-
expect(camelCase(testCases.map((testCase) => testCase.unCamel).join(symbol))).to.equal(
50+
expect(camelCase(testCases.map((testCase) => testCase.unCamel).join(symbol))).toBe(
5251
testCases.map((testCase) => testCase.camel).join(symbol),
5352
);
5453
});
@@ -59,13 +58,13 @@ describe('camelCase', () => {
5958
describe('unCamelCase', () => {
6059
testCases.forEach((testCase) => {
6160
it(`${testCase.camel} => ${testCase.unCamel}`, () => {
62-
expect(unCamelCase(testCase.camel)).to.equal(testCase.unCamel);
61+
expect(unCamelCase(testCase.camel)).toBe(testCase.unCamel);
6362
});
6463
});
6564
describe('symbols', () => {
6665
symbols.forEach((symbol) => {
6766
it(JSON.stringify(symbol), () => {
68-
expect(unCamelCase(testCases.map((testCase) => testCase.camel).join(symbol))).to.equal(
67+
expect(unCamelCase(testCases.map((testCase) => testCase.camel).join(symbol))).toBe(
6968
testCases.map((testCase) => testCase.unCamel).join(symbol),
7069
);
7170
});

test/css-in-js.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const autoprefixer = require('autoprefixer');
44
const cases = require('postcss-parser-tests');
5-
const expect = require('chai').expect;
65
const JSON5 = require('json5');
76
const objectStringify = require('../object-stringify');
87
const postcss = require('postcss');
@@ -14,7 +13,7 @@ describe('CSS in JS', () => {
1413
from: '/fixtures/basic.js',
1514
});
1615

17-
expect(document.nodes).to.lengthOf(0);
16+
expect(document.nodes).toHaveLength(0);
1817
});
1918
it('glamorous', () => {
2019
const code = `
@@ -47,7 +46,7 @@ describe('CSS in JS', () => {
4746
from: '/fixtures/glamorous-prefix.jsx',
4847
})
4948
.then((result) => {
50-
expect(result.content).equal(out);
49+
expect(result.content).toBe(out);
5150
});
5251
});
5352

@@ -66,9 +65,9 @@ describe('CSS in JS', () => {
6665
).first.first.first;
6766

6867
decl.raws.prop.raw = 'WebkitBorderRadius';
69-
expect(decl.prop).to.equal('-webkit-border-radius');
68+
expect(decl.prop).toBe('-webkit-border-radius');
7069
decl.raws.value.raw = '15px';
71-
expect(decl.value).to.equal('15px');
70+
expect(decl.value).toBe('15px');
7271
});
7372
it('atRule.raws.params.raw', () => {
7473
const atRule = syntax.parse(
@@ -86,7 +85,7 @@ describe('CSS in JS', () => {
8685
).first.first.first;
8786

8887
atRule.raws.params.raw = "(minWidth: ' + minWidth + ')";
89-
expect(atRule.params).to.equal("(min-width: ' + minWidth + ')");
88+
expect(atRule.params).toBe("(min-width: ' + minWidth + ')");
9089
});
9190
});
9291

@@ -100,10 +99,10 @@ describe('CSS in JS', () => {
10099
from: '/fixtures/glamorous-empty-object-literals.jsx',
101100
});
102101

103-
expect(root.toString()).to.equal(code);
102+
expect(root.toString()).toBe(code);
104103

105104
root.first.first.raws.after = '';
106-
expect(root.toString()).to.equal(`
105+
expect(root.toString()).toBe(`
107106
import glm from 'glamorous';
108107
const Component1 = glm.a({});
109108
`);
@@ -121,9 +120,9 @@ describe('CSS in JS', () => {
121120
from: '/fixtures/glamorous-float.jsx',
122121
});
123122

124-
expect(root.first.first.first).to.haveOwnProperty('prop', 'float');
123+
expect(root.first.first.first).toHaveProperty('prop', 'float');
125124

126-
expect(root.toString()).to.equal(`
125+
expect(root.toString()).toBe(`
127126
import glm from 'glamorous';
128127
const Component1 = glm.a({
129128
cssFloat: "left",
@@ -140,7 +139,7 @@ describe('CSS in JS', () => {
140139
}),
141140
];
142141

143-
expect(root.toString()).to.equal(`
142+
expect(root.toString()).toBe(`
144143
import glm from 'glamorous';
145144
const Component1 = glm.a({
146145
cssFloat: "right",
@@ -159,7 +158,7 @@ describe('CSS in JS', () => {
159158
const jsSource = root.toString(objectStringify).trim();
160159
const jsonSource = '{\n' + jsSource.replace(/,$/, '').replace(/[\s;]+$/gm, '') + '\n}';
161160

162-
expect(JSON5.parse(jsonSource)).be.ok;
161+
expect(JSON5.parse(jsonSource)).toBeTruthy();
163162
});
164163
});
165164
});
@@ -178,6 +177,6 @@ describe('CSS in JS', () => {
178177
from: filename,
179178
});
180179

181-
expect(document.nodes).to.have.lengthOf(2);
180+
expect(document.nodes).toHaveLength(2);
182181
});
183182
});

test/emotion.js

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
const expect = require('chai').expect;
43
const fs = require('fs');
54
const syntax = require('../');
65

@@ -15,27 +14,24 @@ describe('javascript tests', () => {
1514

1615
code = code.toString();
1716

18-
expect(document.toString()).to.equal(code);
19-
expect(document.nodes).to.lengthOf(4);
17+
expect(document.toString()).toBe(code);
18+
expect(document.nodes).toHaveLength(4);
2019

2120
document.nodes.forEach((root) => {
22-
expect(root.last.toString()).to.be.a('string');
23-
expect(root.source).to.haveOwnProperty('input');
21+
expect(typeof root.last.toString()).toBe('string');
22+
expect(root.source).toHaveProperty('input');
2423

25-
expect(code).to.includes(root.source.input.css);
26-
expect(root.source.input.css.length).lessThan(code.length);
27-
expect(root.source).to.haveOwnProperty('start').to.haveOwnProperty('line').to.greaterThan(1);
24+
expect(code).toEqual(expect.stringContaining(root.source.input.css));
25+
expect(root.source.input.css.length).toBeLessThan(code.length);
26+
expect(root.source.start.line).toBeGreaterThan(1);
2827

2928
root.walk((node) => {
30-
expect(node).to.haveOwnProperty('source');
29+
expect(node).toHaveProperty('source');
3130

32-
expect(node.source)
33-
.to.haveOwnProperty('input')
34-
.to.haveOwnProperty('css')
35-
.equal(root.source.input.css);
31+
expect(node.source.input.css).toBe(root.source.input.css);
3632

37-
expect(node.source).to.haveOwnProperty('start').to.haveOwnProperty('line');
38-
expect(node.source).to.haveOwnProperty('end').to.haveOwnProperty('line');
33+
expect(node.source).toHaveProperty('start.line');
34+
expect(node.source).toHaveProperty('end.line');
3935
});
4036
});
4137
});
@@ -50,27 +46,24 @@ describe('javascript tests', () => {
5046

5147
code = code.toString();
5248

53-
expect(document.toString()).to.equal(code);
54-
expect(document.nodes).to.lengthOf(6);
49+
expect(document.toString()).toBe(code);
50+
expect(document.nodes).toHaveLength(6);
5551

5652
document.nodes.forEach((root) => {
57-
expect(root.last.toString()).to.be.a('string');
58-
expect(root.source).to.haveOwnProperty('input');
53+
expect(typeof root.last.toString()).toBe('string');
54+
expect(root.source).toHaveProperty('input');
5955

60-
expect(code).to.includes(root.source.input.css);
61-
expect(root.source.input.css.length).lessThan(code.length);
62-
expect(root.source).to.haveOwnProperty('start').to.haveOwnProperty('line').to.greaterThan(1);
56+
expect(code).toEqual(expect.stringContaining(root.source.input.css));
57+
expect(root.source.input.css.length).toBeLessThan(code.length);
58+
expect(root.source.start.line).toBeGreaterThan(1);
6359

6460
root.walk((node) => {
65-
expect(node).to.haveOwnProperty('source');
61+
expect(node).toHaveProperty('source');
6662

67-
expect(node.source)
68-
.to.haveOwnProperty('input')
69-
.to.haveOwnProperty('css')
70-
.equal(root.source.input.css);
63+
expect(node.source.input.css).toBe(root.source.input.css);
7164

72-
expect(node.source).to.haveOwnProperty('start').to.haveOwnProperty('line');
73-
expect(node.source).to.haveOwnProperty('end').to.haveOwnProperty('line');
65+
expect(node.source).toHaveProperty('start.line');
66+
expect(node.source).toHaveProperty('end.line');
7467
});
7568
});
7669
});

test/glamorous.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
const expect = require('chai').expect;
43
const fs = require('fs');
54
const syntax = require('../');
65

@@ -15,26 +14,23 @@ describe('javascript tests', () => {
1514

1615
code = code.toString();
1716

18-
expect(document.toString(syntax)).to.equal(code);
19-
expect(document.nodes).to.lengthOf(5);
17+
expect(document.toString(syntax)).toBe(code);
18+
expect(document.nodes).toHaveLength(5);
2019

2120
document.nodes.forEach((root) => {
22-
expect(root.source).to.haveOwnProperty('input');
21+
expect(root.source).toHaveProperty('input');
2322

24-
expect(code).to.includes(root.source.input.css);
25-
expect(root.source.input.css.length).lessThan(code.length);
26-
expect(root.source).to.haveOwnProperty('start').to.haveOwnProperty('line').to.greaterThan(1);
23+
expect(code).toEqual(expect.stringContaining(root.source.input.css));
24+
expect(root.source.input.css.length).toBeLessThan(code.length);
25+
expect(root.source.start.line).toBeGreaterThan(1);
2726

2827
root.walk((node) => {
29-
expect(node).to.haveOwnProperty('source');
28+
expect(node).toHaveProperty('source');
3029

31-
expect(node.source)
32-
.to.haveOwnProperty('input')
33-
.to.haveOwnProperty('css')
34-
.equal(root.source.input.css);
30+
expect(node.source.input.css).toBe(root.source.input.css);
3531

36-
expect(node.source).to.haveOwnProperty('start').to.haveOwnProperty('line');
37-
expect(node.source).to.haveOwnProperty('end').to.haveOwnProperty('line');
32+
expect(node.source).toHaveProperty('start.line');
33+
expect(node.source).toHaveProperty('end.line');
3834
});
3935
});
4036
});

0 commit comments

Comments
 (0)