-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathasync-chunks_spec.ts
127 lines (119 loc) · 3.21 KB
/
async-chunks_spec.ts
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import * as webpack from 'webpack';
import { markAsyncChunksNonInitial } from './async-chunks';
describe('async-chunks', () => {
describe('markAsyncChunksNonInitial()', () => {
it('sets `initial: false` for all extra entry points loaded asynchronously', () => {
const chunks = [
{
id: 0,
names: ['first'],
initial: true,
},
{
id: 1,
names: ['second'],
initial: true,
},
{
id: 'third', // IDs can be strings too.
names: ['third'],
initial: true,
},
];
const entrypoints = {
first: {
chunks: [0],
},
second: {
chunks: [1],
},
third: {
chunks: ['third'],
},
};
const webpackStats = { chunks, entrypoints } as unknown as webpack.Stats.ToJsonOutput;
const extraEntryPoints = [
{
bundleName: 'first',
inject: false, // Loaded asynchronously.
input: 'first.css',
},
{
bundleName: 'second',
inject: true,
input: 'second.js',
},
{
bundleName: 'third',
inject: false, // Loaded asynchronously.
input: 'third.js',
},
];
const newChunks = markAsyncChunksNonInitial(webpackStats, extraEntryPoints);
expect(newChunks).toEqual([
{
id: 0,
names: ['first'],
initial: false, // No longer initial because it was marked async.
},
{
id: 1,
names: ['second'],
initial: true,
},
{
id: 'third',
names: ['third'],
initial: false, // No longer initial because it was marked async.
},
] as Exclude<webpack.Stats.ToJsonOutput['chunks'], undefined>);
});
it('ignores runtime dependency of async chunks', () => {
const chunks = [
{
id: 0,
names: ['asyncStuff'],
initial: true,
},
{
id: 1,
names: ['runtime'],
initial: true,
},
];
const entrypoints = {
asyncStuff: {
chunks: [0, 1], // Includes runtime as a dependency.
},
};
const webpackStats = { chunks, entrypoints } as unknown as webpack.Stats.ToJsonOutput;
const extraEntryPoints = [
{
bundleName: 'asyncStuff',
inject: false, // Loaded asynchronously.
input: 'asyncStuff.js',
},
];
const newChunks = markAsyncChunksNonInitial(webpackStats, extraEntryPoints);
expect(newChunks).toEqual([
{
id: 0,
names: ['asyncStuff'],
initial: false, // No longer initial because it was marked async.
},
{
id: 1,
names: ['runtime'],
initial: true, // Still initial, even though its a dependency.
},
] as Exclude<webpack.Stats.ToJsonOutput['chunks'], undefined>);
});
});
});