mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 20:45:00 -05:00
The Tests menu had "ALL tests, parallel", "ALL tests, sequential" and, eleven entries below them, "EVERYTHING (sequential)" - and nothing said what the difference was. "ALL tests" runs WeKan's own suite only: Mocha, the node unit suites, the import regression, the node E2E harness and the three browsers. "EVERYTHING" runs that, then the database conformance run for every database with a Docker image for this CPU, then all of FerretDB's own tests. Two entries claiming to be all of them, one of which is not. Now the everything-run is entry 1 in both build.sh and build.bat, the other two are named "WeKan's own tests only" and their descriptions end with what they do NOT cover, and every option says where its logs go. Every option in the menu now also WRITES those logs: a new one_log helper in build.sh (:onelog / :tee in build.bat) puts Mocha, the import regression, node E2E, each Playwright browser, the floating-promises guard and the test counts into ../log/<datetime>/ beside the whole-suite runs. It reuses WEKAN_LOGDIR when a larger run set one, so a run stays in ONE directory. Before this, running a single option left nothing to check afterwards - "check the newest test logs" only worked for the whole-suite runs. The .bat prompts stay outside the tee: PowerShell's Tee-Object buffers the pipeline, so a piped "[y/N]" prompt is never shown. The guard test pins the order and the wording: entry 1 must be the everything -run, entries 2 and 3 must not claim to be ALL tests, and both scripts must log every option. Thanks to xet7 !
161 lines
8.2 KiB
JavaScript
161 lines
8.2 KiB
JavaScript
'use strict';
|
|
|
|
// build.sh and build.bat are the same menu on two platforms, and build.sh is the
|
|
// one that gets used - so build.bat drifts behind it silently. Two things are
|
|
// checked here, both of which had gone wrong:
|
|
//
|
|
// * the test runs must ALWAYS delete .build and build WeKan first. Both scripts
|
|
// built only when the bundle was MISSING, which is precisely the case where a
|
|
// bundle exists but is stale: the suite then passes or fails on code that is
|
|
// no longer in the working tree.
|
|
// * every menu entry build.sh offers must exist in build.bat. Two were missing:
|
|
// the dev server's custom port + ROOT_URL host, and "Install Playwright
|
|
// browsers".
|
|
//
|
|
// Run: node tests/buildScriptParity.test.cjs
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
|
|
const read = rel => fs.readFileSync(path.join(__dirname, '..', rel), 'utf8');
|
|
|
|
const sh = read('build.sh');
|
|
const bat = read('build.bat');
|
|
|
|
console.log('buildScriptParity:');
|
|
|
|
test('build.sh builds before the tests, every time', () => {
|
|
const at = sh.indexOf('function run_all_tests()');
|
|
assert.ok(at !== -1, 'the ALL-tests flow must be there');
|
|
const flow = sh.slice(at, sh.indexOf('\n}\n', at));
|
|
const build = flow.indexOf('build_wekan');
|
|
assert.ok(build !== -1, 'it must build');
|
|
// Unconditionally: not inside an `if [ ! -d .build/bundle ]` guard.
|
|
assert.ok(!/if \[ ! -d \.build\/bundle \][^\n]*\n\s*echo[^\n]*\n\s*build_wekan/.test(flow),
|
|
'building only when the bundle is MISSING leaves a stale bundle in place');
|
|
assert.ok(/Deleting \.build and building WeKan before running the tests/.test(flow),
|
|
'and it says so');
|
|
// build_wekan is what deletes .build.
|
|
const fn = sh.slice(sh.indexOf('function build_wekan()'));
|
|
assert.ok(/rm -rf [^\n]*\.build/.test(fn.slice(0, 400)), 'build_wekan deletes .build');
|
|
// The server it starts is the bundle, so the freshness matters.
|
|
assert.ok(/serves Node E2E \+ Playwright browser tests\. Built fresh above/.test(flow),
|
|
'the description must not still promise the old bundle is reused');
|
|
});
|
|
|
|
test('build.bat does the same, in both of its ALL-tests flows', () => {
|
|
assert.ok(/^:rebuild_for_tests/m.test(bat), 'the subroutine must exist');
|
|
const sub = bat.slice(/^:rebuild_for_tests/m.exec(bat).index);
|
|
assert.ok(/rmdir \/s \/q "%REPO%\\\.build"/.test(sub.slice(0, 900)), 'it deletes .build');
|
|
assert.ok(/call meteor build \.build --directory/.test(sub.slice(0, 900)), 'and builds');
|
|
assert.ok(/main\.js is missing after building/.test(sub.slice(0, 1200)),
|
|
'and refuses to run the tests without a bundle');
|
|
for (const label of [':test_all_parallel', ':test_all_sequential']) {
|
|
const flow = bat.slice(bat.indexOf(label), bat.indexOf('call :start_bundle_server',
|
|
bat.indexOf(label)));
|
|
assert.ok(/call :rebuild_for_tests/.test(flow),
|
|
`${label} must rebuild before starting the test server`);
|
|
assert.ok(/if errorlevel 1 goto end/.test(flow.slice(flow.indexOf('call :rebuild_for_tests'))),
|
|
`${label} must stop when the build failed`);
|
|
}
|
|
assert.ok(!/No recompile: your existing build is reused/.test(bat));
|
|
});
|
|
|
|
test('"Run ALL tests" really runs all of them, in both scripts', () => {
|
|
// The node suites - test:unit:all, i.e. the ~165 .cjs guards plus the sticker /
|
|
// Trello / OAuth2 .js tests - were in package.json and in no test RUN: the flow
|
|
// ran mocha, import, e2e and the three browsers only. A guard that never runs
|
|
// guards nothing.
|
|
const flow = sh.slice(sh.indexOf('function run_all_tests()'));
|
|
assert.ok(/unit\) meteor npm run test:unit:all \|\| rc=\$\?/.test(flow),
|
|
'build.sh must have a unit job that runs test:unit:all');
|
|
assert.ok(/launch_job unit/.test(flow), 'and launch it');
|
|
for (const keys of flow.match(/ALLKEYS="[^"]+"/g) || []) {
|
|
assert.ok(/\bunit\b/.test(keys), `${keys} must include the unit job`);
|
|
}
|
|
assert.ok(/unit\) echo "Unit tests \(node\)" ;;/.test(flow), 'labelled in the summary');
|
|
assert.ok(/unit\) n=\$\(grep -cE '\^\\s\*ok - '/.test(flow),
|
|
'and counted - the node suites print " ok - <name>", not a check mark');
|
|
|
|
// build.bat: both flows start it, wait for it and report it.
|
|
assert.ok((bat.match(/start "Wekan unit"/g) || []).length === 2,
|
|
'both .bat flows must start the unit job');
|
|
assert.ok(/call :seq_run_wait unit unit C_unit/.test(bat), 'sequential waits for it');
|
|
assert.ok(/if not exist "\.done-unit" set "ALLDONE=0"/.test(bat), 'parallel waits for it');
|
|
assert.ok((bat.match(/call :report "!S_unit!"/g) || []).length === 2,
|
|
'and both summaries report it');
|
|
assert.ok(/:jcount_unit/.test(bat), 'with a counter that understands its output');
|
|
assert.ok(/call meteor npm run test:unit:all/.test(bat), 'running the same script');
|
|
});
|
|
|
|
test('every menu entry of build.sh exists in build.bat', () => {
|
|
// build.sh's entries are "Label|description" pairs passed to choose().
|
|
const labels = [...sh.matchAll(/^\s*"([^"|]+)\|[^"]*"\s*\\?$/gm)].map(m => m[1].trim());
|
|
assert.ok(labels.length > 20, `expected the whole menu, found ${labels.length}`);
|
|
// How each one is spelled in the .bat menu (same words, or the closest thing
|
|
// Windows offers). A label missing from BOTH lists is a real parity gap.
|
|
const spelling = {
|
|
'localhost:3000 + trace warnings': 'trace warnings',
|
|
'localhost:3000 + bundle visualizer': 'bundle visualizer',
|
|
'CURRENT-IP:3000 + MONGO_URL 27019': 'MONGO_URL 27019',
|
|
'Mocha (server-side)': 'Mocha',
|
|
// The .bat menu escapes its parentheses (echo 1^) EVERYTHING ^(sequential^)),
|
|
// so the label is compared without them.
|
|
'EVERYTHING (sequential): WeKan tests + all databases + FerretDB tests':
|
|
'EVERYTHING ^(sequential^)',
|
|
'FerretDB v1 MySQL (experimental)': 'FerretDB v1 MySQL',
|
|
'FerretDB v1 MariaDB (experimental)': 'FerretDB v1 MariaDB',
|
|
'FerretDB v1 SAP HANA (experimental)': 'FerretDB v1 SAP HANA',
|
|
// The Docker backends are named slightly differently in the two menus; what
|
|
// must match is the compose file each one starts, which is checked below.
|
|
'FerretDB v2 (PostgreSQL)': 'ferretdb-v2-postgresql',
|
|
};
|
|
const missing = labels.filter(label => {
|
|
const needle = spelling[label] || label;
|
|
return !bat.includes(needle);
|
|
});
|
|
assert.deepStrictEqual(missing, [],
|
|
'build.bat is missing menu entries build.sh has - it is the one that drifts');
|
|
});
|
|
|
|
test('both offer the same Docker backends, by compose file', () => {
|
|
// The labels differ ("FerretDB v2 (PostgreSQL)" vs "FerretDB v2 Postgres");
|
|
// the file each one starts is the thing that must not drift.
|
|
const files = s => [...s.matchAll(/docker-compose[\w.-]*\.yml/g)].map(m => m[0]);
|
|
const inSh = new Set(files(sh));
|
|
const inBat = new Set(files(bat));
|
|
const missing = [...inSh].filter(f => !inBat.has(f));
|
|
assert.deepStrictEqual(missing, [], 'a backend build.sh can start and build.bat cannot');
|
|
});
|
|
|
|
test('the .bat menus number what they dispatch', () => {
|
|
// A menu that prints 1..12 but dispatches 1..11 silently drops an entry - which
|
|
// is how a parity gap survives being "added".
|
|
for (const menu of ['menu_dev', 'menu_tests', 'menu_setup', 'menu_tools']) {
|
|
const start = bat.indexOf(`:${menu}`);
|
|
assert.ok(start !== -1, `${menu} must exist`);
|
|
const block = bat.slice(start, bat.indexOf(`goto ${menu}`, start + menu.length));
|
|
const printed = [...block.matchAll(/echo\s+(\d+)\^\)/g)].map(m => Number(m[1]));
|
|
const dispatched = [...block.matchAll(/if "%choice%"=="(\d+)"/g)]
|
|
.map(m => Number(m[1])).filter(n => n !== 0);
|
|
assert.deepStrictEqual(dispatched, printed, `${menu}: printed and dispatched differ`);
|
|
}
|
|
});
|
|
|
|
test('every goto/call in build.bat has a label to land on', () => {
|
|
const labels = new Set([...bat.matchAll(/^:(\w+)/gm)].map(m => m[1].toLowerCase()));
|
|
const targets = new Set([
|
|
...[...bat.matchAll(/goto\s+(\w+)/g)].map(m => m[1].toLowerCase()),
|
|
...[...bat.matchAll(/call\s+:(\w+)/g)].map(m => m[1].toLowerCase()),
|
|
]);
|
|
targets.delete('end');
|
|
targets.delete('eof');
|
|
const missing = [...targets].filter(t => !labels.has(t));
|
|
assert.deepStrictEqual(missing, [], 'a goto with no label falls through to the next line');
|
|
});
|
|
|
|
console.log(`\n${passed} tests passed`);
|