Skip to content

Commit f745bf1

Browse files
authored
chore: bring in folio source (#6923)
- Source now lives at `src/test`. - Former folio tests live at `tests/playwright-test`. - We use `src/test/internal.ts` that exposes base test without Playwright fixtures for most tests (to avoid modifications for now). - Test types live in `types/testFoo.d.ts`. - Stable test runner is installed to `tests/config/test-runner` during `npm install`. - All deps including test-only are now listed in `package.json`. Non-test deps must also be listed in `build_package.js` to get included.
1 parent d4e50be commit f745bf1

File tree

97 files changed

+17150
-650
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+17150
-650
lines changed

.github/workflows/tests_primary.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,20 @@ jobs:
4747
name: ${{ matrix.browser }}-${{ matrix.os }}-test-results
4848
path: test-results
4949

50+
test_test_runner:
51+
name: Test Runner
52+
strategy:
53+
fail-fast: false
54+
matrix:
55+
os: [ubuntu-latest, windows-latest, macos-latest]
56+
runs-on: ${{ matrix.os }}
57+
steps:
58+
- uses: actions/checkout@v2
59+
- uses: actions/setup-node@v2
60+
with:
61+
node-version: 12
62+
- run: npm ci
63+
env:
64+
DEBUG: pw:install
65+
- run: npm run build
66+
- run: npm run ttest

install-from-github.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@
1818
// This file is only run when someone installs via the github repo
1919

2020
const {execSync} = require('child_process');
21+
const path = require('path');
22+
23+
console.log(`Updating test runner...`);
24+
try {
25+
execSync('npm ci --save=false --fund=false --audit=false', {
26+
stdio: ['inherit', 'inherit', 'inherit'],
27+
cwd: path.join(__dirname, 'tests', 'config', 'test-runner'),
28+
});
29+
} catch (e) {
30+
process.exit(1);
31+
}
2132

2233
console.log(`Rebuilding installer...`);
2334
try {

package-lock.json

Lines changed: 374 additions & 572 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
"node": ">=12"
1010
},
1111
"scripts": {
12-
"ctest": "folio --config=tests/config/default.config.ts --project=chromium",
13-
"ftest": "folio --config=tests/config/default.config.ts --project=firefox",
14-
"wtest": "folio --config=tests/config/default.config.ts --project=webkit",
15-
"atest": "folio --config=tests/config/android.config.ts",
16-
"etest": "folio --config=tests/config/electron.config.ts",
17-
"test": "folio --config=tests/config/default.config.ts",
12+
"basetest": "node ./tests/config/test-runner/node_modules/@playwright/test/lib/cli/cli.js test",
13+
"ctest": "npm run basetest -- --config=tests/config/default.config.ts --project=chromium",
14+
"ftest": "npm run basetest -- --config=tests/config/default.config.ts --project=firefox",
15+
"wtest": "npm run basetest -- --config=tests/config/default.config.ts --project=webkit",
16+
"atest": "npm run basetest -- --config=tests/config/android.config.ts",
17+
"etest": "npm run basetest -- --config=tests/config/electron.config.ts",
18+
"ttest": "npm run basetest -- --config=tests/playwright-test/playwright-test.config.ts",
19+
"test": "npm run basetest -- --config=tests/config/default.config.ts",
1820
"eslint": "[ \"$CI\" = true ] && eslint --quiet -f codeframe --ext ts . || eslint --ext ts .",
1921
"tsc": "tsc -p .",
2022
"tsc-installer": "tsc -p ./src/install/tsconfig.json",
@@ -36,7 +38,32 @@
3638
"bin": {
3739
"playwright": "./lib/cli/cli.js"
3840
},
41+
"DEPS-NOTE": "Any non-test dependency must be added to the build_package.js script as well",
3942
"dependencies": {
43+
"@babel/code-frame": "^7.12.13",
44+
"@babel/core": "^7.14.0",
45+
"@babel/plugin-proposal-class-properties": "^7.13.0",
46+
"@babel/plugin-proposal-dynamic-import": "^7.13.8",
47+
"@babel/plugin-proposal-export-namespace-from": "^7.12.13",
48+
"@babel/plugin-proposal-logical-assignment-operators": "^7.13.8",
49+
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.13.8",
50+
"@babel/plugin-proposal-numeric-separator": "^7.12.13",
51+
"@babel/plugin-proposal-optional-chaining": "^7.13.12",
52+
"@babel/plugin-proposal-private-methods": "^7.13.0",
53+
"@babel/plugin-proposal-private-property-in-object": "^7.14.0",
54+
"@babel/plugin-syntax-async-generators": "^7.8.4",
55+
"@babel/plugin-syntax-json-strings": "^7.8.3",
56+
"@babel/plugin-syntax-object-rest-spread": "^7.8.3",
57+
"@babel/plugin-syntax-optional-catch-binding": "^7.8.3",
58+
"@babel/plugin-transform-modules-commonjs": "^7.14.0",
59+
"@babel/preset-typescript": "^7.13.0",
60+
"colors": "^1.4.0",
61+
"expect": "^26.4.2",
62+
"minimatch": "^3.0.3",
63+
"ms": "^2.1.2",
64+
"pirates": "^4.0.1",
65+
"pixelmatch": "^5.2.1",
66+
"source-map-support": "^0.4.18",
4067
"commander": "^6.1.0",
4168
"debug": "^4.1.1",
4269
"extract-zip": "^2.0.1",
@@ -53,10 +80,14 @@
5380
"yazl": "^2.5.1"
5481
},
5582
"devDependencies": {
83+
"@types/babel__code-frame": "^7.0.2",
84+
"@types/babel__core": "^7.1.14",
5685
"@types/debug": "^4.1.5",
5786
"@types/extract-zip": "^1.6.2",
5887
"@types/mime": "^2.0.3",
88+
"@types/minimatch": "^3.0.3",
5989
"@types/node": "^10.17.28",
90+
"@types/pixelmatch": "^5.2.1",
6091
"@types/pngjs": "^3.4.2",
6192
"@types/progress": "^2.0.3",
6293
"@types/proper-lockfile": "^4.1.1",
@@ -65,8 +96,10 @@
6596
"@types/react-dom": "^17.0.0",
6697
"@types/resize-observer-browser": "^0.1.4",
6798
"@types/rimraf": "^3.0.0",
99+
"@types/source-map-support": "^0.4.2",
68100
"@types/webpack": "^4.41.25",
69101
"@types/ws": "7.2.6",
102+
"@types/xml2js": "^0.4.5",
70103
"@types/yazl": "^2.4.2",
71104
"@typescript-eslint/eslint-plugin": "^4.25.0",
72105
"@typescript-eslint/parser": "^4.25.0",
@@ -80,7 +113,6 @@
80113
"eslint-plugin-notice": "^0.9.10",
81114
"eslint-plugin-react-hooks": "^4.2.0",
82115
"file-loader": "^6.1.0",
83-
"folio": "=0.4.0-alpha28",
84116
"formidable": "^1.2.2",
85117
"html-webpack-plugin": "^4.4.1",
86118
"ncp": "^2.0.0",
@@ -90,9 +122,10 @@
90122
"socksv5": "0.0.6",
91123
"style-loader": "^1.2.1",
92124
"ts-loader": "^8.0.3",
93-
"typescript": "^4.0.2",
125+
"typescript": "=4.2.4",
94126
"webpack": "^4.44.2",
95127
"webpack-cli": "^3.3.12",
128+
"xml2js": "^0.4.23",
96129
"yaml": "^1.10.0"
97130
}
98131
}

packages/build_package.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,27 @@ const PACKAGES = {
6161
'playwright-chromium': {
6262
description: 'A high-level API to automate Chromium',
6363
browsers: ['chromium', 'ffmpeg'],
64-
files: [...PLAYWRIGHT_CORE_FILES],
64+
files: PLAYWRIGHT_CORE_FILES,
6565
},
6666
};
6767

68+
const DEPENDENCIES = [
69+
'commander',
70+
'debug',
71+
'extract-zip',
72+
'https-proxy-agent',
73+
'jpeg-js',
74+
'mime',
75+
'pngjs',
76+
'progress',
77+
'proper-lockfile',
78+
'proxy-from-env',
79+
'rimraf',
80+
'stack-utils',
81+
'ws',
82+
'yazl',
83+
];
84+
6885
// 1. Parse CLI arguments
6986
const args = process.argv.slice(2);
7087
if (args.some(arg => arg === '--help')) {
@@ -121,9 +138,10 @@ if (!args.some(arg => arg === '--no-cleanup')) {
121138

122139
// 4. Generate package.json
123140
const pwInternalJSON = require(path.join(ROOT_PATH, 'package.json'));
124-
const dependencies = { ...pwInternalJSON.dependencies };
125-
if (packageName === 'playwright-test')
126-
dependencies.folio = pwInternalJSON.devDependencies.folio;
141+
const depNames = packageName === 'playwright-test' ? Object.keys(pwInternalJSON.dependencies) : DEPENDENCIES;
142+
const dependencies = {};
143+
for (const dep of depNames)
144+
dependencies[dep] = pwInternalJSON.dependencies[dep];
127145
await writeToPackage('package.json', JSON.stringify({
128146
name: package.name || packageName,
129147
version: pwInternalJSON.version,

packages/playwright-test/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616

1717
module.exports = {
1818
...require('./lib/inprocess'),
19-
...require('./lib/cli/fixtures')
19+
...require('./lib/test/index')
2020
};

src/cli/cli.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ import { BrowserContextOptions, LaunchOptions } from '../client/types';
3535
import { spawn } from 'child_process';
3636
import { installDeps } from '../install/installDeps';
3737
import { allBrowserNames, BrowserName } from '../utils/registry';
38-
import { addTestCommand } from './testRunner';
3938
import * as utils from '../utils/utils';
4039

4140
const SCRIPTS_DIRECTORY = path.join(__dirname, '..', '..', 'bin');
4241

4342
type BrowserChannel = 'chrome-beta'|'chrome';
4443
const allBrowserChannels: Set<BrowserChannel> = new Set(['chrome-beta', 'chrome']);
44+
const packageJSON = require('../../package.json');
4545

4646
program
47-
.version('Version ' + require('../../package.json').version)
47+
.version('Version ' + packageJSON.version)
4848
.name(process.env.PW_CLI_NAME || 'npx playwright');
4949

5050
commandWithOpenOptions('open [url]', 'open page in browser specified via -b, --browser', [])
@@ -226,8 +226,19 @@ program
226226
console.log(' $ show-trace trace/directory');
227227
});
228228

229-
if (!process.env.PW_CLI_TARGET_LANG)
230-
addTestCommand(program);
229+
if (!process.env.PW_CLI_TARGET_LANG) {
230+
if (packageJSON.name === '@playwright/test' || process.env.PWTEST_CLI_ALLOW_TEST_COMMAND) {
231+
require('../test/cli').addTestCommand(program);
232+
} else {
233+
const command = program.command('test');
234+
command.description('Run tests with Playwright Test. Available in @playwright/test package.');
235+
command.action(async (args, opts) => {
236+
console.error('Please install @playwright/test package to use Playwright Test.');
237+
console.error(' npm install -D @playwright/test');
238+
process.exit(1);
239+
});
240+
}
241+
}
231242

232243
if (process.argv[2] === 'run-driver')
233244
runDriver();

src/cli/testRunner.ts renamed to src/test/cli.ts

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919
import * as commander from 'commander';
2020
import * as fs from 'fs';
2121
import * as path from 'path';
22-
import type { Config } from 'folio';
23-
24-
type RunnerType = typeof import('folio/out/runner').Runner;
22+
import type { Config } from './types';
23+
import { Runner } from './runner';
2524

2625
const defaultTimeout = 30000;
2726
const defaultReporter = process.env.CI ? 'dot' : 'list';
@@ -37,14 +36,6 @@ const defaultConfig: Config = {
3736
};
3837

3938
export function addTestCommand(program: commander.CommanderStatic) {
40-
let Runner: RunnerType;
41-
try {
42-
Runner = require('folio/out/runner').Runner as RunnerType;
43-
} catch (e) {
44-
addStubTestCommand(program);
45-
return;
46-
}
47-
4839
const command = program.command('test [test-filter...]');
4940
command.description('Run tests with Playwright Test');
5041
command.option('--browser <browser>', `Browser to use for tests, one of "all", "chromium", "firefox" or "webkit" (default: "chromium")`);
@@ -68,7 +59,7 @@ export function addTestCommand(program: commander.CommanderStatic) {
6859
command.option('-x', `Stop after the first failure`);
6960
command.action(async (args, opts) => {
7061
try {
71-
await runTests(Runner, args, opts);
62+
await runTests(args, opts);
7263
} catch (e) {
7364
console.error(e.toString());
7465
process.exit(1);
@@ -86,7 +77,7 @@ export function addTestCommand(program: commander.CommanderStatic) {
8677
});
8778
}
8879

89-
async function runTests(Runner: RunnerType, args: string[], opts: { [key: string]: any }) {
80+
async function runTests(args: string[], opts: { [key: string]: any }) {
9081
const browserOpt = opts.browser ? opts.browser.toLowerCase() : 'chromium';
9182
if (!['all', 'chromium', 'firefox', 'webkit'].includes(browserOpt))
9283
throw new Error(`Unsupported browser "${opts.browser}", must be one of "all", "chromium", "firefox" or "webkit"`);
@@ -135,11 +126,6 @@ async function runTests(Runner: RunnerType, args: string[], opts: { [key: string
135126
throw new Error(`Configuration file not found. Run "npx playwright test --help" for more information.`);
136127
}
137128

138-
process.env.FOLIO_JUNIT_OUTPUT_NAME = process.env.PLAYWRIGHT_JUNIT_OUTPUT_NAME;
139-
process.env.FOLIO_JUNIT_SUITE_ID = process.env.PLAYWRIGHT_JUNIT_SUITE_ID;
140-
process.env.FOLIO_JUNIT_SUITE_NAME = process.env.PLAYWRIGHT_JUNIT_SUITE_NAME;
141-
process.env.FOLIO_JSON_OUTPUT_NAME = process.env.PLAYWRIGHT_JSON_OUTPUT_NAME;
142-
143129
const result = await runner.run(!!opts.list, args.map(forceRegExp), opts.project || undefined);
144130
if (result === 'sigint')
145131
process.exit(130);
@@ -172,13 +158,3 @@ function overridesFromOptions(options: { [key: string]: any }): Config {
172158
workers: options.workers ? parseInt(options.workers, 10) : undefined,
173159
};
174160
}
175-
176-
function addStubTestCommand(program: commander.CommanderStatic) {
177-
const command = program.command('test');
178-
command.description('Run tests with Playwright Test. Available in @playwright/test package.');
179-
command.action(async (args, opts) => {
180-
console.error('Please install @playwright/test package to use Playwright Test.');
181-
console.error(' npm install -D @playwright/test');
182-
process.exit(1);
183-
});
184-
}

0 commit comments

Comments
 (0)