mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 20:45:00 -05:00
Two gaps, and together they meant most of the test suite never ran anywhere. The flow ran six jobs - mocha, the import regression, the Node E2E harness and the three browsers - and no npm unit script at all. Everything in `test:unit:node` and `test:unit:all` was therefore never executed by "Run ALL tests": that is the ~165 .cjs guards plus the sticker, Trello and OAuth2 suites. A guard that never runs guards nothing, and several of those were written to fail the suite when a fix regresses. Both scripts now have a `unit` job that runs `meteor npm run test:unit:all`. It needs no server and no browser, so it starts beside Mocha and the import regression in the parallel flow, and takes its own step in the sequential one; it is counted, waited for and reported in both, with its own ../log/<run>/wekan-alltests-unit.log. And the scripts themselves were incomplete: 72 suite files existed that no npm script mentioned - addCardTabSubmit, apiLogout, boardRepair, exportHTMLXss, ldapPasswordLoginGuard, oidcProfileMerge, userDeletionCleanup and 65 more. They are all in `test:unit:node` now; `tests/rtl.test.js`, which documents itself as runnable by node, joins `test:unit:all`. `tests/all.test.js` stays out on purpose: it is the Meteor mocha ENTRY POINT that imports the two suite indexes, and it runs under `meteor test`, which is the mocha job. tests/testsAreRegistered.test.cjs - which already caught suites missing from the mocha indexes - now also fails when a plain-node suite is in no npm script, and when the ALL-tests flow stops running that script. tests/buildScriptParity.test.cjs pins the job in both files: the command, the launch, the key sets, the label, the counter, and in the .bat both flows starting it, waiting for it and reporting it. NOT verified here: there is no node in this environment, so those 72 suites have never been executed anywhere. Some may fail on the first real run - that is the information this change buys, not a regression it introduces. Thanks to xet7 !
154 lines
7.7 KiB
JavaScript
154 lines
7.7 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 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`);
|