/
script-in-multiple-workers_test.ts
211 lines (160 loc) · 6.88 KB
/
script-in-multiple-workers_test.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
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {assert} from 'chai';
import {describe, it} from 'mocha';
import * as puppeteer from 'puppeteer';
import {click, getBrowserAndPages, goToResource, step, waitFor} from '../../shared/helper.js';
import {addBreakpointForLine, createSelectorsForWorkerFile, getBreakpointDecorators, getExecutionLine, getOpenSources, openNestedWorkerFile, PAUSE_BUTTON, RESUME_BUTTON} from '../helpers/sources-helpers.js';
async function validateSourceTabs() {
await step('Validate exactly one source file is open', async () => {
assert.deepEqual(await getOpenSources(), ['multi-workers.js']);
});
}
describe('Multi-Workers', async function() {
// The tests in this suite are particularly slow, as they perform a lot of actions
this.timeout(10000);
[false, true].forEach(sourceMaps => {
const withOrWithout = sourceMaps ? 'with source maps' : 'without source maps';
const targetPage = sourceMaps ? 'sources/multi-workers-sourcemap.html' : 'sources/multi-workers.html';
const scriptFile = sourceMaps ? 'multi-workers.min.js' : 'multi-workers.js';
function workerFileSelectors(workerIndex: number) {
return createSelectorsForWorkerFile(scriptFile, 'test/e2e/resources/sources', 'multi-workers.js', workerIndex);
}
async function validateNavigationTree() {
await step('Ensure 10 works exist', async () => {
await waitFor(workerFileSelectors(10).rootSelector);
});
}
async function validateBreakpoints(frontend: puppeteer.Page) {
assert.deepEqual(await getBreakpointDecorators(frontend), [6, 12]);
assert.deepEqual(await getBreakpointDecorators(frontend, true), [6]);
}
it(`loads scripts exactly once on reload ${withOrWithout}`, async () => {
// Have the target load the page.
await goToResource(targetPage);
await click('#tab-sources');
await validateNavigationTree();
await openNestedWorkerFile(workerFileSelectors(1));
// Look at source tabs
await validateSourceTabs();
// Reload page
await goToResource(targetPage);
// Check workers again
await validateNavigationTree();
// Look at source tabs again
await validateSourceTabs();
});
// Flaky test
it.skip(`[crbug.com/1073406]: loads scripts exactly once on break ${withOrWithout}`, async () => {
const {target} = getBrowserAndPages();
// Have the target load the page.
await goToResource(targetPage);
await click('#tab-sources');
await validateNavigationTree();
// Send message to a worker to trigger break
await target.evaluate('workers[3].postMessage({command:"break"});');
// Should automatically switch to sources tab.
// Validate that we are paused by locating the resume button
await waitFor(RESUME_BUTTON);
// Look at source tabs
await validateSourceTabs();
// Continue
await click(RESUME_BUTTON);
// Verify that we have resumed.
await waitFor(PAUSE_BUTTON);
await target.evaluate('workers[7].postMessage({command:"break"});');
// Validate that we are paused
await waitFor(RESUME_BUTTON);
// Look at source tabs
await validateSourceTabs();
});
describe(`copies breakpoints between workers ${withOrWithout}`, () => {
beforeEach(async () => {
const {frontend} = getBrowserAndPages();
// Have the target load the page.
await goToResource(targetPage);
await click('#tab-sources');
// Wait for all workers to load
await validateNavigationTree();
// Open file from second worker
await openNestedWorkerFile(workerFileSelectors(2));
// Set two breakpoints
await addBreakpointForLine(frontend, 6);
// Disable first breakpoint
const bpEntry = await waitFor('.breakpoint-entry');
const bpCheckbox = await waitFor('input', bpEntry);
if (!bpCheckbox) {
assert.fail('Could not find checkbox to disable breakpoint');
return;
}
await bpCheckbox.evaluate(n => (n as HTMLElement).click());
await frontend.waitForSelector('.cm-breakpoint-disabled');
// Add another breakpoint
await addBreakpointForLine(frontend, 12);
// Check breakpoints
await validateBreakpoints(frontend);
// Close tab
await click('[aria-label="Close multi-workers.js"]');
});
it('when opening different file in editor', async () => {
const {frontend} = getBrowserAndPages();
// Open different worker
await openNestedWorkerFile(workerFileSelectors(3));
// Check breakpoints
await validateBreakpoints(frontend);
});
it('after reloading', async () => {
const {target, frontend} = getBrowserAndPages();
await target.reload();
// Open different worker
await openNestedWorkerFile(workerFileSelectors(4));
// Check breakpoints
await validateBreakpoints(frontend);
});
});
describe(`hits breakpoints added to workers ${withOrWithout}`, () => {
beforeEach(async () => {
const {frontend} = getBrowserAndPages();
// Have the target load the page.
await goToResource(targetPage);
await step('Open sources panel', async () => {
await click('#tab-sources');
});
await validateNavigationTree();
await step('Open second worker file', async () => {
await openNestedWorkerFile(workerFileSelectors(2));
});
await step('Set breakpoint', async () => {
await addBreakpointForLine(frontend, 6);
});
});
// Flaky test
it.skip('[crbug.com/1073406]: for pre-loaded workers', async () => {
const {target} = getBrowserAndPages();
// Send message to a worker to trigger break
await target.evaluate('workers[5].postMessage({});');
// Validate that we are paused by locating the resume button
await waitFor(RESUME_BUTTON);
// Validate that the source line is highlighted
assert.strictEqual(await getExecutionLine(), 6);
// Look at source tabs
await validateSourceTabs();
});
// Flaky test
it.skip('[crbug.com/1073406] for newly created workers', async () => {
const {target} = getBrowserAndPages();
await step('Launch new worker to hit breakpoint', async () => {
await target.evaluate(`new Worker('${scriptFile}').postMessage({});`);
});
await step('Validate that we are paused', async () => {
await waitFor(RESUME_BUTTON);
});
await step('Validate source line is highlighted', async () => {
assert.strictEqual(await getExecutionLine(), 6);
});
await validateSourceTabs();
});
});
});
});