From 4bb2658e74c052c0e947ac9fb863bc8cf93fe602 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Wed, 12 Aug 2020 22:41:40 -0700 Subject: [PATCH] test: fix create output folder (#3431) --- test/base.fixture.ts | 12 +++++++++++- test/chromium/tracing.spec.ts | 6 +++--- test/pdf.spec.ts | 6 +++--- test/proxy.spec.ts | 6 ------ test/runner/index.js | 1 + test/runner/testOptions.js | 1 - test/runner/worker.js | 1 + test/types.d.ts | 1 - 8 files changed, 19 insertions(+), 15 deletions(-) diff --git a/test/base.fixture.ts b/test/base.fixture.ts index 744b3b4158..3008787131 100644 --- a/test/base.fixture.ts +++ b/test/base.fixture.ts @@ -14,8 +14,8 @@ * limitations under the License. */ -import path from 'path'; import fs from 'fs'; +import path from 'path'; import childProcess from 'child_process'; import { LaunchOptions, BrowserType, Browser, BrowserContext, Page, BrowserServer } from '../index'; import { TestServer } from '../utils/testserver/'; @@ -37,6 +37,7 @@ declare global { playwright: typeof import('../index'); browserType: BrowserType; browser: Browser; + outputDir: string; } interface FixtureState { toImpl: (rpcObject: any) => any; @@ -166,3 +167,12 @@ registerFixture('httpsServer', async ({http_server}, test) => { http_server.httpsServer.reset(); await test(http_server.httpsServer); }); + +registerWorkerFixture('outputDir', async ({}, test) => { + const outputDir = path.join(__dirname, 'output-' + browserName); + try { + await fs.promises.mkdir(outputDir, { recursive: true }); + } catch (e) { + } + await test(outputDir); +}); diff --git a/test/chromium/tracing.spec.ts b/test/chromium/tracing.spec.ts index 070447f5a1..4d6c0bfee4 100644 --- a/test/chromium/tracing.spec.ts +++ b/test/chromium/tracing.spec.ts @@ -18,14 +18,14 @@ import '../base.fixture'; import fs from 'fs'; import path from 'path'; import { ChromiumBrowser } from '../..'; -const {FFOX, CHROMIUM, WEBKIT, OUTPUT_DIR, CHANNEL} = testOptions; +const {FFOX, CHROMIUM, WEBKIT, CHANNEL} = testOptions; declare global { interface FixtureState { outputFile: string; } } -registerFixture('outputFile', async ({parallelIndex}, test) => { - const outputFile = path.join(OUTPUT_DIR, `trace-${parallelIndex}.json`); +registerFixture('outputFile', async ({outputDir, parallelIndex}, test) => { + const outputFile = path.join(outputDir, `trace-${parallelIndex}.json`); await test(outputFile); if (fs.existsSync(outputFile)) fs.unlinkSync(outputFile); diff --git a/test/pdf.spec.ts b/test/pdf.spec.ts index 0c74c549fc..484be2f020 100644 --- a/test/pdf.spec.ts +++ b/test/pdf.spec.ts @@ -18,11 +18,11 @@ import './base.fixture'; import fs from 'fs' import path from 'path' -const {FFOX, CHROMIUM, WEBKIT, OUTPUT_DIR, HEADLESS} = testOptions; +const {FFOX, CHROMIUM, WEBKIT, HEADLESS} = testOptions; // Printing to pdf is currently only supported in headless chromium. -it.skip(!(HEADLESS && CHROMIUM))('should be able to save file', async({page}) => { - const outputFile = path.join(OUTPUT_DIR, 'output.pdf'); +it.skip(!(HEADLESS && CHROMIUM))('should be able to save file', async({page, outputDir}) => { + const outputFile = path.join(outputDir, 'output.pdf'); await page.pdf({path: outputFile}); expect(fs.readFileSync(outputFile).byteLength).toBeGreaterThan(0); fs.unlinkSync(outputFile); diff --git a/test/proxy.spec.ts b/test/proxy.spec.ts index a4c9d0b739..61a4321b13 100644 --- a/test/proxy.spec.ts +++ b/test/proxy.spec.ts @@ -93,12 +93,6 @@ it.fail(CHROMIUM && !HEADLESS)('should exclude patterns', async ({browserType, d expect(await page.title()).toBe('Served by the proxy'); } - if (CHROMIUM) { - // Should successfully navigate to the error page. - await page.waitForEvent('framenavigated', frame => frame.url() === 'chrome-error://chromewebdata/'); - expect(page.url()).toBe('chrome-error://chromewebdata/'); - } - await browser.close(); }); diff --git a/test/runner/index.js b/test/runner/index.js index 7d58e3da37..527947c155 100644 --- a/test/runner/index.js +++ b/test/runner/index.js @@ -79,6 +79,7 @@ program }); await runner.run(files); await runner.stop(); + process.exit(runner.stats.failures ? 1 : 0); }); program.parse(process.argv); diff --git a/test/runner/testOptions.js b/test/runner/testOptions.js index 946d1390c5..a4e9572cbf 100644 --- a/test/runner/testOptions.js +++ b/test/runner/testOptions.js @@ -33,6 +33,5 @@ testOptions.CHANNEL = process.env.PWCHANNEL !== 'none'; testOptions.HEADLESS = !!valueFromEnv('HEADLESS', true); testOptions.ASSETS_DIR = path.join(__dirname, '..', 'assets'); testOptions.GOLDEN_DIR = path.join(__dirname, '..', 'golden-' + browserName); -testOptions.OUTPUT_DIR = path.join(__dirname, '..', 'output-' + browserName); module.exports = testOptions; diff --git a/test/runner/worker.js b/test/runner/worker.js index 848543e2e9..aa1efad9e5 100644 --- a/test/runner/worker.js +++ b/test/runner/worker.js @@ -16,6 +16,7 @@ const path = require('path'); const Mocha = require('mocha'); +const { registerWorkerFixture } = require('./fixturePool'); const { fixturesUI, fixturePool } = require('./fixturesUI'); const { gracefullyCloseAll } = require('../../lib/server/processLauncher'); const GoldenUtils = require('../../utils/testrunner/GoldenUtils'); diff --git a/test/types.d.ts b/test/types.d.ts index 713029948c..18fa12198d 100644 --- a/test/types.d.ts +++ b/test/types.d.ts @@ -55,7 +55,6 @@ declare const testOptions: { LINUX: boolean; WIN: boolean; HEADLESS: boolean; - OUTPUT_DIR: string; USES_HOOKS: boolean; CHANNEL: boolean; ASSETS_DIR: string;