Skip to content

Commit 8622775

Browse files
test: use @webpack-contrib/test-utils
1 parent 9e4cd7c commit 8622775

17 files changed

+66
-136
lines changed

test/Errors.test.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable */
22
import loader from '../src';
3-
import webpack from './helpers/compiler';
3+
import webpack from '@webpack-contrib/test-utils';
44

55
describe('Errors', () => {
66
test('Loader Error', async () => {
@@ -23,10 +23,19 @@ describe('Errors', () => {
2323
expect(err).toThrowErrorMatchingSnapshot();
2424
});
2525

26-
test('Validation Error', () => {
27-
const err = () => loader.call({ query: { template: 1 } });
26+
test('Validation Error', async () => {
27+
const config = {
28+
loader: {
29+
test: /\.html$/,
30+
options: {
31+
template: 1,
32+
},
33+
},
34+
};
2835

29-
expect(err).toThrow();
30-
expect(err).toThrowErrorMatchingSnapshot();
36+
const stats = await webpack('error.js', config);
37+
const { errors } = stats.toJson()
38+
39+
errors.forEach((error) => expect(error).toMatchSnapshot());
3140
});
3241
});

test/__snapshots__/Errors.test.js.snap

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ tree.forEach is not a function
88
`;
99

1010
exports[`Errors Validation Error 1`] = `
11-
"HTML Loader Invalid Options
11+
"./fixture.html
12+
Module build failed: ValidationError: HTML Loader Invalid Options
1213
1314
options.template should be boolean,string
14-
"
15+
16+
@ ./error.js 1:0-34 3:15-19"
1517
`;

test/__snapshots__/loader.test.js.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ export default \`<!DOCTYPE html>
1414
<title>HTML Loader</title>
1515
</head>
1616
<body>
17-
<!-- HTML Content -->
1817
<div id=\\"app\\"></div>
18+
1919
<!-- HTML Import -->
2020
\${HTML__IMPORT__0}
21+
2122
<!-- HTML URL -->
2223
<img src=\\"\${HTML__URL__0}\\">
2324
</body>

test/e2e/__snapshots__/html.test.js.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ exports[`E2E HTML 1`] = `
1010
<!-- HTML URL -->
1111
<img src=\\"9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\">
1212
</div>
13+
14+
1315
"
1416
`;

test/e2e/__snapshots__/template.test.js.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ exports[`E2E Templates 1`] = `
1010
<!-- HTML URL -->
1111
<img src=\\"9c87cbf3ba33126ffd25ae7f2f6bbafb.png\\">
1212
</div>
13+
14+
1315
"
1416
`;

test/e2e/html.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable */
22
import path from 'path';
3-
import dom from '../helpers/dom';
4-
import webpack from '../helpers/compiler';
3+
import webpack, { dom } from '@webpack-contrib/test-utils';
54

65
describe('E2E', () => {
76
test('HTML', async () => {
@@ -28,7 +27,7 @@ describe('E2E', () => {
2827

2928
const scripts = {
3029
main: assets['main.js'].source(),
31-
runtime: assets['runtime.js'].source(),
30+
runtime: assets['main-runtime.js'].source(),
3231
};
3332

3433
const { window } = dom([scripts.runtime, scripts.main]);

test/e2e/template.test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* eslint-disable */
22
import path from 'path';
3-
import dom from '../helpers/dom';
4-
import webpack from '../helpers/compiler';
3+
import webpack, { dom } from '@webpack-contrib/test-utils';
54

65
describe('E2E', () => {
76
test('Templates', async () => {
@@ -28,7 +27,7 @@ describe('E2E', () => {
2827

2928
const scripts = {
3029
main: assets['main.js'].source(),
31-
runtime: assets['runtime.js'].source(),
30+
runtime: assets['main-runtime.js'].source(),
3231
};
3332

3433
const { window } = dom([scripts.runtime, scripts.main]);

test/fixtures/file.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="import"></div>

test/fixtures/file.png

6.62 KB
Loading

test/fixtures/fixture.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
<title>HTML Loader</title>
66
</head>
77
<body>
8-
<!-- HTML Content -->
98
<div id="app"></div>
9+
1010
<!-- HTML Import -->
1111
<import src="./file.html"></import>
12+
1213
<!-- HTML URL -->
1314
<img src="./file.png">
1415
</body>

0 commit comments

Comments
 (0)