From 34b5c57cf211bcaf1bc48f75a8cd8d0b4378e5f5 Mon Sep 17 00:00:00 2001 From: Christopher Mead Date: Wed, 2 Oct 2024 17:46:44 -0600 Subject: [PATCH] Console output test: loop with short pauses (#4882) Test for https://github.com/posit-dev/positron/pull/4848 Also, retries globally turned on for smoke tests with "double screenshots and traces" as relevent. ### QA Notes All smoke tests pass. --- test/automation/src/playwrightDriver.ts | 8 ++- .../positron/console/consoleOutput.test.ts | 51 +++++++++++++++++++ .../positron/output/consoleOutputLog.test.ts | 2 +- test/smoke/src/utils.ts | 5 +- test/smoke/test/positronIndex.js | 2 +- 5 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 test/smoke/src/areas/positron/console/consoleOutput.test.ts diff --git a/test/automation/src/playwrightDriver.ts b/test/automation/src/playwrightDriver.ts index 4f5318bf32e..c9d3719836a 100644 --- a/test/automation/src/playwrightDriver.ts +++ b/test/automation/src/playwrightDriver.ts @@ -63,7 +63,9 @@ export class PlaywrightDriver { try { let persistPath: string | undefined = undefined; if (persist) { - persistPath = join(this.options.logsPath, `playwright-trace-${PlaywrightDriver.traceCounter++}-${name.replace(/\s+/g, '-')}.zip`); + // --- Start Positron --- + persistPath = join(this.options.logsPath, `playwright-trace-${PlaywrightDriver.traceCounter++}-${name.replace(/\s+/g, '-')}_${Date.now()}.zip`); + // --- End Positron --- } await measureAndLog(() => this.context.tracing.stopChunk({ path: persistPath }), `stopTracing for ${name}`, this.options.logger); @@ -73,7 +75,9 @@ export class PlaywrightDriver { // does not guarantee to give us a screenshot unless // some driver action ran before. if (persist) { - await this.takeScreenshot(name); + // --- Start Positron --- + await this.takeScreenshot(`${name}_${Date.now()}`); + // --- End Positron --- } } catch (error) { // Ignore diff --git a/test/smoke/src/areas/positron/console/consoleOutput.test.ts b/test/smoke/src/areas/positron/console/consoleOutput.test.ts new file mode 100644 index 00000000000..a2c1c032817 --- /dev/null +++ b/test/smoke/src/areas/positron/console/consoleOutput.test.ts @@ -0,0 +1,51 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (C) 2024 Posit Software, PBC. All rights reserved. + * Licensed under the Elastic License 2.0. See LICENSE.txt for license information. + *--------------------------------------------------------------------------------------------*/ + + +import { Application, PositronRFixtures } from '../../../../../automation'; +import { setupAndStartApp } from '../../../positronUtils'; + +describe('Console Output', () => { + setupAndStartApp(); + + describe('Console Output - R', () => { + before(async function () { + await PositronRFixtures.SetupFixtures(this.app as Application); + }); + + it('R - Console output in a loop with short pauses [C885225]', async function () { + const app = this.app as Application; + + const code = `tokens <- c( +"", +"Why", +" do", +" programmers", +" prefer", +" dark", +" mode", +"?\n\n", +"Because", +" light", +" attracts", +" bugs", +"!" +) + +for(token in tokens) { + cat(token) + Sys.sleep(0.01) +}`; + + await app.workbench.positronConsole.pasteCodeToConsole(code); + + await app.workbench.positronConsole.sendEnterKey(); + + await app.workbench.positronConsole.waitForConsoleContents((contents) => contents.some((line) => line.includes('Why do programmers prefer dark mode'))); + await app.workbench.positronConsole.waitForConsoleContents((contents) => contents.some((line) => line.includes('Because light attracts bugs!'))); + + }); + }); +}); diff --git a/test/smoke/src/areas/positron/output/consoleOutputLog.test.ts b/test/smoke/src/areas/positron/output/consoleOutputLog.test.ts index df3b3834fb2..b8a6048f053 100644 --- a/test/smoke/src/areas/positron/output/consoleOutputLog.test.ts +++ b/test/smoke/src/areas/positron/output/consoleOutputLog.test.ts @@ -9,7 +9,7 @@ import { Application, PositronPythonFixtures, PositronRFixtures } from '../../.. import { setupAndStartApp } from '../../../positronUtils'; -describe('Console Output #web', () => { +describe('Output #web', () => { setupAndStartApp(); describe('Console Output Log - Python', () => { diff --git a/test/smoke/src/utils.ts b/test/smoke/src/utils.ts index 3d4912658e9..b7cda86919e 100644 --- a/test/smoke/src/utils.ts +++ b/test/smoke/src/utils.ts @@ -64,7 +64,10 @@ export function installDiagnosticsHandler(logger: Logger, appFn?: () => Applicat logger.log(''); const app: Application = appFn?.() ?? this.app; - await app?.stopTracing(testTitle.replace(/[^a-z0-9\-]/ig, '_'), failed); + // --- Start Positron --- + // state is undefined during retry + await app?.stopTracing(testTitle.replace(/[^a-z0-9\-]/ig, '_'), failed || (currentTest.state === undefined)); + // --- End Positron --- }); } diff --git a/test/smoke/test/positronIndex.js b/test/smoke/test/positronIndex.js index 56581e01fb9..f955f46ca0e 100644 --- a/test/smoke/test/positronIndex.js +++ b/test/smoke/test/positronIndex.js @@ -75,7 +75,7 @@ function getMochaOptions(opts) { spec: '-', // Console output xunit: REPORT_PATH, }, - retries: 0, + retries: 1, }; }