-
-
Notifications
You must be signed in to change notification settings - Fork 384
/
Copy pathBeforeLinkAppendHook.test.js
49 lines (43 loc) · 1.27 KB
/
BeforeLinkAppendHook.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import MiniCssExtractPlugin from '../src';
import { getCompiler, compile } from './helpers';
it('It should be able to inject successfully', async (done) => {
class RewriteErrorHandler {
// eslint-disable-next-line class-methods-use-this
apply(compiler) {
compiler.hooks.thisCompilation.tap(
'RewriteErrorHandler',
(compilation) => {
compilation.hooks.miniCssExtractPluginBeforeLinkAppend.tap(
'RewriteErrorHandler',
(source, chunk, hash) => {
expect(source).toBeDefined();
expect(chunk).toBeDefined();
expect(hash).toBeDefined();
return 'head.onerror = console.error;';
}
);
}
);
}
}
const compiler = getCompiler(
'./esmAsync.js',
{ esModule: true },
{
mode: 'production',
optimization: { minimize: false },
plugins: [
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css',
}),
new RewriteErrorHandler(),
],
}
);
const stats = await compile(compiler);
const content = stats.compilation.assets['main.bundle.js'].source();
expect(stats.hasErrors()).toBe(false);
expect(content).toMatchSnapshot();
done();
});