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>

test/helpers/compiler.js

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

test/helpers/dom.js

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

test/loader.test.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
/* eslint-disable */
2-
import webpack from './helpers/compiler';
2+
import path from 'path';
3+
import webpack from '@webpack-contrib/test-utils';
34

45
describe('Loader', () => {
56
test('Defaults', async () => {
67
const config = {
7-
loader: {
8-
test: /\.html$/,
9-
options: {},
10-
},
11-
};
8+
rules: [
9+
{
10+
test: /\.html$/,
11+
use: [
12+
{
13+
loader: path.resolve('src'),
14+
options: {},
15+
},
16+
],
17+
},
18+
{
19+
test: /\.png$/,
20+
use: ['file-loader'],
21+
},
22+
],
23+
}
1224

1325
const stats = await webpack('fixture.js', config);
14-
const { source } = stats.toJson().modules[1];
26+
const { source } = stats.toJson().modules[2];
27+
1528

1629
expect(source).toMatchSnapshot();
1730
});

test/options/import.test.js

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

44
describe('Options', () => {
55
describe('import', () => {
@@ -12,7 +12,7 @@ describe('Options', () => {
1212
};
1313

1414
const stats = await webpack('options/import/fixture.js', config);
15-
const { source } = stats.toJson().modules[1];
15+
const { source } = stats.toJson().modules[0];
1616

1717
expect(source).toMatchSnapshot();
1818
});
@@ -28,7 +28,7 @@ describe('Options', () => {
2828
};
2929

3030
const stats = await webpack('options/import/fixture.js', config);
31-
const { source } = stats.toJson().modules[1];
31+
const { source } = stats.toJson().modules[0];
3232

3333
expect(source).toMatchSnapshot();
3434
});
@@ -44,7 +44,7 @@ describe('Options', () => {
4444
};
4545

4646
const stats = await webpack('options/import/filter/fixture.js', config);
47-
const { source } = stats.toJson().modules[1];
47+
const { source } = stats.toJson().modules[0];
4848

4949
expect(source).toMatchSnapshot();
5050
});
@@ -62,7 +62,7 @@ describe('Options', () => {
6262
};
6363

6464
const stats = await webpack('options/import/filter/fixture.js', config);
65-
const { source } = stats.toJson().modules[1];
65+
const { source } = stats.toJson().modules[0];
6666

6767
expect(source).toMatchSnapshot();
6868
});

test/options/minimize.test.js

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

44
describe('Options', () => {
55
describe('minimize', () => {
@@ -14,7 +14,7 @@ describe('Options', () => {
1414
};
1515

1616
const stats = await webpack('options/minimize/fixture.js', config);
17-
const { source } = stats.toJson().modules[1];
17+
const { source } = stats.toJson().modules[0];
1818

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

test/options/template.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('template', () => {
@@ -16,7 +16,7 @@ describe('Options', () => {
1616
};
1717

1818
const stats = await webpack('options/template/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('options/template/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/url.test.js

Lines changed: 5 additions & 5 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('url', () => {
@@ -14,7 +14,7 @@ describe('Options', () => {
1414
};
1515

1616
const stats = await webpack('options/url/fixture.js', config);
17-
const { source } = stats.toJson().modules[1];
17+
const { source } = stats.toJson().modules[0];
1818

1919
expect(source).toMatchSnapshot();
2020
});
@@ -30,7 +30,7 @@ describe('Options', () => {
3030
};
3131

3232
const stats = await webpack('options/url/fixture.js', config);
33-
const { source } = stats.toJson().modules[1];
33+
const { source } = stats.toJson().modules[0];
3434

3535
expect(source).toMatchSnapshot();
3636
});
@@ -46,7 +46,7 @@ describe('Options', () => {
4646
};
4747

4848
const stats = await webpack('options/url/filter/fixture.js', config);
49-
const { source } = stats.toJson().modules[1];
49+
const { source } = stats.toJson().modules[0];
5050

5151
expect(source).toMatchSnapshot();
5252
});
@@ -64,7 +64,7 @@ describe('Options', () => {
6464
};
6565

6666
const stats = await webpack('options/url/filter/fixture.js', config);
67-
const { source } = stats.toJson().modules[1];
67+
const { source } = stats.toJson().modules[0];
6868

6969
expect(source).toMatchSnapshot();
7070
});

0 commit comments

Comments
 (0)