Skip to content

Commit 7a6ff03

Browse files
refactor: migrate on jest (#804)
1 parent 417d105 commit 7a6ff03

16 files changed

+4974
-3216
lines changed

package-lock.json

+4,936-3,146
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-9
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,14 @@
2929
"@commitlint/cli": "^7.2.1",
3030
"@commitlint/config-conventional": "^7.1.2",
3131
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
32-
"codecov": "^3.1.0",
32+
"jest": "^23.6.0",
3333
"eslint": "^5.9.0",
3434
"eslint-plugin-import": "^2.14.0",
3535
"eslint-plugin-prettier": "^3.0.0",
3636
"husky": "^1.2.0",
3737
"lint-staged": "^8.1.0",
3838
"prettier": "^1.15.2",
39-
"istanbul": "^0.4.5",
40-
"mocha": "^5.2.0",
41-
"should": "^13.2.3",
4239
"standard-version": "^4.0.0",
43-
"nyc": "^13.1.0",
4440
"strip-ansi": "^5.0.0"
4541
},
4642
"peerDependencies": {
@@ -54,12 +50,12 @@
5450
"travis:lint": "npm run lint",
5551
"release": "standard-version",
5652
"security": "npm audit",
57-
"test": "mocha",
58-
"test:coverage": "nyc mocha",
53+
"test": "jest",
54+
"test:coverage": "jest --collectCoverageFrom='lib/**/*.js' --coverage",
5955
"ci:lint": "npm run lint && npm run security",
6056
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
61-
"ci:test": "npm run test",
62-
"ci:coverage": "npm run test:coverage"
57+
"ci:test": "npm run test -- --runInBand",
58+
"ci:coverage": "npm run test:coverage -- --runInBand"
6359
},
6460
"homepage": "https://github.com/webpack-contrib/css-loader",
6561
"repository": "https://github.com/webpack-contrib/css-loader.git",

test/camelCaseTest.js renamed to test/camelCase.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* globals describe */
2-
31
const { test, testRaw } = require('./helpers');
42

