test('render div with children', t => { const root = t.context.root; const element = ( <div> <b /> <a href="foo" /> </div> ); render(element, root); t.is(root.innerHTML, '<div><b></b><a href="foo"></a></div>'); });
test('.matches()', t => { t.deepEqual(alfyInstance.matches('Unicorn', ['foo', 'unicorn']), ['unicorn']); t.deepEqual(alfyInstance.matches('Unicorn', [{name: 'foo'}, {name: 'unicorn'}], 'name'), [{name: 'unicorn'}]); t.deepEqual(alfyInstance.matches('Foobar', [{name: 'foo', sub: 'bar'}, {name: 'unicorn', sub: 'rainbow'}], (item, input) => item.name + item.sub === input), [{name: 'foo', sub: 'bar'}]); });
test('`forceKillAfterTimeout: false` should not kill after a timeout', async t => { const subprocess = execa('node', ['./test/fixtures/no-killable'], {stdio: ['ipc']}); await pEvent(subprocess, 'message'); subprocess.kill('SIGTERM', {forceKillAfterTimeout: false}); t.true(isRunning(subprocess.pid)); subprocess.kill('SIGKILL'); });
test('cache key', async t => { const alfy = createAlfy(); t.deepEqual(await alfy.fetch(`${URL}/cache-key`, {query: {unicorn: 'rainbow'}, maxAge: 5000}), {unicorn: 'rainbow'}); t.truthy(alfy.cache.store['https://foo.bar/cache-key{"json":true,"query":{"unicorn":"rainbow"},"maxAge":5000}']); });
test('stdout/stderr/all available on errors', async t => { const {stdout, stderr, all} = await t.throwsAsync(execa('exit', ['2'], {all: true}), {message: getExitRegExp('2')}); t.is(typeof stdout, 'string'); t.is(typeof stderr, 'string'); t.is(typeof all, 'string'); });
test('calling cancel method twice should show the same behaviour as calling it once', async t => { const subprocess = execa('noop'); subprocess.cancel(); subprocess.cancel(); const {isCanceled} = await t.throwsAsync(subprocess); t.true(isCanceled); t.true(subprocess.killed); });
test('error.killed is false if process was killed indirectly', async t => { const subprocess = execa('noop'); process.kill(subprocess.pid, 'SIGINT'); // `process.kill()` is emulated by Node.js on Windows const message = process.platform === 'win32' ? /failed with exit code 1/ : /was killed with SIGINT/; const {killed} = await t.throwsAsync(subprocess, {message}); t.false(killed); });
test('timeout kills the process if it times out, in sync mode', async t => { const {killed, timedOut} = await t.throws(() => { execa.sync('noop', {timeout: 1, message: TIMEOUT_REGEXP}); }); t.false(killed); t.true(timedOut); });
test('render jsx div', t => { const root = t.context.root; const element = <div>Foo</div>; render(element, root); t.is(root.innerHTML, '<div>Foo</div>'); render(element, root); t.is(root.innerHTML, '<div>Foo</div>'); });
test('node pass on nodeOptions', async t => { const {stdout} = await execa.node('console.log("foo")', { stdout: 'pipe', nodeOptions: ['-e'] }); t.is(stdout, 'foo'); });
test('pass `stdout` to a file descriptor', async t => { const file = tempfile('.txt'); await execa('test/fixtures/noop', ['foo bar'], {stdout: fs.openSync(file, 'w')}); t.is(fs.readFileSync(file, 'utf8'), 'foo bar\n'); });
test('throw in finally function bubbles up on success', async t => { const {message} = await t.throwsAsync(execa('noop', ['foo']).finally(() => { throw new Error('called'); })); t.is(message, 'called'); });
test('buffer', async t => { const {stdout} = await execa('noop', ['foo'], {encoding: null}); t.true(Buffer.isBuffer(stdout)); t.is(stdout.toString(), 'foo'); });
test('timeout must be an integer', async t => { await t.throws(() => { execa('noop', {timeout: false}); }, INVALID_TIMEOUT_REGEXP); });
test('exitCode is undefined on signal termination', async t => { const subprocess = execa('noop'); process.kill(subprocess.pid); const {exitCode} = await t.throwsAsync(subprocess); t.is(exitCode, undefined); });