mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 20:45:00 -05:00
Both scripts built the bundle only when .build/bundle was MISSING - which is
exactly the case where a bundle exists and is stale. The :3000 test server runs
that precompiled bundle, so Node E2E and every Playwright browser were testing
whatever was built last time, and the run passed or failed on code that is no
longer in the working tree. That is the one thing a test run must never do.
Both now delete .build and build before starting anything, every time, and stop
with an error if the bundle is missing afterwards rather than running the suite
against nothing. build.bat gets a :rebuild_for_tests subroutine with the same
steps as its Setup "Build WeKan", called from both the parallel and the
sequential flow. The line that promised "No recompile: your existing build is
reused" is gone from both.
build.bat was also behind build.sh - the menu that is used - by two entries,
which is the drift this pairing collects:
* Dev server: CUSTOM PORT + SUBDOMAIN, asking for the port and the ROOT_URL
host, with build.sh's rule for what is local and what is proxied;
* Tests: Install Playwright browsers, natively with system dependencies (the
Docker fallback build.sh uses for WebKit on Linux arm64 has no place here).
Both .bat menus renumber and dispatch the new entries.
tests/buildScriptParity.test.cjs keeps the two together: it fails if either
script stops rebuilding before the tests, if a build.sh menu entry has no
counterpart in build.bat, if a Docker compose file one can start and the other
cannot, if a .bat menu prints numbers it does not dispatch, or if a goto lands on
no label.
Thanks to xet7 !
127 lines
6.2 KiB
JavaScript
127 lines
6.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('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`);
|