53
describe('camelCase', () => {

test/customGetLocalIdentTest.js renamed to test/customGetLocalIdent.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* globals describe */
2-
31
const { testLocals } = require('./helpers');
42

53
describe('customGetLocalIdent', () => {

test/helpers.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
/* globals it */
2-
3-
require('should');
41
const vm = require('vm');
52

63
const cssLoader = require('../index.js');
@@ -43,11 +40,11 @@ function getEvaluated(output, modules) {
4340

4441
function assetEvaluated(output, result, modules) {
4542
const exports = getEvaluated(output, modules);
46-
exports.should.be.eql(result);
43+
expect(exports).toEqual(result);
4744
}
4845

4946
function assertRaw(output, result) {
50-
output.should.containEql(result);
47+
expect(output).toContain(result);
5148
}
5249

5350
function runLoader(loader, input, map, addOptions, callback) {
@@ -208,12 +205,12 @@ exports.testSingleItem = function testSingleItem(
208205
return done(err);
209206
}
210207
const exports = getEvaluated(output, modules);
211-
Array.isArray(exports).should.be.eql(true);
212-
exports.length.should.be.eql(1);
213-
(exports[0].length >= 3).should.be.eql(true);
214-
exports[0][0].should.be.eql(1);
215-
exports[0][2].should.be.eql('');
216-
exports[0][1].should.be.eql(result);
208+
expect(Array.isArray(exports)).toBe(true);
209+
expect(exports).toHaveLength(1);
210+
expect(exports[0].length >= 3).toBe(true);
211+
expect(exports[0][0]).toBe(1);
212+
expect(exports[0][2]).toBe('');
213+
expect(exports[0][1]).toBe(result);
217214
return done();
218215
}
219216
);

test/importTest.js renamed to test/import.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* globals describe */
2-
31
const assert = require('assert');
42

53
const stripAnsi = require('strip-ansi');

test/localTest.js renamed to test/local.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* globals describe */
2-
31
const { test } = require('./helpers');
42

53
function testLocal(name, input, result, localsResult, query, modules) {

test/localsTest.js renamed to test/locals.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* globals describe */
2-
31
const { testLocals } = require('./helpers');
42

53
describe('locals', () => {

test/moduleTest.js renamed to test/module.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* globals describe */
2-
31
const path = require('path');
42
const fs = require('fs');
53

test/runtime-api.js renamed to test/runtime-api.test.js

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,39 @@
1-
/* eslint-env mocha */
2-
31
const api = require('../lib/runtime/api');
42

53
describe('css-base', () => {
6-
before(() => {
4+
beforeAll(() => {
75
global.btoa = function btoa(str) {
86
let buffer = null;
97

108
if (str instanceof Buffer) {
119
buffer = str;
1210
} else {
13-
buffer = new Buffer(str.toString(), 'binary');
11+
buffer = Buffer.from(str.toString(), 'binary');
1412
}
1513

1614
return buffer.toString('base64');
1715
};
1816
});
1917

20-
after(() => {
18+
afterAll(() => {
2119
global.btoa = null;
2220
});
2321

2422
it('should toString a single module', () => {
2523
const m = api();
2624
m.push([1, 'body { a: 1; }', '']);
27-
m.toString().should.be.eql('body { a: 1; }');
25+
expect(m.toString()).toBe('body { a: 1; }');
2826
});
2927
it('should toString multiple modules', () => {
3028
const m = api();
3129
m.push([2, 'body { b: 2; }', '']);
3230
m.push([1, 'body { a: 1; }', '']);
33-
m.toString().should.be.eql('body { b: 2; }body { a: 1; }');
31+
expect(m.toString()).toBe('body { b: 2; }body { a: 1; }');
3432
});
3533
it('should toString with media query', () => {
3634
const m = api();
3735
m.push([1, 'body { a: 1; }', 'screen']);
38-
m.toString().should.be.eql('@media screen{body { a: 1; }}');
36+
expect(m.toString()).toBe('@media screen{body { a: 1; }}');
3937
});
4038
it('should import modules', () => {
4139
const m = api();
@@ -47,7 +45,7 @@ describe('css-base', () => {
4745
m.i([m2], '');
4846
m.i([m2, m4], 'print');
4947
m.push(m1);
50-
m.toString().should.be.eql(
48+
expect(m.toString()).toBe(
5149
'body { b: 2; }' +
5250
'body { c: 3; }' +
5351
'@media print{body { d: 4; }}' +
@@ -64,7 +62,7 @@ describe('css-base', () => {
6462
m.i([m2], '');
6563
m.i([m2, m4], 'print');
6664
m.push(m1);
67-
m.toString().should.be.eql(
65+
expect(m.toString()).toBe(
6866
'body { b: 2; }' +
6967
'body { c: 3; }' +
7068
'@media print{body { d: 4; }}' +
@@ -84,7 +82,7 @@ describe('css-base', () => {
8482
sourceRoot: 'webpack://',
8583
},
8684
]);
87-
m.toString().should.be.eql(
85+
expect(m.toString()).toBe(
8886
'body { a: 1; }\n/*# sourceURL=webpack://./path/to/test.scss */\n/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoidGVzdC5zY3NzIiwic291cmNlcyI6WyIuL3BhdGgvdG8vdGVzdC5zY3NzIl0sIm1hcHBpbmdzIjoiQUFBQTsiLCJzb3VyY2VSb290Ijoid2VicGFjazovLyJ9 */'
8987
);
9088
});
@@ -102,6 +100,6 @@ describe('css-base', () => {
102100
sourceRoot: 'webpack://',
103101
},
104102
]);
105-
m.toString().should.be.eql('body { a: 1; }');
103+
expect(m.toString()).toBe('body { a: 1; }');
106104
});
107105
});

test/runtime-escape.js

-18
This file was deleted.

test/runtime-escape.test.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const escape = require('../lib/runtime/escape');
2+
3+
describe('runtime escape', () => {
4+
it('should escape url', () => {
5+
expect(escape(true)).toBe(true);
6+
expect(escape('image.png')).toBe('image.png');
7+
expect(escape('"image.png"')).toBe('image.png');
8+
expect(escape("'image.png'")).toBe('image.png');
9+
expect(escape('image other.png')).toBe('"image other.png"');
10+
expect(escape('"image other.png"')).toBe('"image other.png"');
11+
expect(escape("'image other.png'")).toBe('"image other.png"');
12+
expect(escape('image"other.png')).toBe('"image\\"other.png"');
13+
expect(escape('image\nother.png')).toBe('"image\\nother.png"');
14+
});
15+
});

test/simpleTest.js renamed to test/simple.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* globals describe */
2-
31
const assert = require('assert');
42

53
const stripAnsi = require('strip-ansi');

test/sourceMapTest.js renamed to test/sourceMap.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* globals describe */
2-
31
const { testWithMap, testMap } = require('./helpers');
42

53
describe('source maps', () => {

test/urlTest.js renamed to test/url.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* globals describe */
2-
31
const { test } = require('./helpers');
42

53
describe('url', () => {

test/valuesTest.js renamed to test/values.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* globals describe */
2-
31
const { testLocals, test } = require('./helpers');
42

53
function testLocal(name, input, result, localsResult, query, modules) {

0 commit comments

Comments
 (0)