mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Use Gecko app-data overrides for macOS Firefox in the build-menu probe, Playwright probe and real test projects. Keep isolated directories under .tools/tmp and clean them on process exit without changing HOME or browser sandboxes. Three helper regression tests and six Docker/config checks pass. All three focused security browser scenarios pass in Firefox on macOS 27.0.1. Thanks to xet7 !
112 lines
5.2 KiB
JavaScript
112 lines
5.2 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const build = fs.readFileSync(path.join(__dirname, '..', 'build.sh'), 'utf8');
|
|
let passed = 0;
|
|
function test(name, fn) {
|
|
fn();
|
|
passed += 1;
|
|
console.log(` ok - ${name}`);
|
|
}
|
|
|
|
console.log('playwrightDockerHost:');
|
|
|
|
test('Docker is discovered directly or through the Flatpak host bridge', () => {
|
|
assert.match(build, /function docker_available\(\)/);
|
|
assert.match(build, /command -v flatpak-spawn/);
|
|
assert.match(build, /flatpak-spawn --host sh -lc 'command -v docker/);
|
|
});
|
|
|
|
test('Docker commands use the shared host-aware wrapper', () => {
|
|
assert.match(build, /function docker_exec\(\)/);
|
|
assert.match(build, /flatpak-spawn --host docker "\$@"/);
|
|
assert.match(build, /docker_exec run --rm --init --ipc=host --network host/);
|
|
assert.match(build, /docker_exec pull "mcr\.microsoft\.com\/playwright:/);
|
|
});
|
|
|
|
test('the Playwright runner fails clearly only when neither route exists', () => {
|
|
const runner = build.slice(
|
|
build.indexOf('function run_playwright_docker'),
|
|
build.indexOf('function run_playwright_webkit_docker'),
|
|
);
|
|
assert.match(runner, /if ! docker_available; then/);
|
|
assert.doesNotMatch(runner, /command -v docker/);
|
|
});
|
|
|
|
test("the runner installs local browsers and falls back per browser", () => {
|
|
assert.ok(build.includes("function ensure_playwright_test_dependencies()"));
|
|
assert.ok(build.includes("function ensure_native_playwright_browser()"));
|
|
assert.ok(build.includes("$WEKAN_DIR/.tools/ms-playwright"));
|
|
assert.ok(build.includes("! native_browser_can_launch \"$browser\" && docker_available"));
|
|
const config = fs.readFileSync(path.join(__dirname, "playwright", "playwright.config.js"), "utf8");
|
|
assert.ok(config.includes("LOCAL_BROWSER_CACHE"));
|
|
assert.ok(config.includes("ms-playwright"));
|
|
assert.ok(build.includes("function native_browser_is_installed()"));
|
|
assert.ok(build.includes("WEKAN_PLAYWRIGHT_PROJECT=\"$browser\""));
|
|
assert.ok(config.includes("SELECTED_BROWSER"));
|
|
assert.ok(/SELECTED_BROWSER[\s\S]*name: SELECTED_BROWSER/.test(config));
|
|
});
|
|
|
|
|
|
test('browser retry policy preserves normal runs and stops immediately in bail mode', () => {
|
|
const source = fs.readFileSync(path.join(__dirname, 'playwright', 'playwright.config.js'), 'utf8');
|
|
const vm = require('node:vm');
|
|
function config(env) {
|
|
const sandbox = {
|
|
module: { exports: {} }, __dirname: path.join(__dirname, 'playwright'),
|
|
process: { env: { WEKAN_PLAYWRIGHT_PROBE: '0', WEKAN_PLAYWRIGHT_ALL: '1', ...env } },
|
|
require: name => name === '@playwright/test'
|
|
? { defineConfig: value => value, devices: {} }
|
|
: name === './helpers/browser-launch.cjs' ? { browserLaunchOptions: () => ({}) } : require(name),
|
|
};
|
|
vm.runInNewContext(source, sandbox);
|
|
return sandbox.module.exports;
|
|
}
|
|
assert.strictEqual(config({}).projects.find(project => project.name === 'webkit').retries, 1);
|
|
assert.strictEqual(config({ CI: '1' }).retries, 2, 'normal CI retains its retries');
|
|
assert.strictEqual(config({}).use.trace, 'on-first-retry');
|
|
for (const CI of ['', '1']) {
|
|
const value = config({ CI, WEKAN_TEST_BAIL: '1' });
|
|
assert.strictEqual(value.retries, 0, 'bail stops at the first failure');
|
|
assert.strictEqual(value.maxFailures, 1);
|
|
assert.strictEqual(value.use.trace, 'retain-on-failure', 'first failure retains evidence without retrying');
|
|
assert.ok(value.projects.every(project => !project.retries), 'no project can override bail with a retry');
|
|
assert.deepStrictEqual(Array.from(value.projects, project => project.name), ['chromium', 'firefox', 'webkit']);
|
|
}
|
|
});
|
|
|
|
|
|
test('macOS Docker pins only gateway Mongo connections and preserves URI options', () => {
|
|
const { execFileSync } = require('node:child_process');
|
|
const root = path.resolve(__dirname, '..');
|
|
const temp = fs.mkdtempSync(path.join(root, '.tools/tmp/playwright-docker-uri-'));
|
|
const runner = build.slice(build.indexOf('function run_playwright_docker'),
|
|
build.indexOf('function run_playwright_webkit_docker'));
|
|
const script = `
|
|
docker_available() { return 0; }
|
|
ensure_playwright_test_dependencies() { return 0; }
|
|
uname() { printf Darwin; }
|
|
node() { printf 1.63.0; }
|
|
docker_exec() { printf '%s\\n' "$@"; }
|
|
${runner}
|
|
run_playwright_docker firefox --list
|
|
`;
|
|
try {
|
|
for (const [uri, expected] of [
|
|
['mongodb://127.0.0.1:3101/meteor', 'mongodb://host.docker.internal:3101/meteor?directConnection=true'],
|
|
['mongodb://localhost:3101/meteor?replicaSet=meteor', 'mongodb://host.docker.internal:3101/meteor?replicaSet=meteor&directConnection=true'],
|
|
['mongodb://localhost:3101/meteor?directConnection=false', 'mongodb://host.docker.internal:3101/meteor?directConnection=false'],
|
|
['mongodb://database.example/meteor', 'mongodb://database.example/meteor'],
|
|
]) {
|
|
const output = execFileSync('bash', ['-c', script], { encoding: 'utf8',
|
|
env: { ...process.env, TMPDIR: temp, WEKAN_DIR: temp, WEKAN_FILES_PATH_HOST: temp, WEKAN_MONGO_URL: uri, WEKAN_TEST_SMTP_PORT: '' } });
|
|
assert.ok(output.split('\n').includes(`WEKAN_MONGO_URL=${expected}`), output);
|
|
}
|
|
} finally { fs.rmSync(temp, { recursive: true, force: true }); }
|
|
});
|
|
|
|
console.log(`\n${passed} tests passed`);
|