smoke - always have a logger

This commit is contained in:
Benjamin Pasero 2021-12-09 08:48:42 +01:00
parent 15415b6de6
commit 158bd2507e
No known key found for this signature in database
GPG key ID: E6380CC4C8219E65
19 changed files with 163 additions and 175 deletions

View file

@ -94,7 +94,7 @@ export class Application {
async captureScreenshot(name: string): Promise<void> {
if (this.options.screenshotsPath) {
const raw = await measureAndLog(this.code.capturePage(), 'capturePage', this.options.logger);
const raw = await measureAndLog(this.code.capturePage(), 'capturePage', this.logger);
const buffer = Buffer.from(raw, 'base64');
const screenshotPath = path.join(this.options.screenshotsPath, `${name}.png`);
this.logger.log('Screenshot recorded:', screenshotPath);

View file

@ -3,15 +3,14 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import minimist = require('minimist');
import { Application } from '../../../../automation';
import { Application, Logger } from '../../../../automation';
import { installCommonTestHandlers } from '../../utils';
export function setup(opts: minimist.ParsedArgs) {
export function setup(logger: Logger) {
describe('Editor', () => {
// Shared before/after handling
installCommonTestHandlers(opts);
installCommonTestHandlers(logger);
it('shows correct quick outline', async function () {
const app = this.app as Application;

View file

@ -3,15 +3,14 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import minimist = require('minimist');
import { Application, Quality } from '../../../../automation';
import { Application, Logger, Quality } from '../../../../automation';
import { installCommonTestHandlers } from '../../utils';
export function setup(opts: minimist.ParsedArgs) {
export function setup(logger: Logger) {
describe('Extensions', () => {
// Shared before/after handling
installCommonTestHandlers(opts);
installCommonTestHandlers(logger);
it('install and enable vscode-smoketest-check extension', async function () {
const app = this.app as Application;

View file

@ -3,15 +3,14 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import minimist = require('minimist');
import { Application, ProblemSeverity, Problems } from '../../../../automation/out';
import { Application, ProblemSeverity, Problems, Logger } from '../../../../automation';
import { installCommonTestHandlers } from '../../utils';
export function setup(opts: minimist.ParsedArgs) {
export function setup(logger: Logger) {
describe('Language Features', () => {
// Shared before/after handling
installCommonTestHandlers(opts);
installCommonTestHandlers(logger);
it('verifies quick outline', async function () {
const app = this.app as Application;

View file

@ -3,10 +3,9 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as fs from 'fs';
import minimist = require('minimist');
import * as path from 'path';
import { Application } from '../../../../automation';
import { writeFileSync } from 'fs';
import { join, dirname } from 'path';
import { Application, Logger } from '../../../../automation';
import { installCommonTestHandlers } from '../../utils';
function toUri(path: string): string {
@ -18,12 +17,12 @@ function toUri(path: string): string {
}
function createWorkspaceFile(workspacePath: string): string {
const workspaceFilePath = path.join(path.dirname(workspacePath), 'smoketest.code-workspace');
const workspaceFilePath = join(dirname(workspacePath), 'smoketest.code-workspace');
const workspace = {
folders: [
{ path: toUri(path.join(workspacePath, 'public')) },
{ path: toUri(path.join(workspacePath, 'routes')) },
{ path: toUri(path.join(workspacePath, 'views')) }
{ path: toUri(join(workspacePath, 'public')) },
{ path: toUri(join(workspacePath, 'routes')) },
{ path: toUri(join(workspacePath, 'views')) }
],
settings: {
'workbench.startupEditor': 'none',
@ -31,16 +30,16 @@ function createWorkspaceFile(workspacePath: string): string {
}
};
fs.writeFileSync(workspaceFilePath, JSON.stringify(workspace, null, '\t'));
writeFileSync(workspaceFilePath, JSON.stringify(workspace, null, '\t'));
return workspaceFilePath;
}
export function setup(opts: minimist.ParsedArgs) {
export function setup(logger: Logger) {
describe('Multiroot', () => {
// Shared before/after handling
installCommonTestHandlers(opts, async opts => {
installCommonTestHandlers(logger, async opts => {
const workspacePath = createWorkspaceFile(opts.workspacePath);
return { ...opts, workspacePath };
});

View file

@ -4,15 +4,14 @@
*--------------------------------------------------------------------------------------------*/
import * as cp from 'child_process';
import minimist = require('minimist');
import { Application } from '../../../../automation';
import { Application, Logger } from '../../../../automation';
import { installCommonTestHandlers } from '../../utils';
export function setup(opts: minimist.ParsedArgs) {
export function setup(logger: Logger) {
describe.skip('Notebooks', () => {
// Shared before/after handling
installCommonTestHandlers(opts);
installCommonTestHandlers(logger);
afterEach(async function () {
const app = this.app as Application;

View file

@ -3,15 +3,14 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import minimist = require('minimist');
import { Application, ActivityBarPosition } from '../../../../automation';
import { Application, ActivityBarPosition, Logger } from '../../../../automation';
import { installCommonTestHandlers } from '../../utils';
export function setup(opts: minimist.ParsedArgs) {
export function setup(logger: Logger) {
describe('Preferences', () => {
// Shared before/after handling
installCommonTestHandlers(opts);
installCommonTestHandlers(logger);
it('turns off editor line numbers and verifies the live change', async function () {
const app = this.app as Application;

View file

@ -4,15 +4,14 @@
*--------------------------------------------------------------------------------------------*/
import * as cp from 'child_process';
import minimist = require('minimist');
import { Application } from '../../../../automation';
import { Application, Logger } from '../../../../automation';
import { installCommonTestHandlers, retry } from '../../utils';
export function setup(opts: minimist.ParsedArgs) {
export function setup(logger: Logger) {
describe('Search', () => {
// Shared before/after handling
installCommonTestHandlers(opts);
installCommonTestHandlers(logger);
after(function () {
const app = this.app as Application;
@ -76,7 +75,7 @@ export function setup(opts: minimist.ParsedArgs) {
describe('Quick Open', () => {
// Shared before/after handling
installCommonTestHandlers(opts);
installCommonTestHandlers(logger);
it('quick open search produces correct result', async function () {
const app = this.app as Application;

View file

@ -3,15 +3,14 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import minimist = require('minimist');
import { Application, Quality, StatusBarElement } from '../../../../automation';
import { Application, Quality, StatusBarElement, Logger } from '../../../../automation';
import { installCommonTestHandlers } from '../../utils';
export function setup(opts: minimist.ParsedArgs) {
export function setup(isWeb: boolean, logger: Logger) {
describe('Statusbar', () => {
// Shared before/after handling
installCommonTestHandlers(opts);
installCommonTestHandlers(logger);
it('verifies presence of all default status bar elements', async function () {
const app = this.app as Application;
@ -24,7 +23,7 @@ export function setup(opts: minimist.ParsedArgs) {
await app.workbench.statusbar.waitForStatusbarElement(StatusBarElement.PROBLEMS_STATUS);
await app.workbench.quickaccess.openFile('app.js');
if (!opts.web) {
if (!isWeb) {
// Encoding picker currently hidden in web (only UTF-8 supported)
await app.workbench.statusbar.waitForStatusbarElement(StatusBarElement.ENCODING_STATUS);
}
@ -45,7 +44,7 @@ export function setup(opts: minimist.ParsedArgs) {
await app.workbench.statusbar.clickOn(StatusBarElement.INDENTATION_STATUS);
await app.workbench.quickinput.waitForQuickInputOpened();
await app.workbench.quickinput.closeQuickInput();
if (!opts.web) {
if (!isWeb) {
// Encoding picker currently hidden in web (only UTF-8 supported)
await app.workbench.statusbar.clickOn(StatusBarElement.ENCODING_STATUS);
await app.workbench.quickinput.waitForQuickInputOpened();

View file

@ -3,10 +3,9 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ParsedArgs } from 'minimist';
import { Application, Terminal, TerminalCommandId, TerminalCommandIdWithValue } from '../../../../automation/out';
import { Application, Terminal, TerminalCommandId, TerminalCommandIdWithValue } from '../../../../automation';
export function setup(opts: ParsedArgs) {
export function setup() {
describe('Terminal Editors', () => {
let terminal: Terminal;

View file

@ -3,10 +3,9 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ParsedArgs } from 'minimist';
import { Application, Terminal, TerminalCommandId, TerminalCommandIdWithValue } from '../../../../automation/out';
import { Application, Terminal, TerminalCommandId, TerminalCommandIdWithValue } from '../../../../automation';
export function setup(opts: ParsedArgs) {
export function setup() {
describe('Terminal Persistence', () => {
// Acquire automation API
let terminal: Terminal;

View file

@ -3,13 +3,12 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ParsedArgs } from 'minimist';
import { Application, Terminal, TerminalCommandId, TerminalCommandIdWithValue } from '../../../../automation';
const CONTRIBUTED_PROFILE_NAME = `JavaScript Debug Terminal`;
const ANY_PROFILE_NAME = '^((?!JavaScript Debug Terminal).)*$';
export function setup(opts: ParsedArgs) {
export function setup() {
describe('Terminal Profiles', () => {
// Acquire automation API
let terminal: Terminal;

View file

@ -3,11 +3,9 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Application, Terminal, TerminalCommandId, TerminalCommandIdWithValue } from '../../../../automation';
import { ParsedArgs } from 'minimist';
import { Application, Terminal, TerminalCommandId, TerminalCommandIdWithValue } from '../../../../automation/out';
export function setup(opts: ParsedArgs) {
export function setup() {
describe('Terminal Tabs', () => {
// Acquire automation API
let terminal: Terminal;

View file

@ -3,18 +3,17 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import minimist = require('minimist');
import { Application, Terminal, TerminalCommandId } from '../../../../automation/out';
import { Application, Terminal, TerminalCommandId, Logger } from '../../../../automation';
import { installCommonTestHandlers } from '../../utils';
import { setup as setupTerminalEditorsTests } from './terminal-editors.test';
import { setup as setupTerminalPersistenceTests } from './terminal-persistence.test';
import { setup as setupTerminalProfileTests } from './terminal-profiles.test';
import { setup as setupTerminalTabsTests } from './terminal-tabs.test';
export function setup(opts: minimist.ParsedArgs) {
export function setup(isWeb: boolean, logger: Logger) {
describe('Terminal', function () {
// TODO: Enable terminal tests for non-web when the desktop driver is moved to playwright
if (!opts.web) {
if (!isWeb) {
return;
}
@ -22,7 +21,7 @@ export function setup(opts: minimist.ParsedArgs) {
this.retries(3);
// Shared before/after handling
installCommonTestHandlers(opts);
installCommonTestHandlers(logger);
let terminal: Terminal;
before(async function () {
@ -42,9 +41,9 @@ export function setup(opts: minimist.ParsedArgs) {
await terminal.runCommand(TerminalCommandId.KillAll);
});
setupTerminalEditorsTests(opts);
setupTerminalPersistenceTests(opts);
setupTerminalProfileTests(opts);
setupTerminalTabsTests(opts);
setupTerminalEditorsTests();
setupTerminalPersistenceTests();
setupTerminalProfileTests();
setupTerminalTabsTests();
});
}

View file

@ -3,20 +3,19 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Application, ApplicationOptions, Quality } from '../../../../automation/out';
import { ParsedArgs } from 'minimist';
import { Application, ApplicationOptions, Logger, Quality } from '../../../../automation';
import { installCommonAfterHandlers, getRandomUserDataDir, startApp, timeout, installCommonBeforeEachHandler } from '../../utils';
export function setup(opts: ParsedArgs) {
export function setup(stableCodePath: string | undefined, isRemote: boolean, logger: Logger) {
describe('Data Loss (insiders -> insiders)', () => {
let app: Application | undefined = undefined;
installCommonBeforeEachHandler();
installCommonAfterHandlers(opts, () => app);
installCommonBeforeEachHandler(logger);
installCommonAfterHandlers(() => app);
it('verifies opened editors are restored', async function () {
app = await startApp(opts, this.defaultOptions);
app = await startApp(this.defaultOptions);
// Open 3 editors and pin 2 of them
await app.workbench.quickaccess.openFile('www');
@ -51,7 +50,7 @@ export function setup(opts: ParsedArgs) {
});
async function testHotExit(restartDelay: number | undefined, autoSave: boolean | undefined) {
app = await startApp(opts, this.defaultOptions);
app = await startApp(this.defaultOptions);
if (autoSave) {
await app.workbench.settingsEditor.addUserSetting('files.autoSave', '"afterDelay"');
@ -98,12 +97,11 @@ export function setup(opts: ParsedArgs) {
let insidersApp: Application | undefined = undefined;
let stableApp: Application | undefined = undefined;
installCommonBeforeEachHandler();
installCommonAfterHandlers(opts, () => insidersApp ?? stableApp, async () => stableApp?.stop());
installCommonBeforeEachHandler(logger);
installCommonAfterHandlers(() => insidersApp ?? stableApp, async () => stableApp?.stop());
it('verifies opened editors are restored', async function () {
const stableCodePath = opts['stable-build'];
if (!stableCodePath || opts.remote) {
if (!stableCodePath || isRemote) {
this.skip();
}
@ -160,8 +158,7 @@ export function setup(opts: ParsedArgs) {
});
async function testHotExit(restartDelay: number | undefined) {
const stableCodePath = opts['stable-build'];
if (!stableCodePath || opts.remote) {
if (!stableCodePath || isRemote) {
this.skip();
}

View file

@ -3,22 +3,21 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import minimist = require('minimist');
import { join } from 'path';
import { Application } from '../../../../automation';
import { Application, Logger } from '../../../../automation';
import { installCommonAfterHandlers, installCommonBeforeEachHandler, startApp } from '../../utils';
export function setup(args: minimist.ParsedArgs) {
export function setup(logger: Logger) {
describe('Launch', () => {
let app: Application | undefined;
installCommonBeforeEachHandler();
installCommonAfterHandlers(args, () => app);
installCommonBeforeEachHandler(logger);
installCommonAfterHandlers(() => app);
it(`verifies that application launches when user data directory has non-ascii characters`, async function () {
const massagedOptions = { ...this.defaultOptions, userDataDir: join(this.defaultOptions.userDataDir, 'ø') };
app = await startApp(args, massagedOptions);
app = await startApp(massagedOptions);
await app.stop();
app = undefined;

View file

@ -3,25 +3,24 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import minimist = require('minimist');
import { Application, Quality } from '../../../../automation';
import { Application, Quality, Logger } from '../../../../automation';
import { installCommonAfterHandlers, installCommonBeforeEachHandler, startApp } from '../../utils';
export function setup(args: minimist.ParsedArgs) {
export function setup(logger: Logger) {
describe('Localization', () => {
let app: Application | undefined = undefined;
installCommonBeforeEachHandler();
installCommonAfterHandlers(args, () => app);
installCommonBeforeEachHandler(logger);
installCommonAfterHandlers(() => app);
it(`starts with 'DE' locale and verifies title and viewlets text is in German`, async function () {
if (this.defaultOptions.quality === Quality.Dev || this.defaultOptions.remote) {
return this.skip();
}
app = await startApp(args, this.defaultOptions);
app = await startApp(this.defaultOptions);
await app.workbench.extensions.openExtensionsViewlet();
await app.workbench.extensions.installExtension('ms-ceintl.vscode-language-pack-de', false);

View file

@ -13,7 +13,7 @@ import * as rimraf from 'rimraf';
import * as mkdirp from 'mkdirp';
import * as vscodetest from 'vscode-test';
import fetch from 'node-fetch';
import { Quality, ApplicationOptions, MultiLogger, Logger, ConsoleLogger, FileLogger, measureAndLog } from '../../automation';
import { Quality, MultiLogger, Logger, ConsoleLogger, FileLogger, measureAndLog } from '../../automation';
import { timeout } from './utils';
import { setup as setupDataLossTests } from './areas/workbench/data-loss.test';
@ -29,24 +29,7 @@ import { setup as setupLocalizationTests } from './areas/workbench/localization.
import { setup as setupLaunchTests } from './areas/workbench/launch.test';
import { setup as setupTerminalTests } from './areas/terminal/terminal.test';
try {
gracefulify(fs);
} catch (error) {
console.error(`Error enabling graceful-fs: ${error}`);
}
const testDataPath = path.join(os.tmpdir(), 'vscsmoke');
if (fs.existsSync(testDataPath)) {
rimraf.sync(testDataPath);
}
fs.mkdirSync(testDataPath);
process.once('exit', () => {
try {
rimraf.sync(testDataPath);
} catch {
// noop
}
});
const repoPath = path.join(__dirname, '..', '..', '..');
const [, , ...args] = process.argv;
const opts = minimist(args, {
@ -68,6 +51,53 @@ const opts = minimist(args, {
default: {
verbose: false
}
}) as {
verbose?: boolean,
remote?: boolean,
headless?: boolean,
web?: boolean,
screenshots?: string,
build?: string,
'stable-build'?: string,
browser?: string,
electronArgs?: string
};
const logger = createLogger();
function createLogger(): Logger {
const loggers: Logger[] = [];
// Log to console if verbose
if (opts.verbose) {
loggers.push(new ConsoleLogger());
}
// Always log to log file
const logPath = path.join(repoPath, '.build', 'logs', opts.web ? 'smoke-tests-browser' : opts.remote ? 'smoke-tests-remote' : 'smoke-tests');
mkdirp.sync(logPath);
loggers.push(new FileLogger(path.join(logPath, 'smoke-test-runner.log')));
return new MultiLogger(loggers);
}
try {
gracefulify(fs);
} catch (error) {
logger.log(`Error enabling graceful-fs: ${error}`);
}
const testDataPath = path.join(os.tmpdir(), 'vscsmoke');
if (fs.existsSync(testDataPath)) {
rimraf.sync(testDataPath);
}
fs.mkdirSync(testDataPath);
process.once('exit', () => {
try {
rimraf.sync(testDataPath);
} catch {
// noop
}
});
const testRepoUrl = 'https://github.com/microsoft/vscode-smoketest-express';
@ -81,12 +111,10 @@ if (screenshotsPath) {
}
function fail(errorMessage): void {
console.error(errorMessage);
logger.log(errorMessage);
process.exit(1);
}
const repoPath = path.join(__dirname, '..', '..', '..');
let quality: Quality;
let version: string | undefined;
@ -169,9 +197,9 @@ if (!opts.web) {
}
if (opts.remote) {
console.log(`Running desktop remote smoke tests against ${electronPath}`);
logger.log(`Running desktop remote smoke tests against ${electronPath}`);
} else {
console.log(`Running desktop smoke tests against ${electronPath}`);
logger.log(`Running desktop smoke tests against ${electronPath}`);
}
}
@ -185,7 +213,7 @@ else {
if (!fs.existsSync(testCodeServerPath)) {
fail(`Can't find Code server at ${testCodeServerPath}.`);
} else {
console.log(`Running web smoke tests against ${testCodeServerPath}`);
logger.log(`Running web smoke tests against ${testCodeServerPath}`);
}
}
@ -194,7 +222,7 @@ else {
process.env.VSCODE_DEV = '1';
process.env.VSCODE_CLI = '1';
console.log(`Running web smoke out of sources`);
logger.log(`Running web smoke out of sources`);
}
if (process.env.VSCODE_DEV === '1') {
@ -206,7 +234,7 @@ else {
const userDataDir = path.join(testDataPath, 'd');
async function setupRepository(logger: Logger): Promise<void> {
async function setupRepository(): Promise<void> {
if (opts['test-repo']) {
logger.log('Copying test project repository:', opts['test-repo']);
rimraf.sync(workspacePath);
@ -234,7 +262,7 @@ async function setupRepository(logger: Logger): Promise<void> {
}
}
async function ensureStableCode(logger: Logger): Promise<void> {
async function ensureStableCode(): Promise<void> {
if (opts.web || !opts['build']) {
return;
}
@ -282,25 +310,27 @@ async function ensureStableCode(logger: Logger): Promise<void> {
opts['stable-build'] = stableCodePath;
}
async function setup(logger: Logger): Promise<void> {
async function setup(): Promise<void> {
logger.log('Test data:', testDataPath);
logger.log('Preparing smoketest setup...');
await measureAndLog(ensureStableCode(logger), 'ensureStableCode', logger);
await measureAndLog(setupRepository(logger), 'setupRepository', logger);
await measureAndLog(ensureStableCode(), 'ensureStableCode', logger);
await measureAndLog(setupRepository(), 'setupRepository', logger);
logger.log('Smoketest setup done!\n');
}
async function createOptions(): Promise<ApplicationOptions> {
return {
before(async function () {
this.timeout(2 * 60 * 1000); // allow two minutes for setup
this.defaultOptions = {
quality,
codePath: opts.build,
workspacePath,
userDataDir,
extensionsPath,
waitTime: parseInt(opts['wait-time'] || '0') || 20,
logger: await createLogger(),
logger,
verbose: opts.verbose,
screenshotsPath,
remote: opts.remote,
@ -309,30 +339,8 @@ async function createOptions(): Promise<ApplicationOptions> {
browser: opts.browser,
extraArgs: (opts.electronArgs || '').split(' ').map(a => a.trim()).filter(a => !!a)
};
}
async function createLogger(): Promise<Logger> {
const loggers: Logger[] = [];
// Log to console if verbose
if (opts.verbose) {
loggers.push(new ConsoleLogger());
}
// Always log to log file
const logPath = path.join(repoPath, '.build', 'logs', opts.web ? 'smoke-tests-browser' : opts.remote ? 'smoke-tests-remote' : 'smoke-tests');
await mkdirp(logPath);
loggers.push(new FileLogger(path.join(logPath, 'smoke-test-runner.log')));
return new MultiLogger(loggers);
}
before(async function () {
this.timeout(2 * 60 * 1000); // allow two minutes for setup
const options = this.defaultOptions = await createOptions();
await setup(options.logger);
await setup();
});
after(async function () {
@ -363,23 +371,23 @@ after(async function () {
throw new Error('giving up after 30s');
}
})
]), 'rimraf(testDataPath)', this.defaultOptions.logger);
]), 'rimraf(testDataPath)', logger);
} catch (error) {
this.defaultOptions.logger(`Unable to delete smoke test workspace: ${error}. This indicates some process is locking the workspace folder.`);
logger.log(`Unable to delete smoke test workspace: ${error}. This indicates some process is locking the workspace folder.`);
}
});
describe(`VSCode Smoke Tests (${opts.web ? 'Web' : 'Electron'})`, () => {
if (!opts.web) { setupDataLossTests(opts); }
if (!opts.web) { setupPreferencesTests(opts); }
setupSearchTests(opts);
setupNotebookTests(opts);
setupLanguagesTests(opts);
setupEditorTests(opts);
setupTerminalTests(opts);
setupStatusbarTests(opts);
setupExtensionTests(opts);
if (!opts.web) { setupMultirootTests(opts); }
if (!opts.web) { setupLocalizationTests(opts); }
if (!opts.web) { setupLaunchTests(opts); }
if (!opts.web) { setupDataLossTests(opts['stable-build'], !!opts.remote, logger); }
if (!opts.web) { setupPreferencesTests(logger); }
setupSearchTests(logger);
setupNotebookTests(logger);
setupLanguagesTests(logger);
setupEditorTests(logger);
setupTerminalTests(!!opts.web, logger);
setupStatusbarTests(!!opts.web, logger);
setupExtensionTests(logger);
if (!opts.web) { setupMultirootTests(logger); }
if (!opts.web) { setupLocalizationTests(logger); }
if (!opts.web) { setupLaunchTests(logger); }
});

View file

@ -3,9 +3,8 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import minimist = require('minimist');
import { Suite, Context } from 'mocha';
import { Application, ApplicationOptions } from '../../automation';
import { Application, ApplicationOptions, Logger } from '../../automation';
export function describeRepeat(n: number, description: string, callback: (this: Suite) => void): void {
for (let i = 0; i < n; i++) {
@ -19,31 +18,31 @@ export function itRepeat(n: number, description: string, callback: (this: Contex
}
}
export function installCommonTestHandlers(args: minimist.ParsedArgs, optionsTransform?: (opts: ApplicationOptions) => Promise<ApplicationOptions>) {
installCommonBeforeHandlers(args, optionsTransform);
installCommonAfterHandlers(args);
export function installCommonTestHandlers(logger: Logger, optionsTransform?: (opts: ApplicationOptions) => Promise<ApplicationOptions>) {
installCommonBeforeHandlers(logger, optionsTransform);
installCommonAfterHandlers();
}
export function installCommonBeforeHandlers(args: minimist.ParsedArgs, optionsTransform?: (opts: ApplicationOptions) => Promise<ApplicationOptions>) {
export function installCommonBeforeHandlers(logger: Logger, optionsTransform?: (opts: ApplicationOptions) => Promise<ApplicationOptions>) {
before(async function () {
this.app = await startApp(args, this.defaultOptions, optionsTransform);
this.app = await startApp(this.defaultOptions, optionsTransform);
});
installCommonBeforeEachHandler();
installCommonBeforeEachHandler(logger);
}
export function installCommonBeforeEachHandler() {
export function installCommonBeforeEachHandler(logger: Logger) {
beforeEach(async function () {
const testTitle = this.currentTest?.title;
this.defaultOptions.logger.log('');
this.defaultOptions.logger.log(`>>> Test start: ${testTitle} <<<`);
this.defaultOptions.logger.log('');
logger.log('');
logger.log(`>>> Test start: ${testTitle} <<<`);
logger.log('');
await this.app?.startTracing(testTitle);
});
}
export async function startApp(args: minimist.ParsedArgs, options: ApplicationOptions, optionsTransform?: (opts: ApplicationOptions) => Promise<ApplicationOptions>): Promise<Application> {
export async function startApp(options: ApplicationOptions, optionsTransform?: (opts: ApplicationOptions) => Promise<ApplicationOptions>): Promise<Application> {
if (optionsTransform) {
options = await optionsTransform({ ...options });
}
@ -68,11 +67,11 @@ export function getRandomUserDataDir(options: ApplicationOptions): string {
return options.userDataDir.concat(`-${userDataPathSuffix}`);
}
export function installCommonAfterHandlers(opts: minimist.ParsedArgs, appFn?: () => Application | undefined, joinFn?: () => Promise<unknown>) {
export function installCommonAfterHandlers(appFn?: () => Application | undefined, joinFn?: () => Promise<unknown>) {
after(async function () {
const app: Application = appFn?.() ?? this.app;
if (this.currentTest?.state === 'failed' && opts.screenshots) {
if (this.currentTest?.state === 'failed') {
const name = this.currentTest!.fullTitle().replace(/[^a-z0-9\-]/ig, '_');
try {
await app.captureScreenshot(name);