test: fix create output folder (#3431)
This commit is contained in:
parent
51bd3709ff
commit
4bb2658e74
|
|
@ -14,8 +14,8 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import path from 'path';
|
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import path from 'path';
|
||||||
import childProcess from 'child_process';
|
import childProcess from 'child_process';
|
||||||
import { LaunchOptions, BrowserType, Browser, BrowserContext, Page, BrowserServer } from '../index';
|
import { LaunchOptions, BrowserType, Browser, BrowserContext, Page, BrowserServer } from '../index';
|
||||||
import { TestServer } from '../utils/testserver/';
|
import { TestServer } from '../utils/testserver/';
|
||||||
|
|
@ -37,6 +37,7 @@ declare global {
|
||||||
playwright: typeof import('../index');
|
playwright: typeof import('../index');
|
||||||
browserType: BrowserType<Browser>;
|
browserType: BrowserType<Browser>;
|
||||||
browser: Browser;
|
browser: Browser;
|
||||||
|
outputDir: string;
|
||||||
}
|
}
|
||||||
interface FixtureState {
|
interface FixtureState {
|
||||||
toImpl: (rpcObject: any) => any;
|
toImpl: (rpcObject: any) => any;
|
||||||
|
|
@ -166,3 +167,12 @@ registerFixture('httpsServer', async ({http_server}, test) => {
|
||||||
http_server.httpsServer.reset();
|
http_server.httpsServer.reset();
|
||||||
await test(http_server.httpsServer);
|
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 fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { ChromiumBrowser } from '../..';
|
import { ChromiumBrowser } from '../..';
|
||||||
const {FFOX, CHROMIUM, WEBKIT, OUTPUT_DIR, CHANNEL} = testOptions;
|
const {FFOX, CHROMIUM, WEBKIT, CHANNEL} = testOptions;
|
||||||
declare global {
|
declare global {
|
||||||
interface FixtureState {
|
interface FixtureState {
|
||||||
outputFile: string;
|
outputFile: string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
registerFixture('outputFile', async ({parallelIndex}, test) => {
|
registerFixture('outputFile', async ({outputDir, parallelIndex}, test) => {
|
||||||
const outputFile = path.join(OUTPUT_DIR, `trace-${parallelIndex}.json`);
|
const outputFile = path.join(outputDir, `trace-${parallelIndex}.json`);
|
||||||
await test(outputFile);
|
await test(outputFile);
|
||||||
if (fs.existsSync(outputFile))
|
if (fs.existsSync(outputFile))
|
||||||
fs.unlinkSync(outputFile);
|
fs.unlinkSync(outputFile);
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,11 @@ import './base.fixture';
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import path from 'path'
|
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.
|
// Printing to pdf is currently only supported in headless chromium.
|
||||||
it.skip(!(HEADLESS && CHROMIUM))('should be able to save file', async({page}) => {
|
it.skip(!(HEADLESS && CHROMIUM))('should be able to save file', async({page, outputDir}) => {
|
||||||
const outputFile = path.join(OUTPUT_DIR, 'output.pdf');
|
const outputFile = path.join(outputDir, 'output.pdf');
|
||||||
await page.pdf({path: outputFile});
|
await page.pdf({path: outputFile});
|
||||||
expect(fs.readFileSync(outputFile).byteLength).toBeGreaterThan(0);
|
expect(fs.readFileSync(outputFile).byteLength).toBeGreaterThan(0);
|
||||||
fs.unlinkSync(outputFile);
|
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');
|
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();
|
await browser.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,7 @@ program
|
||||||
});
|
});
|
||||||
await runner.run(files);
|
await runner.run(files);
|
||||||
await runner.stop();
|
await runner.stop();
|
||||||
|
process.exit(runner.stats.failures ? 1 : 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
program.parse(process.argv);
|
program.parse(process.argv);
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,5 @@ testOptions.CHANNEL = process.env.PWCHANNEL !== 'none';
|
||||||
testOptions.HEADLESS = !!valueFromEnv('HEADLESS', true);
|
testOptions.HEADLESS = !!valueFromEnv('HEADLESS', true);
|
||||||
testOptions.ASSETS_DIR = path.join(__dirname, '..', 'assets');
|
testOptions.ASSETS_DIR = path.join(__dirname, '..', 'assets');
|
||||||
testOptions.GOLDEN_DIR = path.join(__dirname, '..', 'golden-' + browserName);
|
testOptions.GOLDEN_DIR = path.join(__dirname, '..', 'golden-' + browserName);
|
||||||
testOptions.OUTPUT_DIR = path.join(__dirname, '..', 'output-' + browserName);
|
|
||||||
|
|
||||||
module.exports = testOptions;
|
module.exports = testOptions;
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const Mocha = require('mocha');
|
const Mocha = require('mocha');
|
||||||
|
const { registerWorkerFixture } = require('./fixturePool');
|
||||||
const { fixturesUI, fixturePool } = require('./fixturesUI');
|
const { fixturesUI, fixturePool } = require('./fixturesUI');
|
||||||
const { gracefullyCloseAll } = require('../../lib/server/processLauncher');
|
const { gracefullyCloseAll } = require('../../lib/server/processLauncher');
|
||||||
const GoldenUtils = require('../../utils/testrunner/GoldenUtils');
|
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;
|
LINUX: boolean;
|
||||||
WIN: boolean;
|
WIN: boolean;
|
||||||
HEADLESS: boolean;
|
HEADLESS: boolean;
|
||||||
OUTPUT_DIR: string;
|
|
||||||
USES_HOOKS: boolean;
|
USES_HOOKS: boolean;
|
||||||
CHANNEL: boolean;
|
CHANNEL: boolean;
|
||||||
ASSETS_DIR: string;
|
ASSETS_DIR: string;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue