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
|
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { join } from 'path';
import { Application, ApplicationOptions, Logger, Quality } from '../../../../automation';
import { createApp, timeout, installDiagnosticsHandler, installAppAfterHandler, getRandomUserDataDir, suiteLogsPath } from '../../utils';
export function setup(ensureStableCode: () => string | undefined, logger: Logger) {
describe('Data Loss (insiders -> insiders)', () => {
let app: Application | undefined = undefined;
// Shared before/after handling
installDiagnosticsHandler(logger, () => app);
installAppAfterHandler(() => app);
it('verifies opened editors are restored', async function () {
app = createApp({
...this.defaultOptions,
logsPath: suiteLogsPath(this.defaultOptions, 'test_verifies_opened_editors_are_restored')
});
await app.start();
// Open 3 editors
await app.workbench.quickaccess.openFile(join(app.workspacePathOrFolder, 'bin', 'www'));
await app.workbench.quickaccess.runCommand('View: Keep Editor');
await app.workbench.quickaccess.openFile(join(app.workspacePathOrFolder, 'app.js'));
await app.workbench.quickaccess.runCommand('View: Keep Editor');
await app.workbench.editors.newUntitledFile();
await app.restart();
// Verify 3 editors are open
await app.workbench.editors.selectTab('Untitled-1');
await app.workbench.editors.selectTab('app.js');
await app.workbench.editors.selectTab('www');
await app.stop();
app = undefined;
});
it('verifies editors can save and restore', async function () {
app = createApp({
...this.defaultOptions,
logsPath: suiteLogsPath(this.defaultOptions, 'test_verifies_editors_can_save_and_restore')
});
await app.start();
const textToType = 'Hello, Code';
// open editor and type
await app.workbench.quickaccess.openFile(join(app.workspacePathOrFolder, 'app.js'));
await app.workbench.editor.waitForTypeInEditor('app.js', textToType);
await app.workbench.editors.waitForTab('app.js', true);
// save
await app.workbench.editors.saveOpenedFile();
await app.workbench.editors.waitForTab('app.js', false);
// restart
await app.restart();
// verify contents
await app.workbench.editor.waitForEditorContents('app.js', contents => contents.indexOf(textToType) > -1);
await app.stop();
app = undefined;
});
it('verifies that "hot exit" works for dirty files (without delay)', function () {
return testHotExit.call(this, 'test_verifies_that_hot_exit_works_for_dirty_files_without_delay', undefined);
});
it('verifies that "hot exit" works for dirty files (with delay)', function () {
return testHotExit.call(this, 'test_verifies_that_hot_exit_works_for_dirty_files_with_delay', 2000);
});
it('verifies that auto save triggers on shutdown', function () {
return testHotExit.call(this, 'test_verifies_that_auto_save_triggers_on_shutdown', undefined, true);
});
async function testHotExit(title: string, restartDelay: number | undefined, autoSave: boolean | undefined) {
app = createApp({
...this.defaultOptions,
logsPath: suiteLogsPath(this.defaultOptions, title)
});
await app.start();
if (autoSave) {
await app.workbench.settingsEditor.addUserSetting('files.autoSave', '"afterDelay"');
}
const textToTypeInUntitled = 'Hello from Untitled';
await app.workbench.editors.newUntitledFile();
await app.workbench.editor.waitForTypeInEditor('Untitled-1', textToTypeInUntitled);
await app.workbench.editors.waitForTab('Untitled-1', true);
const textToType = 'Hello, Code';
await app.workbench.quickaccess.openFile(join(app.workspacePathOrFolder, 'readme.md'));
await app.workbench.editor.waitForTypeInEditor('readme.md', textToType);
await app.workbench.editors.waitForTab('readme.md', !autoSave);
if (typeof restartDelay === 'number') {
// this is an OK use of a timeout in a smoke test:
// we want to simulate a user having typed into
// the editor and pausing for a moment before
// terminating
await timeout(restartDelay);
}
await app.restart();
await app.workbench.editors.waitForTab('readme.md', !autoSave);
await app.workbench.editors.waitForTab('Untitled-1', true);
await app.workbench.editors.selectTab('readme.md');
await app.workbench.editor.waitForEditorContents('readme.md', contents => contents.indexOf(textToType) > -1);
await app.workbench.editors.selectTab('Untitled-1');
await app.workbench.editor.waitForEditorContents('Untitled-1', contents => contents.indexOf(textToTypeInUntitled) > -1);
await app.stop();
app = undefined;
}
});
describe.skip('Data Loss (stable -> insiders)', () => { //TODO@bpasero enable again once we shipped 1.67.x
let insidersApp: Application | undefined = undefined;
let stableApp: Application | undefined = undefined;
// Shared before/after handling
installDiagnosticsHandler(logger, () => insidersApp ?? stableApp);
installAppAfterHandler(() => insidersApp ?? stableApp, async () => stableApp?.stop());
it('verifies opened editors are restored', async function () {
const stableCodePath = ensureStableCode();
if (!stableCodePath) {
this.skip();
}
// macOS: the first launch of stable Code will trigger
// additional checks in the OS (notarization validation)
// so it can take a very long time. as such we install
// a retry handler to make sure we do not fail as a
// consequence.
if (process.platform === 'darwin') {
this.retries(2);
}
const userDataDir = getRandomUserDataDir(this.defaultOptions);
const logsPath = suiteLogsPath(this.defaultOptions, 'test_verifies_opened_editors_are_restored_from_stable');
const stableOptions: ApplicationOptions = Object.assign({}, this.defaultOptions);
stableOptions.codePath = stableCodePath;
stableOptions.userDataDir = userDataDir;
stableOptions.quality = Quality.Stable;
stableOptions.logsPath = logsPath;
stableApp = new Application(stableOptions);
await stableApp.start();
// Open 3 editors
await stableApp.workbench.quickaccess.openFile(join(stableApp.workspacePathOrFolder, 'bin', 'www'));
await stableApp.workbench.quickaccess.runCommand('View: Keep Editor');
await stableApp.workbench.quickaccess.openFile(join(stableApp.workspacePathOrFolder, 'app.js'));
await stableApp.workbench.quickaccess.runCommand('View: Keep Editor');
await stableApp.workbench.editors.newUntitledFile();
await stableApp.stop();
stableApp = undefined;
const insiderOptions: ApplicationOptions = Object.assign({}, this.defaultOptions);
insiderOptions.userDataDir = userDataDir;
insiderOptions.logsPath = logsPath;
insidersApp = new Application(insiderOptions);
await insidersApp.start();
// Verify 3 editors are open
await insidersApp.workbench.editors.selectTab('Untitled-1');
await insidersApp.workbench.editors.selectTab('app.js');
await insidersApp.workbench.editors.selectTab('www');
await insidersApp.stop();
insidersApp = undefined;
});
it('verifies that "hot exit" works for dirty files (without delay)', async function () {
return testHotExit.call(this, `test_verifies_that_hot_exit_works_for_dirty_files_without_delay_from_stable`, undefined);
});
it('verifies that "hot exit" works for dirty files (with delay)', async function () {
return testHotExit.call(this, `test_verifies_that_hot_exit_works_for_dirty_files_with_delay_from_stable`, 2000);
});
async function testHotExit(title: string, restartDelay: number | undefined) {
const stableCodePath = ensureStableCode();
if (!stableCodePath) {
this.skip();
}
const userDataDir = getRandomUserDataDir(this.defaultOptions);
const logsPath = suiteLogsPath(this.defaultOptions, title);
const stableOptions: ApplicationOptions = Object.assign({}, this.defaultOptions);
stableOptions.codePath = stableCodePath;
stableOptions.userDataDir = userDataDir;
stableOptions.quality = Quality.Stable;
stableOptions.logsPath = logsPath;
stableApp = new Application(stableOptions);
await stableApp.start();
const textToTypeInUntitled = 'Hello from Untitled';
await stableApp.workbench.editors.newUntitledFile();
await stableApp.workbench.editor.waitForTypeInEditor('Untitled-1', textToTypeInUntitled);
await stableApp.workbench.editors.waitForTab('Untitled-1', true);
const textToType = 'Hello, Code';
await stableApp.workbench.quickaccess.openFile(join(stableApp.workspacePathOrFolder, 'readme.md'));
await stableApp.workbench.editor.waitForTypeInEditor('readme.md', textToType);
await stableApp.workbench.editors.waitForTab('readme.md', true);
if (typeof restartDelay === 'number') {
// this is an OK use of a timeout in a smoke test
// we want to simulate a user having typed into
// the editor and pausing for a moment before
// terminating
await timeout(restartDelay);
}
await stableApp.stop();
stableApp = undefined;
const insiderOptions: ApplicationOptions = Object.assign({}, this.defaultOptions);
insiderOptions.userDataDir = userDataDir;
insiderOptions.logsPath = logsPath;
insidersApp = new Application(insiderOptions);
await insidersApp.start();
await insidersApp.workbench.editors.waitForTab('readme.md', true);
await insidersApp.workbench.editors.waitForTab('Untitled-1', true);
await insidersApp.workbench.editors.selectTab('readme.md');
await insidersApp.workbench.editor.waitForEditorContents('readme.md', contents => contents.indexOf(textToType) > -1);
await insidersApp.workbench.editors.selectTab('Untitled-1');
await insidersApp.workbench.editor.waitForEditorContents('Untitled-1', contents => contents.indexOf(textToTypeInUntitled) > -1);
await insidersApp.stop();
insidersApp = undefined;
}
});
}
|