duration.js
This file
Path
test/return/duration.js
63 lines · 1.9 KiB · JavaScript
Last changed by
TweaksSindre Sorhusbefore adoption698a1b8
History of this fileTake it
The walk stopped after 200 commits: lines older than 9f65b86 point at it.
TweaksSindre Sorhusbefore adoption698a1b8
lines 1–3why, one step back1import assert from 'node:assert/strict';2import test from 'node:test';3import {assertThrows, assertRejects} from '../helpers/assert.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 4–9why, one step back4import {execa, execaSync} from '../../index.js';5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6import {getEarlyErrorSubprocess, getEarlyErrorSubprocessSync} from '../helpers/early-error.js';78setFixtureDirectory();9TweaksSindre Sorhusbefore adoption698a1b8
lines 10–14why, one step back10const assertDurationMs = durationMs => {11 assert.equal(typeof durationMs, 'number');12 assert.ok(Number.isFinite(durationMs));13 assert.notEqual(durationMs, 0);14 assert.ok(durationMs > 0);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 15–16why, one step back15};16TweaksSindre Sorhusbefore adoption698a1b8
line 17why, one step back17test('result.durationMs', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 18why, one step back18 const {durationMs} = await execa('empty.js');TweaksSindre Sorhusbefore adoption698a1b8
line 19why, one step back19 assertDurationMs(durationMs);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 20–21why, one step back20});21TweaksSindre Sorhusbefore adoption698a1b8
line 22why, one step back22test('result.durationMs - sync', () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 23why, one step back23 const {durationMs} = execaSync('empty.js');TweaksSindre Sorhusbefore adoption698a1b8
line 24why, one step back24 assertDurationMs(durationMs);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 25–26why, one step back25});26TweaksSindre Sorhusbefore adoption698a1b8
lines 27–29why, one step back27test('error.durationMs', async () => {28 const {durationMs} = await assertRejects(execa('fail.js'));29 assertDurationMs(durationMs);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 30–31why, one step back30});31TweaksSindre Sorhusbefore adoption698a1b8
lines 32–33why, one step back32test('error.durationMs - sync', () => {33 const {durationMs} = assertThrows(() => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 34–35why, one step back34 execaSync('fail.js');35 });TweaksSindre Sorhusbefore adoption698a1b8
line 36why, one step back36 assertDurationMs(durationMs);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 37–38why, one step back37});38TweaksSindre Sorhusbefore adoption698a1b8
lines 39–41why, one step back39test('error.durationMs - early validation', async () => {40 const {durationMs} = await assertRejects(getEarlyErrorSubprocess());41 assertDurationMs(durationMs);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 42–43why, one step back42});43TweaksSindre Sorhusbefore adoption698a1b8
lines 44–46why, one step back44test('error.durationMs - early validation, sync', () => {45 const {durationMs} = assertThrows(getEarlyErrorSubprocessSync);46 assertDurationMs(durationMs);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 47–48why, one step back47});48TweaksSindre Sorhusbefore adoption698a1b8
lines 49–51why, one step back49test('error.durationMs - unpipeSignal', async () => {50 const {durationMs} = await assertRejects(execa('noop.js').pipe('stdin.js', {signal: AbortSignal.abort()}));51 assertDurationMs(durationMs);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 52–53why, one step back52});53TweaksSindre Sorhusbefore adoption698a1b8
lines 54–56why, one step back54test('error.durationMs - pipe validation', async () => {55 const {durationMs} = await assertRejects(execa('noop.js').pipe(false));56 assertDurationMs(durationMs);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 57–58why, one step back57});58TweaksSindre Sorhusbefore adoption698a1b8
line 59why, one step back59test('result.durationMs is accurate', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 60–61why, one step back60 const minDurationMs = 1e3;61 const {durationMs} = await execa('delay.js', [minDurationMs]);TweaksSindre Sorhusbefore adoption698a1b8
line 62why, one step back62 assert.ok(durationMs >= minDurationMs);100% test coverage (#1018)ehmickybefore adoption9f65b86
line 63why, one step back63});