Skip to content

Commit

Permalink
refactor: migrate on jest (#804)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi committed Nov 26, 2018
1 parent 417d105 commit 7a6ff03
Show file tree
Hide file tree
Showing 16 changed files with 4,974 additions and 3,216 deletions.
8,082 changes: 4,936 additions & 3,146 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 5 additions & 9 deletions package.json
Expand Up @@ -29,18 +29,14 @@
"@commitlint/cli": "^7.2.1",
"@commitlint/config-conventional": "^7.1.2",
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
"codecov": "^3.1.0",
"jest": "^23.6.0",
"eslint": "^5.9.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-prettier": "^3.0.0",
"husky": "^1.2.0",
"lint-staged": "^8.1.0",
"prettier": "^1.15.2",
"istanbul": "^0.4.5",
"mocha": "^5.2.0",
"should": "^13.2.3",
"standard-version": "^4.0.0",
"nyc": "^13.1.0",
"strip-ansi": "^5.0.0"
},
"peerDependencies": {
Expand All @@ -54,12 +50,12 @@
"travis:lint": "npm run lint",
"release": "standard-version",
"security": "npm audit",
"test": "mocha",
"test:coverage": "nyc mocha",
"test": "jest",
"test:coverage": "jest --collectCoverageFrom='lib/**/*.js' --coverage",
"ci:lint": "npm run lint && npm run security",
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
"ci:test": "npm run test",
"ci:coverage": "npm run test:coverage"
"ci:test": "npm run test -- --runInBand",
"ci:coverage": "npm run test:coverage -- --runInBand"
},
"homepage": "https://github.com/webpack-contrib/css-loader",
"repository": "https://github.com/webpack-contrib/css-loader.git",
Expand Down
2 changes: 0 additions & 2 deletions test/camelCaseTest.js → test/camelCase.test.js
@@ -1,5 +1,3 @@
/* globals describe */

const { test, testRaw } = require('./helpers');

