'use strict'; // Source guards for the two build.sh helpers that have no other coverage: // the dev-server URL prompt (custom port + ROOT_URL host) and the inotify watch // limit check. Both are plain shell, so these assert the wiring; the behaviour of // each was exercised by sourcing the function against fake input. // // Run: node tests/buildDevServer.test.cjs const assert = require('assert'); const fs = require('fs'); const path = require('path'); const sh = fs.readFileSync(path.join(__dirname, '..', 'build.sh'), 'utf8'); let passed = 0; function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); } console.log('buildDevServer:'); test('development logging defaults to quiet and preserves an explicit DEBUG setting', () => { const { execFileSync } = require('child_process'); const assignments = sh.match(/DDP_TRANSPORT=sockjs (DEBUG="[^"]+")/g); assert.strictEqual(assignments.length, 7); for (const assignment of assignments) { for (const value of [undefined, 'true', 'false']) { const env = { ...process.env }; delete env.DEBUG; if (value !== undefined) env.DEBUG = value; const actual = execFileSync('sh', ['-c', `${assignment} sh -c 'printf %s "$DEBUG"'`], { env, encoding: 'utf8' }); assert.strictEqual(actual, value || 'false'); } } const bat = fs.readFileSync(path.join(__dirname, '..', 'build.bat'), 'utf8'); assert.ok(bat.includes('if not defined DEBUG set "DEBUG=false"')); assert.ok(!bat.includes('set "DEBUG=true"')); }); test('the Dev server menu offers a custom port + ROOT_URL host', () => { assert.ok(sh.includes('CUSTOM PORT + SUBDOMAIN|Run Meteor for dev on a custom port and ROOT_URL host (asks)'), 'menu entry is missing'); assert.ok(sh.includes('"Run Meteor for dev on a custom port and ROOT_URL host (asks)")'), 'no case handler matches the menu entry'); }); test('both dev handlers use the selected command and the answered port', () => { const start = sh.indexOf('"Run Meteor for dev on a custom port and ROOT_URL host (asks)")'); const body = sh.slice(start, sh.indexOf('\n\t\t;;', start)); // The shared menu now selects Meteor or the source loader before dispatch; // both must still receive the same URL and port answers. assert.ok(sh.includes('DEV_COMMAND=(meteor run)')); assert.ok(sh.includes('DEV_COMMAND=(node "$WEKAN_DIR/scripts/dev-source/start.cjs")')); assert.ok(/ask_dev_url/.test(body), 'the handler asks for the port/host'); assert.ok(/ROOT_URL="\$DEV_ROOT_URL"/.test(body), 'ROOT_URL comes from the answer'); assert.ok(body.includes('"${DEV_COMMAND[@]}" --port "$DEV_PORT"'), 'the port comes from the answer'); assert.ok(/kill_meteor_on_port "\$DEV_PORT"/.test(body), 'the chosen port is freed first, like the other dev options'); // Comments may mention it; no COMMAND in the handler may pin it. const commands = body.split('\n').filter(l => !/^\s*#/.test(l)).join('\n'); assert.ok(!/localhost:3000/.test(commands), 'the handler must not pin localhost:3000'); }); // The port Meteor LISTENS on and the URL a BROWSER uses are different things // behind a reverse proxy: Caddy serves https://wekan.example.com on 443 and // forwards to localhost:PORT, so appending the local port to that ROOT_URL would // produce https://wekan.example.com:4000, which nothing serves. test('a full URL answer is used verbatim - no port appended (the reported bug)', () => { assert.ok(/\*:\/\/\*\)\s*\n(?:\s*#[^\n]*\n)*\s*url="\$answer" ;;/.test(sh), 'an answer containing a scheme must be used exactly as given'); }); test('a dotted host with no scheme is treated as public, not local', () => { assert.ok(/\*\.\*\)\s*\n(?:\s*#[^\n]*\n)*\s*url="https:\/\/\$answer" ;;/.test(sh), 'a public name gets https:// and NO local port'); }); test('only a local answer gets the port appended', () => { assert.ok(/url="http:\/\/localhost:\$port" ;;/.test(sh), 'empty answer -> localhost:PORT'); assert.ok(/url="http:\/\/\$answer\.localhost:\$port" ;;/.test(sh), 'a bare label ->