Skip to content
Myr

duration.js

This file

Path

test/return/duration.js

61 lines · 1.8 KiB · JavaScript

Last changed by

Refactor tests (#934)ehmickybefore adoption52c4bde

History of this file

Take it

Add `result|error.durationMs` (#896)ehmickybefore adoption7088091

lines 1–3why, one step back
1import test from 'ava';
2import {execa, execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 4why, one step back
4import {getEarlyErrorSubprocess, getEarlyErrorSubprocessSync} from '../helpers/early-error.js';

Add `result|error.durationMs` (#896)ehmickybefore adoption7088091

lines 5–37why, one step back
5
6setFixtureDir();78const assertDurationMs = (t, durationMs) => {9 t.is(typeof durationMs, 'number');10 t.true(Number.isFinite(durationMs));11 t.not(durationMs, 0);12 t.true(durationMs > 0);13};1415test('result.durationMs', async t => {16 const {durationMs} = await execa('empty.js');17 assertDurationMs(t, durationMs);18});1920test('result.durationMs - sync', t => {21 const {durationMs} = execaSync('empty.js');22 assertDurationMs(t, durationMs);23});2425test('error.durationMs', async t => {26 const {durationMs} = await t.throwsAsync(execa('fail.js'));27 assertDurationMs(t, durationMs);28});2930test('error.durationMs - sync', t => {31 const {durationMs} = t.throws(() => {32 execaSync('fail.js');33 });34 assertDurationMs(t, durationMs);35});3637test('error.durationMs - early validation', async t => {

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 38why, one step back
38 const {durationMs} = await t.throwsAsync(getEarlyErrorSubprocess());

Add `result|error.durationMs` (#896)ehmickybefore adoption7088091

lines 39–42why, one step back
39 assertDurationMs(t, durationMs);
40});4142test('error.durationMs - early validation, sync', t => {

Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343

line 43why, one step back
43 const {durationMs} = t.throws(getEarlyErrorSubprocessSync);

Add `result|error.durationMs` (#896)ehmickybefore adoption7088091

lines 44–61why, one step back
44 assertDurationMs(t, durationMs);
45});4647test('error.durationMs - unpipeSignal', async t => {48 const {durationMs} = await t.throwsAsync(execa('noop.js').pipe('stdin.js', {signal: AbortSignal.abort()}));49 assertDurationMs(t, durationMs);50});5152test('error.durationMs - pipe validation', async t => {53 const {durationMs} = await t.throwsAsync(execa('noop.js').pipe(false));54 assertDurationMs(t, durationMs);55});5657test.serial('result.durationMs is accurate', async t => {58 const minDurationMs = 1e3;59 const {durationMs} = await execa('delay.js', [minDurationMs]);60 t.true(durationMs >= minDurationMs);61});