From bacf6ed2c1929bba386ddd0286fb9f86a7c3b83b Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Mon, 15 Nov 2021 12:15:25 +0100 Subject: [PATCH] smoke - properly create screenshots and stop instances (#137220) --- .../areas/workbench/data-migration.test.ts | 20 ++++++++++++++----- test/smoke/src/areas/workbench/launch.test.ts | 20 ++++--------------- test/smoke/src/main.ts | 2 +- test/smoke/src/utils.ts | 8 ++++++-- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/test/smoke/src/areas/workbench/data-migration.test.ts b/test/smoke/src/areas/workbench/data-migration.test.ts index e852e2e30ad..11786a1d62a 100644 --- a/test/smoke/src/areas/workbench/data-migration.test.ts +++ b/test/smoke/src/areas/workbench/data-migration.test.ts @@ -6,11 +6,17 @@ import { Application, ApplicationOptions, Quality } from '../../../../automation'; import { join } from 'path'; import { ParsedArgs } from 'minimist'; -import { timeout } from '../../utils'; +import { afterSuite, timeout } from '../../utils'; export function setup(opts: ParsedArgs, testDataPath: string) { describe('Datamigration', () => { + + let insidersApp: Application | undefined = undefined; + let stableApp: Application | undefined = undefined; + + afterSuite(opts, () => insidersApp, async () => stableApp?.stop()); + it(`verifies opened editors are restored`, async function () { const stableCodePath = opts['stable-build']; if (!stableCodePath) { @@ -31,7 +37,7 @@ export function setup(opts: ParsedArgs, testDataPath: string) { stableOptions.userDataDir = userDataDir; stableOptions.quality = Quality.Stable; - const stableApp = new Application(stableOptions); + stableApp = new Application(stableOptions); await stableApp.start(); // Open 3 editors and pin 2 of them @@ -44,11 +50,12 @@ export function setup(opts: ParsedArgs, testDataPath: string) { await stableApp.workbench.editors.newUntitledFile(); await stableApp.stop(); + stableApp = undefined; const insiderOptions: ApplicationOptions = Object.assign({}, this.defaultOptions); insiderOptions.userDataDir = userDataDir; - const insidersApp = new Application(insiderOptions); + insidersApp = new Application(insiderOptions); await insidersApp.start(); // Verify 3 editors are open @@ -57,6 +64,7 @@ export function setup(opts: ParsedArgs, testDataPath: string) { await insidersApp.workbench.editors.selectTab('www'); await insidersApp.stop(); + insidersApp = undefined; }); it(`verifies that 'hot exit' works for dirty files`, async function () { @@ -72,7 +80,7 @@ export function setup(opts: ParsedArgs, testDataPath: string) { stableOptions.userDataDir = userDataDir; stableOptions.quality = Quality.Stable; - const stableApp = new Application(stableOptions); + stableApp = new Application(stableOptions); await stableApp.start(); await stableApp.workbench.editors.newUntitledFile(); @@ -89,11 +97,12 @@ export function setup(opts: ParsedArgs, testDataPath: string) { await timeout(2000); // give time to store the backup before stopping the app await stableApp.stop(); + stableApp = undefined; const insiderOptions: ApplicationOptions = Object.assign({}, this.defaultOptions); insiderOptions.userDataDir = userDataDir; - const insidersApp = new Application(insiderOptions); + insidersApp = new Application(insiderOptions); await insidersApp.start(); await insidersApp.workbench.editors.waitForTab(readmeMd, true); @@ -105,6 +114,7 @@ export function setup(opts: ParsedArgs, testDataPath: string) { await insidersApp.workbench.editor.waitForEditorContents(untitled, c => c.indexOf(textToTypeInUntitled) > -1); await insidersApp.stop(); + insidersApp = undefined; }); }); } diff --git a/test/smoke/src/areas/workbench/launch.test.ts b/test/smoke/src/areas/workbench/launch.test.ts index 0365098ff24..93074dec346 100644 --- a/test/smoke/src/areas/workbench/launch.test.ts +++ b/test/smoke/src/areas/workbench/launch.test.ts @@ -3,29 +3,18 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import minimist = require('minimist'); import * as path from 'path'; import { Application, ApplicationOptions } from '../../../../automation'; +import { afterSuite } from '../../utils'; -export function setup() { +export function setup(opts: minimist.ParsedArgs) { describe('Launch', () => { let app: Application; - after(async function () { - if (app) { - await app.stop(); - } - }); - - afterEach(async function () { - if (app) { - if (this.currentTest!.state === 'failed') { - const name = this.currentTest!.fullTitle().replace(/[^a-z0-9\-]/ig, '_'); - await app.captureScreenshot(name); - } - } - }); + afterSuite(opts, () => app); it(`verifies that application launches when user data directory has non-ascii characters`, async function () { const defaultOptions = this.defaultOptions as ApplicationOptions; @@ -33,6 +22,5 @@ export function setup() { app = new Application(options); await app.start(); }); - }); } diff --git a/test/smoke/src/main.ts b/test/smoke/src/main.ts index bae2e43cc51..1cf54e68e77 100644 --- a/test/smoke/src/main.ts +++ b/test/smoke/src/main.ts @@ -356,7 +356,7 @@ describe(`VSCode Smoke Tests (${opts.web ? 'Web' : 'Electron'})`, () => { setupExtensionTests(opts); if (!opts.web) { setupMultirootTests(opts); } if (!opts.web) { setupLocalizationTests(opts); } - if (!opts.web) { setupLaunchTests(); } + if (!opts.web) { setupLaunchTests(opts); } // TODO: Enable terminal tests for non-web if (opts.web) { setupTerminalProfileTests(opts); } diff --git a/test/smoke/src/utils.ts b/test/smoke/src/utils.ts index 727a994e6de..8eb977a3681 100644 --- a/test/smoke/src/utils.ts +++ b/test/smoke/src/utils.ts @@ -42,9 +42,9 @@ export function beforeSuite(opts: minimist.ParsedArgs, optionsTransform?: (opts: }); } -export function afterSuite(opts: minimist.ParsedArgs) { +export function afterSuite(opts: minimist.ParsedArgs, appFn?: () => Application | undefined, joinFn?: () => Promise) { after(async function () { - const app = this.app as Application; + const app: Application = appFn?.() ?? this.app; if (this.currentTest?.state === 'failed' && opts.screenshots) { const name = this.currentTest!.fullTitle().replace(/[^a-z0-9\-]/ig, '_'); @@ -58,6 +58,10 @@ export function afterSuite(opts: minimist.ParsedArgs) { if (app) { await app.stop(); } + + if (joinFn) { + await joinFn(); + } }); }