// Windows integration check. Leave the intended Explorer tab in the foreground. // node tests/explorer-selection.cjs --expect C:\path\file.txt [--expect ...] // node tests/explorer-selection.cjs --empty const {spawn} = require('node:child_process'); const path = require('node:path'); const fs = require('node:fs'); const assert = require('node:assert/strict'); const root = path.resolve(__dirname, '..'); const args = process.argv.slice(2), expected = []; let helper = path.join(root, 'vendor/windows/FileBow.Windows.exe'), log, empty = false; for (let i = 0; i < args.length; i++) { if (args[i] === '--expect' && args[i+1]) expected.push(path.resolve(args[++i])); else if (args[i] === '--helper' && args[i+1]) helper = path.resolve(args[++i]); else if (args[i] === '--log' && args[i+1]) log = path.resolve(args[++i]); else if (args[i] === '--empty') empty = true; else throw new Error(`Unknown or incomplete argument: ${args[i]}`); } assert.ok(empty !== (expected.length > 0), 'Use --expect paths or --empty, exclusively.'); const child = spawn(helper, [], {windowsHide:true, stdio:['pipe','pipe','pipe']}); const timer = setTimeout(() => { child.kill(); throw new Error('Selection check timed out'); }, 15000); let buffer = '', replied = false; child.stdout.setEncoding('utf8'); child.stderr.pipe(process.stderr); child.on('error', error => { clearTimeout(timer); console.error(error); process.exitCode = 1; }); child.stdout.on('data', chunk => { buffer += chunk; const lines = buffer.split(/\r?\n/); buffer = lines.pop(); for (const line of lines) { const message = JSON.parse(line); if (message.type === 'ready') child.stdin.write(JSON.stringify({id:1,command:'selection'})+'\n'); if (message.id !== 1) continue; replied = true; clearTimeout(timer); child.stdin.end(); const normalized = values => values.map(value => path.resolve(value).toLowerCase()).sort(); const result = {helper, expected, actual:message.result, error:message.error}; try { assert.equal(message.error, undefined); assert.deepEqual(normalized(message.result), normalized(expected)); result.passed = true; } catch (error) { result.passed = false; console.error(error.message); process.exitCode = 1; } if (log) { fs.mkdirSync(path.dirname(log), {recursive:true}); fs.writeFileSync(log, JSON.stringify(result,null,2)); } console.log(JSON.stringify(result)); } }); child.on('exit', () => { clearTimeout(timer); if (!replied) { console.error('Helper exited without a selection result'); process.exitCode=1; } });