async function runWmr(cwd, ...args) {
	let opts = {};
	const lastArg = args[args.length - 1];
	if (lastArg && typeof lastArg === 'object') {
		opts = args.pop() || opts;
	}
	// Allow running tests against the fully built/bundled version of WMR:
	if (process.env.PRODUCTION_BUILD === 'true') {
		const bin = path.join(__dirname, '..', 'wmr.cjs');
		args.unshift(bin);
	} else {
		// run tests against the original Node ESM source by default:
		const bin = path.join(__dirname, '..', 'src', 'cli.js');
		args.unshift('--experimental-modules', bin);
	}
	const child = childProcess.spawn('node', args, {
		cwd,
		...opts,
		env: {
			...process.env,
			DEBUG: 'true',
			PORT: '0',
			...(opts.env || {})
		}
	});

	const out = {};
	out.output = [];
	out.code = 0;
	out.close = () => child.kill();

	function onOutput(buffer) {
		const raw = stripColors(buffer.toString('utf-8'));
		const lines = raw.split('\n').filter(line => !/\(node:\d+\) ExperimentalWarning:/.test(line) && line);
		out.output.push(...lines);
		// Bubble up errors, but not 404's
		if (/\b([A-Z][a-z]+)?Error\b/m.test(raw) && !/^404 /.test(raw)) {
			console.error(`Error running "wmr ${args.join(' ')}":\n${raw}`);
		}
		if (/server running at/m.test(raw)) {
			let m = raw.match(/https?:\/\/localhost:\d+/g);
			if (m) setAddress(m[0]);
		}
	}
	child.stdout.on('data', onOutput);
	child.stderr.on('data', onOutput);
	out.done = new Promise(resolve => {
		child.on('close', code => resolve((out.code = code)));
	});

	let setAddress;
	out.address = new Promise(resolve => (setAddress = resolve));

	await waitFor(() => out.output.length > 0, 10000);

	return out;
}
@param {string} cwd
@param {[...string[], string | Record<string, any>]} args
@returns {Promise<WmrInstance>}