Skip to content

Commit bacf6ed

Browse files
authored
smoke - properly create screenshots and stop instances (microsoft#137220)
1 parent c33965a commit bacf6ed

File tree

4 files changed

+26
-24
lines changed

4 files changed

+26
-24
lines changed

test/smoke/src/areas/workbench/data-migration.test.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@
66
import { Application, ApplicationOptions, Quality } from '../../../../automation';
77
import { join } from 'path';
88
import { ParsedArgs } from 'minimist';
9-
import { timeout } from '../../utils';
9+
import { afterSuite, timeout } from '../../utils';
1010

1111
export function setup(opts: ParsedArgs, testDataPath: string) {
1212

1313
describe('Datamigration', () => {
14+
15+
let insidersApp: Application | undefined = undefined;
16+
let stableApp: Application | undefined = undefined;
17+
18+
afterSuite(opts, () => insidersApp, async () => stableApp?.stop());
19+
1420
it(`verifies opened editors are restored`, async function () {
1521
const stableCodePath = opts['stable-build'];
1622
if (!stableCodePath) {
@@ -31,7 +37,7 @@ export function setup(opts: ParsedArgs, testDataPath: string) {
3137
stableOptions.userDataDir = userDataDir;
3238
stableOptions.quality = Quality.Stable;
3339

34-
const stableApp = new Application(stableOptions);
40+
stableApp = new Application(stableOptions);
3541
await stableApp.start();
3642

3743
// Open 3 editors and pin 2 of them
@@ -44,11 +50,12 @@ export function setup(opts: ParsedArgs, testDataPath: string) {
4450
await stableApp.workbench.editors.newUntitledFile();
4551

4652
await stableApp.stop();
53+
stableApp = undefined;
4754

4855
const insiderOptions: ApplicationOptions = Object.assign({}, this.defaultOptions);
4956
insiderOptions.userDataDir = userDataDir;
5057

51-
const insidersApp = new Application(insiderOptions);
58+
insidersApp = new Application(insiderOptions);
5259
await insidersApp.start();
5360

5461
// Verify 3 editors are open
@@ -57,6 +64,7 @@ export function setup(opts: ParsedArgs, testDataPath: string) {
5764
await insidersApp.workbench.editors.selectTab('www');
5865

5966
await insidersApp.stop();
67+
insidersApp = undefined;
6068
});
6169

6270
it(`verifies that 'hot exit' works for dirty files`, async function () {
@@ -72,7 +80,7 @@ export function setup(opts: ParsedArgs, testDataPath: string) {
7280
stableOptions.userDataDir = userDataDir;
7381
stableOptions.quality = Quality.Stable;
7482

75-
const stableApp = new Application(stableOptions);
83+
stableApp = new Application(stableOptions);
7684
await stableApp.start();
7785

7886
await stableApp.workbench.editors.newUntitledFile();
@@ -89,11 +97,12 @@ export function setup(opts: ParsedArgs, testDataPath: string) {
8997
await timeout(2000); // give time to store the backup before stopping the app
9098

9199
await stableApp.stop();
100+
stableApp = undefined;
92101

93102
const insiderOptions: ApplicationOptions = Object.assign({}, this.defaultOptions);
94103
insiderOptions.userDataDir = userDataDir;
95104

96-
const insidersApp = new Application(insiderOptions);
105+
insidersApp = new Application(insiderOptions);
97106
await insidersApp.start();
98107

99108
await insidersApp.workbench.editors.waitForTab(readmeMd, true);
@@ -105,6 +114,7 @@ export function setup(opts: ParsedArgs, testDataPath: string) {
105114
await insidersApp.workbench.editor.waitForEditorContents(untitled, c => c.indexOf(textToTypeInUntitled) > -1);
106115

107116
await insidersApp.stop();
117+
insidersApp = undefined;
108118
});
109119
});
110120
}

test/smoke/src/areas/workbench/launch.test.ts

+4-16
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,24 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import minimist = require('minimist');
67
import * as path from 'path';
78
import { Application, ApplicationOptions } from '../../../../automation';
9+
import { afterSuite } from '../../utils';
810

9-
export function setup() {
11+
export function setup(opts: minimist.ParsedArgs) {
1012

1113
describe('Launch', () => {
1214

1315
let app: Application;
1416

15-
after(async function () {
16-
if (app) {
17-
await app.stop();
18-
}
19-
});
20-
21-
afterEach(async function () {
22-
if (app) {
23-
if (this.currentTest!.state === 'failed') {
24-
const name = this.currentTest!.fullTitle().replace(/[^a-z0-9\-]/ig, '_');
25-
await app.captureScreenshot(name);
26-
}
27-
}
28-
});
17+
afterSuite(opts, () => app);
2918

3019
it(`verifies that application launches when user data directory has non-ascii characters`, async function () {
3120
const defaultOptions = this.defaultOptions as ApplicationOptions;
3221
const options: ApplicationOptions = { ...defaultOptions, userDataDir: path.join(defaultOptions.userDataDir, 'abcdø') };
3322
app = new Application(options);
3423
await app.start();
3524
});
36-
3725
});
3826
}

test/smoke/src/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ describe(`VSCode Smoke Tests (${opts.web ? 'Web' : 'Electron'})`, () => {
356356
setupExtensionTests(opts);
357357
if (!opts.web) { setupMultirootTests(opts); }
358358
if (!opts.web) { setupLocalizationTests(opts); }
359-
if (!opts.web) { setupLaunchTests(); }
359+
if (!opts.web) { setupLaunchTests(opts); }
360360

361361
// TODO: Enable terminal tests for non-web
362362
if (opts.web) { setupTerminalProfileTests(opts); }

test/smoke/src/utils.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ export function beforeSuite(opts: minimist.ParsedArgs, optionsTransform?: (opts:
4242
});
4343
}
4444

45-
export function afterSuite(opts: minimist.ParsedArgs) {
45+
export function afterSuite(opts: minimist.ParsedArgs, appFn?: () => Application | undefined, joinFn?: () => Promise<unknown>) {
4646
after(async function () {
47-
const app = this.app as Application;
47+
const app: Application = appFn?.() ?? this.app;
4848

4949
if (this.currentTest?.state === 'failed' && opts.screenshots) {
5050
const name = this.currentTest!.fullTitle().replace(/[^a-z0-9\-]/ig, '_');
@@ -58,6 +58,10 @@ export function afterSuite(opts: minimist.ParsedArgs) {
5858
if (app) {
5959
await app.stop();
6060
}
61+
62+
if (joinFn) {
63+
await joinFn();
64+
}
6165
});
6266
}
6367

0 commit comments

Comments
 (0)