generated from Richienb/node-module-boilerplate
-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathtest.js
67 lines (56 loc) · 1.83 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
62
63
64
65
66
67
const {promises: fs} = require('node:fs'); // eslint-disable-line n/no-unsupported-features/node-builtins
const test = require('ava');
const webpack = require('p-webpack');
const NodePolyfillPlugin = require('./index.js');
test('main', async t => {
await webpack({
entry: './fixtures/main',
output: {
library: {
type: 'commonjs-module',
},
filename: '1.js',
},
plugins: [
new NodePolyfillPlugin({
additionalAliases: ['assert', 'buffer'],
// ExcludeAliases: ['console'],
}),
],
});
t.is(require('./dist/1.js'), 'Hello World');
const output = await fs.readFile('./dist/1.js', {encoding: 'utf8'});
// https://github.com/browserify/console-browserify/blob/f7eefc7c908c29d2e94954e5c6c1098e8c1028b4/index.js#L63
t.false(output.includes('No such label: '));
// https://github.com/feross/buffer/blob/5857e295f4d37e3ad02c3abcbf7e8e5ef51f3be6/index.js#L101
t.true(output.includes('is invalid for option "size"'));
});
test('includeAliases', async t => {
await webpack({
entry: './fixtures/main',
output: {
library: {
type: 'commonjs-module',
},
filename: '2.js',
},
plugins: [
new NodePolyfillPlugin({
additionalAliases: ['console', 'assert'],
excludeAliases: ['buffer', 'Buffer'],
}),
],
});
t.is(require('./dist/2.js'), 'Hello World');
const output = await fs.readFile('./dist/2.js', {encoding: 'utf8'});
// https://github.com/browserify/console-browserify/blob/f7eefc7c908c29d2e94954e5c6c1098e8c1028b4/index.js#L63
t.true(output.includes('No such label: '));
// https://github.com/feross/buffer/blob/master/index.js#L80
t.false(output.includes('is invalid for option "size"'));
});
test('onlyAliases and excludeAliases used at the same time', t => {
t.throws(() => new NodePolyfillPlugin({
onlyAliases: ['console'],
excludeAliases: ['crypto'],
}), {instanceOf: Error});
});