-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathsource-map_spec_large.ts
170 lines (144 loc) · 5.42 KB
/
source-map_spec_large.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/**
* @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 { Architect } from '@angular-devkit/architect';
import { OutputHashing } from '../../src/browser/schema';
import { browserBuild, createArchitect, host } from '../utils';
// tslint:disable-next-line:no-big-function
describe('Browser Builder source map', () => {
const target = { project: 'app', target: 'build' };
let architect: Architect;
beforeEach(async () => {
await host.initialize().toPromise();
architect = (await createArchitect(host.root())).architect;
});
afterEach(async () => host.restore().toPromise());
it('works', async () => {
const overrides = {
sourceMap: true,
extractCss: true,
styles: ['src/styles.css'],
};
host.writeMultipleFiles({
'src/styles.css': `div { flex: 1 }`,
});
const { files } = await browserBuild(architect, host, target, overrides);
expect(await files['main.js.map']).not.toBeUndefined();
expect(await files['styles.css.map']).not.toBeUndefined();
});
it(`sourcemaps sources should not start with '/'`, async () => {
// If sourcemaps sources start with a '/' it will break VS code breakpoints
// Unless 'sourceMapPathOverrides' are provided
const overrides = {
sourceMap: true,
};
const { files } = await browserBuild(architect, host, target, overrides);
const mainJSMap = await files['main.js.map'];
expect(mainJSMap).not.toBeUndefined();
const sources: string[] = JSON.parse(mainJSMap).sources;
for (const source of sources) {
expect(source.startsWith('/')).toBe(false, `${source} started with an '/'.`);
}
});
it('works with outputHashing', async () => {
const { files } = await browserBuild(architect, host, target, {
sourceMap: true,
outputHashing: OutputHashing.All,
});
expect(Object.keys(files).some(name => /main\.[0-9a-f]{20}\.js.map/.test(name))).toBeTruthy();
});
it('does not output source map when disabled', async () => {
const { files } = await browserBuild(architect, host, target, {
sourceMap: false,
});
expect(files['main.js.map']).toBeUndefined();
});
it('supports eval source map', async () => {
const { files } = await browserBuild(architect, host, target, {
sourceMap: true, evalSourceMap: true,
});
expect(files['main.js.map']).toBeUndefined();
expect(await files['main.js']).toContain('eval("function webpackEmptyAsyncContext');
});
it('supports hidden sourcemaps', async () => {
const overrides = {
sourceMap: {
hidden: true,
styles: true,
scripts: true,
},
extractCss: true,
styles: ['src/styles.scss'],
};
host.writeMultipleFiles({
'src/styles.scss': `div { flex: 1 }`,
});
const { files } = await browserBuild(architect, host, target, overrides);
expect('main.js.map' in files).toBe(true);
expect('styles.css.map' in files).toBe(true);
expect(await files['main.js']).not.toContain('sourceMappingURL=main.js.map');
expect(await files['styles.css']).not.toContain('sourceMappingURL=styles.css.map');
});
it('supports styles only sourcemaps', async () => {
const overrides = {
sourceMap: {
styles: true,
scripts: false,
},
extractCss: true,
styles: ['src/styles.scss'],
};
host.writeMultipleFiles({
'src/styles.scss': `div { flex: 1 }`,
});
const { files } = await browserBuild(architect, host, target, overrides);
expect('main.js.map' in files).toBe(false);
expect('styles.css.map' in files).toBe(true);
expect(await files['main.js']).not.toContain('sourceMappingURL=main.js.map');
expect(await files['styles.css']).toContain('sourceMappingURL=styles.css.map');
});
it('supports scripts only sourcemaps', async () => {
const overrides = {
sourceMap: {
styles: false,
scripts: true,
},
extractCss: true,
styles: ['src/styles.scss'],
};
host.writeMultipleFiles({
'src/styles.scss': `div { flex: 1 }`,
});
const { files } = await browserBuild(architect, host, target, overrides);
expect('main.js.map' in files).toBe(true);
expect('styles.css.map' in files).toBe(false);
expect(await files['main.js']).toContain('sourceMappingURL=main.js.map');
expect(await files['styles.css']).not.toContain('sourceMappingURL=styles.css.map');
});
it('should not inline component styles sourcemaps when hidden', async () => {
const overrides = {
sourceMap: {
hidden: true,
styles: true,
scripts: true,
},
extractCss: true,
styles: ['src/styles.scss'],
};
host.writeMultipleFiles({
'src/styles.scss': `div { flex: 1 }`,
'src/app/app.component.css': `p { color: red; }`,
});
const { files } = await browserBuild(architect, host, target, overrides);
expect('main.js.map' in files).toBe(true);
expect('styles.css.map' in files).toBe(true);
expect(await files['main.js']).not.toContain('sourceMappingURL=main.js.map');
expect(await files['main.js']).not.toContain('sourceMappingURL=data:application/json');
expect(await files['styles.css']).not.toContain('sourceMappingURL=styles.css.map');
expect(await files['styles.css']).not.toContain('sourceMappingURL=data:application/json');
});
});