Skip to content
This repository was archived by the owner on Mar 17, 2021. It is now read-only.

Commit 0390cdb

Browse files
test: standardize (@webpack-contrib/test-utils) (#114)
1 parent 457618b commit 0390cdb

File tree

9 files changed

+2190
-429
lines changed

9 files changed

+2190
-429
lines changed

package-lock.json

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

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
1919
"lint-staged": "lint-staged",
2020
"prebuild": "npm run clean",
21-
"prepublish": "npm run build",
21+
"prepare": "npm run build",
2222
"release": "standard-version",
2323
"release:ci": "conventional-github-releaser -p angular",
2424
"release:validate": "commitlint --from=$(git describe --tags --abbrev=0) --to=$(git rev-parse HEAD)",
@@ -40,6 +40,7 @@
4040
"@commitlint/cli": "^5.2.5",
4141
"@commitlint/config-angular": "^5.1.1",
4242
"@webpack-contrib/eslint-config-webpack": "^2.0.2",
43+
"@webpack-contrib/test-utils": "^0.1.2",
4344
"babel-cli": "^6.26.0",
4445
"babel-jest": "^22.0.3",
4546
"babel-plugin-transform-object-rest-spread": "^6.26.0",
@@ -61,8 +62,8 @@
6162
"pre-commit": "^1.2.2",
6263
"prettier": "^1.9.2",
6364
"standard-version": "^4.2.0",
64-
"webpack": "^3.10.0",
65-
"webpack-defaults": "^2.0.0-rc.1"
65+
"webpack": "^4.0.0",
66+
"webpack-defaults": "^2.0.0-rc.2"
6667
},
6768
"engines": {
6869
"node": ">= 6.9.0 || >= 8.9.0"

test/Errors.test.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
/* eslint-disable
22
prefer-destructuring,
33
*/
4-
import loader from '../src';
4+
import webpack from '@webpack-contrib/test-utils';
55

66
describe('Errors', () => {
7-
test('Validation Error', () => {
8-
const err = () => loader.call({ query: { limit: {} } });
7+
test('Validation Error', async () => {
8+
const config = {
9+
loader: {
10+
test: /\.png$/,
11+
options: {
12+
limit: {},
13+
},
14+
},
15+
};
16+
17+
const stats = await webpack('fixture.js', config);
18+
const { source } = stats.toJson().modules[0];
19+
20+
// eslint-disable-next-line
21+
const err = () => eval(source);
922

1023
expect(err).toThrow();
1124
expect(err).toThrowErrorMatchingSnapshot();

test/__snapshots__/Errors.test.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`Errors Validation Error 1`] = `
4-
"URL Loader Invalid Options
4+
"Module build failed: ValidationError: URL Loader Invalid Options
55
66
options.limit should be string,number
77
"

test/helpers/compiler.js

Lines changed: 0 additions & 73 deletions
This file was deleted.

test/loader.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable
22
prefer-destructuring,
33
*/
4-
import webpack from './helpers/compiler';
4+
import webpack from '@webpack-contrib/test-utils';
55

66
describe('Loader', () => {
77
test('Defaults', async () => {
@@ -13,7 +13,7 @@ describe('Loader', () => {
1313
};
1414

1515
const stats = await webpack('fixture.js', config);
16-
const { source } = stats.toJson().modules[1];
16+
const { source } = stats.toJson().modules[0];
1717

1818
expect(source).toMatchSnapshot();
1919
});

test/options/fallback.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable
22
prefer-destructuring,
33
*/
4-
import webpack from '../helpers/compiler';
4+
import webpack from '@webpack-contrib/test-utils';
55

66
describe('Options', () => {
77
describe('fallback', () => {
@@ -17,7 +17,7 @@ describe('Options', () => {
1717
};
1818

1919
const stats = await webpack('fixture.js', config);
20-
const { source } = stats.toJson().modules[1];
20+
const { source } = stats.toJson().modules[0];
2121

2222
expect(source).toMatchSnapshot();
2323
});

test/options/limit.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable
22
prefer-destructuring,
33
*/
4-
import webpack from '../helpers/compiler';
4+
import webpack from '@webpack-contrib/test-utils';
55

66
describe('Options', () => {
77
describe('limit', () => {
@@ -16,7 +16,7 @@ describe('Options', () => {
1616
};
1717

1818
const stats = await webpack('fixture.js', config);
19-
const { source } = stats.toJson().modules[1];
19+
const { source } = stats.toJson().modules[0];
2020

2121
expect(source).toMatchSnapshot();
2222
});
@@ -32,7 +32,7 @@ describe('Options', () => {
3232
};
3333

3434
const stats = await webpack('fixture.js', config);
35-
const { source } = stats.toJson().modules[1];
35+
const { source } = stats.toJson().modules[0];
3636

3737
expect(source).toMatchSnapshot();
3838
});

test/options/mimetype.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable
22
prefer-destructuring,
33
*/
4-
import webpack from '../helpers/compiler';
4+
import webpack from '@webpack-contrib/test-utils';
55

66
describe('Options', () => {
77
describe('mimetype', () => {
@@ -16,7 +16,7 @@ describe('Options', () => {
1616
};
1717

1818
const stats = await webpack('fixture.js', config);
19-
const { source } = stats.toJson().modules[1];
19+
const { source } = stats.toJson().modules[0];
2020

2121
expect(source).toMatchSnapshot();
2222
});

0 commit comments

Comments
 (0)