any-browser 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/postinstall.js +5 -3
- package/src/runner.js +41 -6
package/package.json
CHANGED
package/src/postinstall.js
CHANGED
|
@@ -7,9 +7,11 @@ const isCI = !!process.env.CI;
|
|
|
7
7
|
console.log('');
|
|
8
8
|
console.log(pc.cyan('any-browser needs real browser engines (Chromium, Firefox, WebKit) to run tests.'));
|
|
9
9
|
console.log(
|
|
10
|
-
pc.dim(
|
|
10
|
+
pc.dim("Getting a head start on that now (~300MB total, handled by Playwright)")
|
|
11
11
|
);
|
|
12
|
-
console.log(pc.dim(
|
|
12
|
+
console.log(pc.dim("so your first \"any-browser test\" run is fast. If this step gets"));
|
|
13
|
+
console.log(pc.dim('skipped by your npm/security settings, no problem — any-browser'));
|
|
14
|
+
console.log(pc.dim('double-checks and installs whatever it needs the first time you run it.'));
|
|
13
15
|
|
|
14
16
|
if (isCI) {
|
|
15
17
|
console.log(pc.yellow('\nCI environment detected — skipping the automatic download.'));
|
|
@@ -33,4 +35,4 @@ if (result.status === 0) {
|
|
|
33
35
|
console.log(pc.yellow('certain firewalls/proxies, or if disk space is low).'));
|
|
34
36
|
console.log(pc.dim('Run this once manually, then you\'re good:'));
|
|
35
37
|
console.log(pc.bold(' npx playwright install chromium firefox webkit\n'));
|
|
36
|
-
}
|
|
38
|
+
}
|
package/src/runner.js
CHANGED
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { dirname, join } from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
2
5
|
import pc from 'picocolors';
|
|
3
6
|
import { resolveBrowsers, ENGINE_LABELS } from './browsers.js';
|
|
4
7
|
|
|
8
|
+
const require = createRequire(import.meta.url);
|
|
9
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
|
|
11
|
+
// The config and tests live inside this package, not in whatever folder the
|
|
12
|
+
// user happens to be running `any-browser` from — so we resolve absolute
|
|
13
|
+
// paths to both instead of letting Playwright guess based on cwd.
|
|
14
|
+
const CONFIG_PATH = join(__dirname, '..', 'playwright.config.js');
|
|
15
|
+
|
|
16
|
+
function resolvePlaywrightCli() {
|
|
17
|
+
const pkgJsonPath = require.resolve('@playwright/test/package.json');
|
|
18
|
+
const pkg = require(pkgJsonPath);
|
|
19
|
+
const binFile = typeof pkg.bin === 'string' ? pkg.bin : pkg.bin.playwright;
|
|
20
|
+
return join(dirname(pkgJsonPath), binFile);
|
|
21
|
+
}
|
|
22
|
+
|
|
5
23
|
export async function runTests(browserArgs, options) {
|
|
6
24
|
const { resolved, unknown } = resolveBrowsers(browserArgs);
|
|
7
25
|
|
|
@@ -25,21 +43,38 @@ export async function runTests(browserArgs, options) {
|
|
|
25
43
|
}
|
|
26
44
|
}
|
|
27
45
|
|
|
28
|
-
function
|
|
46
|
+
function ensureBrowserInstalled(engine) {
|
|
29
47
|
return new Promise((resolve) => {
|
|
30
|
-
|
|
48
|
+
const cliPath = resolvePlaywrightCli();
|
|
49
|
+
// `playwright install <engine>` is cheap and near-instant if the browser
|
|
50
|
+
// is already present — it only actually downloads when something's
|
|
51
|
+
// missing. Running it here means we never depend solely on postinstall
|
|
52
|
+
// having been allowed to run.
|
|
53
|
+
const child = spawn(process.execPath, [cliPath, 'install', engine], {
|
|
54
|
+
stdio: 'inherit',
|
|
55
|
+
});
|
|
56
|
+
child.on('close', () => resolve());
|
|
57
|
+
child.on('error', () => resolve());
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function runOne(engine, options) {
|
|
62
|
+
console.log(pc.bold(`\n▶ ${ENGINE_LABELS[engine]} (${engine})`));
|
|
63
|
+
|
|
64
|
+
await ensureBrowserInstalled(engine);
|
|
31
65
|
|
|
32
|
-
|
|
33
|
-
|
|
66
|
+
const cliPath = resolvePlaywrightCli();
|
|
67
|
+
const args = ['test', `--project=${engine}`, `--config=${CONFIG_PATH}`];
|
|
68
|
+
if (!options.headless) args.push('--headed');
|
|
34
69
|
|
|
35
|
-
|
|
70
|
+
await new Promise((resolve) => {
|
|
71
|
+
const child = spawn(process.execPath, [cliPath, ...args], {
|
|
36
72
|
stdio: 'inherit',
|
|
37
73
|
env: {
|
|
38
74
|
...process.env,
|
|
39
75
|
TEST_URL: options.url,
|
|
40
76
|
TEST_HEADLESS: options.headless ? '1' : '0',
|
|
41
77
|
},
|
|
42
|
-
shell: process.platform === 'win32',
|
|
43
78
|
});
|
|
44
79
|
|
|
45
80
|
child.on('close', (code) => {
|