-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy pathsourcesTest.ts
282 lines (244 loc) · 10.2 KB
/
sourcesTest.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
import { expect } from 'chai';
import { join } from 'path';
import Dap from '../../dap/api';
import { createFileTree } from '../createFileTree';
import { ITestHandle, testFixturesDir, testWorkspace } from '../test';
import { itIntegrates, waitForPause } from '../testIntegrationUtils';
describe('sources', () => {
async function dumpSource(p: ITestHandle, event: Dap.LoadedSourceEventParams, name: string) {
p.log('\nSource event for ' + name);
p.log(event);
const content = await p.dap.source({
sourceReference: event.source.sourceReference!,
source: {
path: event.source.path,
sourceReference: event.source.sourceReference,
},
});
p.log(`${content.mimeType}`);
p.log('---------');
p.log(content.content);
p.log('---------');
}
itIntegrates('basic sources', async ({ r }) => {
const p = await r.launchUrl('inlinescript.html');
p.load();
await dumpSource(p, await p.waitForSource('inline'), 'inline');
p.addScriptTag('empty.js');
await dumpSource(p, await p.waitForSource('empty.js'), 'empty.js');
p.evaluate('17', 'doesnotexist.js');
await dumpSource(p, await p.waitForSource('doesnotexist'), 'does not exist');
p.addScriptTag('dir/helloworld.js');
await dumpSource(p, await p.waitForSource('helloworld'), 'dir/helloworld');
p.evaluate('42', '');
await dumpSource(p, await p.waitForSource('eval'), 'eval');
p.log(await p.dap.loadedSources({}), '\nLoaded sources: ');
p.assertLog();
});
itIntegrates('updated content', async ({ r }) => {
const p = await r.launchUrlAndLoad('index.html');
p.cdp.Runtime.evaluate({ expression: 'content1//# sourceURL=test.js' });
await dumpSource(p, await p.waitForSource('test'), 'test.js');
p.cdp.Runtime.evaluate({ expression: 'content2//# sourceURL=test.js' });
await dumpSource(p, await p.waitForSource('test'), 'test.js updated');
p.log(await p.dap.loadedSources({}), '\nLoaded sources: ');
p.assertLog();
});
itIntegrates('basic source map', async ({ r }) => {
const p = await r.launchUrlAndLoad('index.html');
p.addScriptTag('browserify/bundle.js');
const sources = await Promise.all([
p.waitForSource('index.ts'),
p.waitForSource('module1.ts'),
p.waitForSource('module2.ts'),
]);
for (const source of sources) await dumpSource(p, source, '');
p.assertLog();
});
itIntegrates('waiting for source map', async ({ r }) => {
const p = await r.launchUrlAndLoad('index.html');
await p.addScriptTag('browserify/bundle.js');
p.dap.evaluate({ expression: `setTimeout(() => { window.throwError('error2')}, 0)` });
await p.logger.logOutput(await p.dap.once('output'));
p.assertLog();
});
itIntegrates.skip('waiting for source map failure', async ({ r }) => {
const p = await r.launchUrlAndLoad('index.html');
p.adapter.sourceContainer.setSourceMapTimeouts({
load: 2000,
resolveLocation: 0,
output: 0,
sourceMapMinPause: 0,
sourceMapCumulativePause: 0,
});
await p.addScriptTag('browserify/bundle.js');
p.dap.evaluate({ expression: `setTimeout(() => { window.throwError('error2')}, 0)` });
await p.logger.logOutput(await p.dap.once('output'));
p.assertLog();
});
itIntegrates('supports nested sourcemaps (#1390)', async ({ r }) => {
await r.initialize;
const cwd = join(testWorkspace, 'nestedSourceMaps');
const handle = await r.runScript(join(cwd, 'a/main.bundle.js'), { cwd });
await handle.dap.setBreakpoints({
source: { path: join(testWorkspace, 'nestedSourceMaps', 'b', 'lib.js') },
breakpoints: [{ line: 2, column: 1 }],
});
handle.load();
await waitForPause(handle);
handle.assertLog({ substring: true });
});
itIntegrates('supports remote sources (#1424)', async ({ r }) => {
const p = await r.launchUrlAndLoad('index.html');
p.addScriptTag('remote-test/string.js');
const source = await p.waitForSource('string.ts');
await dumpSource(p, source, '');
p.assertLog();
});
itIntegrates('works with relative webpack sourcemaps (#479)', async ({ r }) => {
const p = await r.launchUrl('webpack/relative-paths.html');
await p.dap.setBreakpoints({
source: { path: p.workspacePath('greet.js') },
breakpoints: [{ line: 2, column: 1 }],
});
await p.dap.setBreakpoints({
source: { path: p.workspacePath('web/webpack/farewell.js') },
breakpoints: [{ line: 2, column: 1 }],
});
p.load();
await waitForPause(p); // greet
await waitForPause(p); // farewell
p.assertLog();
});
itIntegrates('allows overrides for relative webpack paths (#479)', async ({ r }) => {
const p = await r.launchUrl('webpack/relative-paths.html', {
sourceMapPathOverrides: {
'webpack:///./*': '${webRoot}/*',
'webpack:///../*': '${webRoot}/was-nested/*',
},
});
await p.dap.setBreakpoints({
source: { path: p.workspacePath('web/was-nested/greet.js') },
breakpoints: [{ line: 2, column: 1 }],
});
await p.dap.setBreakpoints({
source: { path: p.workspacePath('web/webpack/farewell.js') },
breakpoints: [{ line: 2, column: 1 }],
});
p.load();
await waitForPause(p); // greet
await waitForPause(p); // farewell
p.assertLog();
});
itIntegrates('url and hash', async ({ r }) => {
const p = await r.launchUrlAndLoad('index.html');
p.cdp.Runtime.evaluate({ expression: 'a\n//# sourceURL=foo.js' });
await dumpSource(p, await p.waitForSource('foo.js'), 'foo.js');
// Same url, different content => different source.
p.cdp.Runtime.evaluate({ expression: 'b\n//# sourceURL=foo.js' });
await dumpSource(p, await p.waitForSource('foo.js'), 'foo.js');
// Same url, same content => same sources.
await p.cdp.Runtime.evaluate({ expression: 'a\n//# sourceURL=foo.js' });
await p.cdp.Runtime.evaluate({ expression: 'b\n//# sourceURL=foo.js' });
// Content matches => maps to file.
p.addScriptTag('empty.js');
await dumpSource(p, await p.waitForSource('empty.js'), 'empty.js');
// Content does not match => debugger script.
const path = p.workspacePath('web/empty2.js');
p.adapter.sourceContainer.setFileContentOverrideForTest(path, '123');
p.addScriptTag('empty2.js');
await dumpSource(p, await p.waitForSource('empty2.js'), 'empty2.js');
p.log(await p.dap.loadedSources({}), '\nLoaded sources: ');
p.assertLog();
});
itIntegrates('allows module wrapper in node code', async ({ r }) => {
const handle = await r.runScript(join(testWorkspace, 'moduleWrapper', 'index.js'));
handle.load();
const src = await handle.waitForSource('moduleWrapper/test.js');
expect(src.source.sourceReference).to.equal(0);
});
itIntegrates('verifies content when enableContentValidation=true', async ({ r }) => {
const handle = await r.runScript(join(testWorkspace, 'moduleWrapper', 'customWrapper.js'));
handle.load();
const src = await handle.waitForSource('moduleWrapper/test.js');
expect(src.source.sourceReference).to.be.greaterThan(0);
});
itIntegrates('does not verify content when enableContentValidation=false', async ({ r }) => {
const handle = await r.runScript(join(testWorkspace, 'moduleWrapper', 'customWrapper.js'), {
enableContentValidation: false,
});
handle.load();
const src = await handle.waitForSource('moduleWrapper/test.js');
expect(src.source.sourceReference).to.equal(0);
});
itIntegrates('allows shebang in node code', async ({ r }) => {
createFileTree(testFixturesDir, {
index: 'require("./shebang-lf"); require("./shebang-crlf"); debugger;',
'shebang-lf': '#!/bin/node\nconsole.log("hello world")',
'shebang-crlf': '#!/bin/node\r\nconsole.log("hello world")',
});
const handle = await r.runScript(join(testFixturesDir, 'index'));
handle.load();
const lf = handle.waitForSource('shebang-lf');
const crlf = handle.waitForSource('shebang-crlf');
handle.log(await lf, undefined, []);
handle.log(await crlf, undefined, []);
handle.assertLog();
});
itIntegrates('removes any query from node paths (#529)', async ({ r }) => {
const handle = await r.runScript(
join(testWorkspace, 'simpleNode', 'simpleWebpackWithQuery.js'),
{
cwd: join(testWorkspace, 'simpleNode'),
},
);
handle.load();
handle.log(await handle.waitForSource('simpleWebpackWithQuery.ts'), undefined, []);
handle.assertLog();
});
describe('sourcemap error handling', () => {
itIntegrates('logs initial parse errors', async ({ r }) => {
const p = await r.launchUrlAndLoad('index.html');
const output = p.dap.once('output', o => o.category === 'stderr');
await p.evaluate(
'//# sourceMappingURL=data:application/json;charset=utf-8;base64,ZGV2cw==\n',
);
await p.logger.logOutput(await output);
p.assertLog();
});
itIntegrates('logs not found errors', async ({ r }) => {
const p = await r.launchUrlAndLoad('index.html');
const output = p.dap.once('output', o => o.category === 'stderr');
await p.evaluate('//# sourceMappingURL=does-not-exist.js.map\n');
await p.logger.logOutput(await output);
p.assertLog();
});
itIntegrates('logs lazy parse errors', async ({ r }) => {
const p = await r.launchUrlAndLoad('index.html');
await p.dap.setBreakpoints({
source: { path: p.workspacePath('web/eval1Source.js') },
breakpoints: [{ line: 1, column: 1 }],
});
const output = r.rootDap().once('output', o => o.category === 'stderr');
const contents = Buffer.from(
JSON.stringify({
version: 3,
file: 'eval1.js',
sourceRoot: '',
sources: ['eval1Source.js'],
mappings: '#,####;',
}),
).toString('base64');
const ev = p.evaluate(
`//# sourceMappingURL=data:application/json;charset=utf-8;base64,${contents}\n`,
);
await p.logger.logOutput(await output);
await waitForPause(p);
await ev;
p.assertLog();
});
});
});