File size: 3,977 Bytes
af1bee9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env node
// One-command runner: `npm test` -> Playwright (PLAYWRIGHT_MODE=live against the local MOCK app) -> case map -> artifact check.
// Each run writes to results/runs/<PW_RUN_ID>/; canonical results/ is updated only on full runs (scripts/promote-reporter.js).
// Exit code is Playwright's (or 1 if referenced artifacts are missing), so CI/orchestrator sees real failures.
const { spawnSync } = require('child_process'); const fs = require('fs'); const path = require('path');
const d = new Date(); const p2 = (n) => String(n).padStart(2, '0');
const runId = process.env.PW_RUN_ID || `${d.getFullYear()}${p2(d.getMonth() + 1)}${p2(d.getDate())}-${p2(d.getHours())}${p2(d.getMinutes())}${p2(d.getSeconds())}-${process.pid}`;
const env = { ...process.env, PLAYWRIGHT_MODE: process.env.PLAYWRIGHT_MODE || 'live', PW_RUN_ID: runId };
const root = path.resolve(__dirname, '..'); const runDir = path.join(root, 'results', 'runs', runId);
const pw = spawnSync('npx', ['playwright', 'test', ...process.argv.slice(2)], { stdio: 'inherit', env, shell: process.platform === 'win32' });
const node = (script, extraEnv = {}, args = []) => spawnSync(process.execPath, [path.join(__dirname, script), ...args], { stdio: 'inherit', env: { ...env, ...extraEnv } }).status;
const runJson = path.join(runDir, 'results.pwjson');
let artifactsOk = true;
if (fs.existsSync(runJson)) {
  node('case-map.js', { CASE_MAP_RESULTS: runJson, CASE_MAP_OUTDIR: runDir });
  artifactsOk = node('verify-artifacts.js', {}, [runJson]) === 0;
  const info = fs.existsSync(path.join(runDir, 'run-info.json')) ? JSON.parse(fs.readFileSync(path.join(runDir, 'run-info.json'), 'utf8')) : {};
  if (info.promoted) { node('case-map.js'); artifactsOk = node('verify-artifacts.js') === 0 && artifactsOk; }
} else console.error(`No results.pwjson in ${runDir}`);
// Tolerant suite (suite: tolerant / go_no_go: false): separate Playwright run + case map under results/tolerant/. Never changes the
// go/no-go results or this command's exit code; its outcome is printed for separate reporting. Skipped for filtered runs.
const plain = process.argv.length <= 2 && !process.env.RUN_MODULES && String(process.env.RUN_SUITE || 'gate').toLowerCase() !== 'tolerant';
if (plain && process.env.SKIP_TOLERANT !== '1') {
  const tId = `${runId}-tolerant`; const tDir = path.join(root, 'results', 'runs', tId);
  console.log(`\n=== Tolerant suite (separate; not go/no-go) run ${tId} ===`);
  const t = spawnSync('npx', ['playwright', 'test'], { stdio: 'inherit', env: { ...env, PW_RUN_ID: tId, RUN_SUITE: 'tolerant' }, shell: process.platform === 'win32' });
  const tJson = path.join(tDir, 'results.pwjson');
  if (fs.existsSync(tJson)) {
    node('case-map.js', { CASE_MAP_RESULTS: tJson, CASE_MAP_OUTDIR: path.join(root, 'results', 'tolerant'), CASE_MAP_SUITE: 'tolerant' });
    node('verify-artifacts.js', {}, [tJson]);
  }
  console.log(`Tolerant suite exit code ${t.status} (reported separately; does not affect go/no-go or this exit code).`);
}
if (plain && process.env.SKIP_HELD !== '1') {
  // Held suite (execution_hold): scripted cases of HELD_RUN_MODULES (default HCM) against the MOCK only; never a pod; not go/no-go.
  const hId = `${runId}-held`; const hDir = path.join(root, 'results', 'runs', hId);
  console.log(`\n=== Held suite (execution_hold; MOCK only; not go/no-go) run ${hId} ===`);
  const h = spawnSync('npx', ['playwright', 'test', '--pass-with-no-tests'], { stdio: 'inherit', env: { ...env, PW_RUN_ID: hId, RUN_SUITE: 'held' }, shell: process.platform === 'win32' });
  const hJson = path.join(hDir, 'results.pwjson');
  if (fs.existsSync(hJson)) { node('case-map.js', { CASE_MAP_RESULTS: hJson, CASE_MAP_OUTDIR: path.join(root, 'results', 'held'), CASE_MAP_SUITE: 'held' }); node('verify-artifacts.js', {}, [hJson]); }
  console.log(`Held suite exit code ${h.status} (reported separately).`);
}
process.exit(pw.status || (artifactsOk ? 0 : 1));