-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
_config.js
70 lines (69 loc) · 1.76 KB
/
_config.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
68
69
70
const assert = require('node:assert');
const path = require('node:path');
// @ts-expect-error not included in types
const { getObject } = require('../../../../utils');
module.exports = defineTest({
description: 'associates empty modules with chunks if tree-shaking is disabled for them',
options: {
strictDeprecations: false,
input: ['main1.js', 'main2.js'],
plugins: {
resolveId(id) {
if (id.startsWith('empty')) {
if (id === 'emptyResolved') {
return {
id,
moduleSideEffects: 'no-treeshake'
};
}
return id;
}
},
load(id) {
if (id.startsWith('empty')) {
if (id === 'emptyLoaded') {
return { code: '', moduleSideEffects: 'no-treeshake' };
}
return '';
}
},
transform(code, id) {
if (id === 'emptyTransformed') {
return { code: '', moduleSideEffects: 'no-treeshake' };
}
},
generateBundle(options, bundle) {
assert.deepStrictEqual(
getObject(
[...this.getModuleIds()].map(id => [
id.startsWith('empty') ? id : path.relative(__dirname, id),
this.getModuleInfo(id).hasModuleSideEffects
])
),
{
empty: true,
emptyLoaded: 'no-treeshake',
emptyResolved: 'no-treeshake',
emptyTransformed: 'no-treeshake',
'main1.js': true,
'main2.js': true
}
);
assert.deepStrictEqual(
getObject(
Object.entries(bundle).map(([chunkId, chunk]) => [
chunkId,
Object.keys(chunk.modules).map(moduleId => path.relative(__dirname, moduleId))
])
),
{
'main1.js': ['emptyResolved', 'main1.js'],
'main2.js': ['emptyLoaded', 'main2.js'],
'generated-emptyTransformed.js': ['emptyTransformed']
}
);
}
}
},
expectedWarnings: ['DEPRECATED_FEATURE']
});