forked from Richienb/node-polyfill-webpack-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
61 lines (52 loc) · 1.67 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
const fs = require('node:fs');
const test = require('ava');
const webpack = require('p-webpack');
const GopeedPolyfillPlugin = require('./index.js');
test('main', async t => {
await webpack({
entry: './fixture',
output: {
library: {
type: 'commonjs-module',
},
filename: '1.js',
},
plugins: [
new GopeedPolyfillPlugin({
excludeAliases: ['process'],
}),
],
});
t.is(require('./dist/1.js'), 'Hello World');
// https://github.com/defunctzombie/node-process/blob/77caa43cdaee4ea710aa14d11cea1705293c0ef3/browser.js#L16C8-L16C9
t.false(fs.readFileSync('./dist/1.js').toString().includes('clearTimeout has not been defined'));
// https://github.com/feross/buffer/blob/master/index.js#L80
t.true(fs.readFileSync('./dist/1.js').toString().includes('is invalid for option "size"'));
});
test('includeAliases', async t => {
await webpack({
entry: './fixture',
output: {
library: {
type: 'commonjs-module',
},
filename: '2.js',
},
plugins: [
new GopeedPolyfillPlugin({
includeAliases: ['process'],
}),
],
});
t.is(require('./dist/2.js'), 'Hello World');
// https://github.com/defunctzombie/node-process/blob/77caa43cdaee4ea710aa14d11cea1705293c0ef3/browser.js#L16C8-L16C9
t.true(fs.readFileSync('./dist/2.js').toString().includes('clearTimeout has not been defined'));
// https://github.com/feross/buffer/blob/master/index.js#L80
t.false(fs.readFileSync('./dist/2.js').toString().includes('is invalid for option "size"'));
});
test('includeAliases and excludeAliases used at the same time', t => {
t.throws(() => new GopeedPolyfillPlugin({
includeAliases: ['process'],
excludeAliases: ['crypto'],
}), {instanceOf: Error});
});