describe('camelCase', () => {
Expand Down
@@ -1,5 +1,3 @@
/* globals describe */

const { testLocals } = require('./helpers');

describe('customGetLocalIdent', () => {
Expand Down
19 changes: 8 additions & 11 deletions test/helpers.js
@@ -1,6 +1,3 @@
/* globals it */

require('should');
const vm = require('vm');

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

function assetEvaluated(output, result, modules) {
const exports = getEvaluated(output, modules);
exports.should.be.eql(result);
expect(exports).toEqual(result);
}

function assertRaw(output, result) {
output.should.containEql(result);
expect(output).toContain(result);
}

function runLoader(loader, input, map, addOptions, callback) {
Expand Down Expand Up @@ -208,12 +205,12 @@ exports.testSingleItem = function testSingleItem(
return done(err);
}
const exports = getEvaluated(output, modules);
Array.isArray(exports).should.be.eql(true);
exports.length.should.be.eql(1);
(exports[0].length >= 3).should.be.eql(true);
exports[0][0].should.be.eql(1);
exports[0][2].should.be.eql('');
exports[0][1].should.be.eql(result);
expect(Array.isArray(exports)).toBe(true);
expect(exports).toHaveLength(1);
expect(exports[0].length >= 3).toBe(true);
expect(exports[0][0]).toBe(1);
expect(exports[0][2]).toBe('');
expect(exports[0][1]).toBe(result);
return done();
}
);
Expand Down
2 changes: 0 additions & 2 deletions test/importTest.js → test/import.test.js
@@ -1,5 +1,3 @@
/* globals describe */

const assert = require('assert');

const stripAnsi = require('strip-ansi');
Expand Down
2 changes: 0 additions & 2 deletions test/localTest.js → test/local.test.js
@@ -1,5 +1,3 @@
/* globals describe */

const { test } = require('./helpers');

function testLocal(name, input, result, localsResult, query, modules) {
Expand Down
2 changes: 0 additions & 2 deletions test/localsTest.js → test/locals.test.js
@@ -1,5 +1,3 @@
/* globals describe */

const { testLocals } = require('./helpers');

describe('locals', () => {
Expand Down
2 changes: 0 additions & 2 deletions test/moduleTest.js → test/module.test.js
@@ -1,5 +1,3 @@
/* globals describe */

const path = require('path');
const fs = require('fs');

Expand Down
22 changes: 10 additions & 12 deletions test/runtime-api.js → test/runtime-api.test.js
@@ -1,41 +1,39 @@
/* eslint-env mocha */

const api = require('../lib/runtime/api');

describe('css-base', () => {
before(() => {
beforeAll(() => {
global.btoa = function btoa(str) {
let buffer = null;

if (str instanceof Buffer) {
buffer = str;
} else {
buffer = new Buffer(str.toString(), 'binary');
buffer = Buffer.from(str.toString(), 'binary');
}

return buffer.toString('base64');
};
});

after(() => {
afterAll(() => {
global.btoa = null;
});

it('should toString a single module', () => {
const m = api();
m.push([1, 'body { a: 1; }', '']);
m.toString().should.be.eql('body { a: 1; }');
expect(m.toString()).toBe('body { a: 1; }');
});
it('should toString multiple modules', () => {
const m = api();
m.push([2, 'body { b: 2; }', '']);
m.push([1, 'body { a: 1; }', '']);
m.toString().should.be.eql('body { b: 2; }body { a: 1; }');
expect(m.toString()).toBe('body { b: 2; }body { a: 1; }');
});
it('should toString with media query', () => {
const m = api();
m.push([1, 'body { a: 1; }', 'screen']);
m.toString().should.be.eql('@media screen{body { a: 1; }}');
expect(m.toString()).toBe('@media screen{body { a: 1; }}');
});
it('should import modules', () => {
const m = api();
Expand All @@ -47,7 +45,7 @@ describe('css-base', () => {
m.i([m2], '');
m.i([m2, m4], 'print');
m.push(m1);
m.toString().should.be.eql(
expect(m.toString()).toBe(
'body { b: 2; }' +
'body { c: 3; }' +
'@media print{body { d: 4; }}' +
Expand All @@ -64,7 +62,7 @@ describe('css-base', () => {
m.i([m2], '');
m.i([m2, m4], 'print');
m.push(m1);
m.toString().should.be.eql(
expect(m.toString()).toBe(
'body { b: 2; }' +
'body { c: 3; }' +
'@media print{body { d: 4; }}' +
Expand All @@ -84,7 +82,7 @@ describe('css-base', () => {
sourceRoot: 'webpack://',
},
]);
m.toString().should.be.eql(
expect(m.toString()).toBe(
'body { a: 1; }\n/*# sourceURL=webpack://./path/to/test.scss */\n/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJmaWxlIjoidGVzdC5zY3NzIiwic291cmNlcyI6WyIuL3BhdGgvdG8vdGVzdC5zY3NzIl0sIm1hcHBpbmdzIjoiQUFBQTsiLCJzb3VyY2VSb290Ijoid2VicGFjazovLyJ9 */'
);
});
Expand All @@ -102,6 +100,6 @@ describe('css-base', () => {
sourceRoot: 'webpack://',
},
]);
m.toString().should.be.eql('body { a: 1; }');
expect(m.toString()).toBe('body { a: 1; }');
});
});
18 changes: 0 additions & 18 deletions test/runtime-escape.js

This file was deleted.

15 changes: 15 additions & 0 deletions test/runtime-escape.test.js
@@ -0,0 +1,15 @@
const escape = require('../lib/runtime/escape');

describe('runtime escape', () => {
it('should escape url', () => {
expect(escape(true)).toBe(true);
expect(escape('image.png')).toBe('image.png');
expect(escape('"image.png"')).toBe('image.png');
expect(escape("'image.png'")).toBe('image.png');
expect(escape('image other.png')).toBe('"image other.png"');
expect(escape('"image other.png"')).toBe('"image other.png"');
expect(escape("'image other.png'")).toBe('"image other.png"');
expect(escape('image"other.png')).toBe('"image\\"other.png"');
expect(escape('image\nother.png')).toBe('"image\\nother.png"');
});
});
2 changes: 0 additions & 2 deletions test/simpleTest.js → test/simple.test.js
@@ -1,5 +1,3 @@
/* globals describe */

const assert = require('assert');

const stripAnsi = require('strip-ansi');
Expand Down
2 changes: 0 additions & 2 deletions test/sourceMapTest.js → test/sourceMap.test.js
@@ -1,5 +1,3 @@
/* globals describe */

const { testWithMap, testMap } = require('./helpers');

describe('source maps', () => {
Expand Down
2 changes: 0 additions & 2 deletions test/urlTest.js → test/url.test.js
@@ -1,5 +1,3 @@
/* globals describe */

const { test } = require('./helpers');

describe('url', () => {
Expand Down
2 changes: 0 additions & 2 deletions test/valuesTest.js → test/values.test.js
@@ -1,5 +1,3 @@
/* globals describe */

const { testLocals, test } = require('./helpers');

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

0 comments on commit 7a6ff03

Please sign in to comment.