mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-14 21:53:35 +03:00
test: fix create output folder (#3431)
This commit is contained in:
parent
51bd3709ff
commit
4bb2658e74
@ -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: 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);
|
||||
});
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
});
|
||||
|
||||
|
@ -79,6 +79,7 @@ program
|
||||
});
|
||||
await runner.run(files);
|
||||
await runner.stop();
|
||||
process.exit(runner.stats.failures ? 1 : 0);
|
||||
});
|
||||
|
||||
program.parse(process.argv);
|
||||
|
@ -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;
|
||||
|
@ -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');
|
||||
|
1
test/types.d.ts
vendored
1
test/types.d.ts
vendored
@ -55,7 +55,6 @@ declare const testOptions: {
|
||||
LINUX: boolean;
|
||||
WIN: boolean;
|
||||
HEADLESS: boolean;
|
||||
OUTPUT_DIR: string;
|
||||
USES_HOOKS: boolean;
|
||||
CHANNEL: boolean;
|
||||
ASSETS_DIR: string;
|
||||
|
Loading…
Reference in New Issue
Block a user