Skip to content
Myr

duration.js

This file

Path

test/return/duration.js

63 lines · 1.9 KiB · JavaScript

Last changed by

TweaksSindre Sorhusbefore adoption698a1b8

History of this file

Take it

The walk stopped after 200 commits: lines older than 9f65b86 point at it.

TweaksSindre Sorhusbefore adoption698a1b8

lines 1–3why, one step back
1import 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 back
4import {execa, execaSync} from '../../index.js';
5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6import {getEarlyErrorSubprocess, getEarlyErrorSubprocessSync} from '../helpers/early-error.js';78setFixtureDirectory();9

TweaksSindre Sorhusbefore adoption698a1b8

lines 10–14why, one step back
10const 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 back
15};
16

TweaksSindre Sorhusbefore adoption698a1b8

line 17why, one step back
17test('result.durationMs', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 18why, one step back
18 const {durationMs} = await execa('empty.js');

TweaksSindre Sorhusbefore adoption698a1b8

line 19why, one step back
19 assertDurationMs(durationMs);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 20–21why, one step back
20});
21

TweaksSindre Sorhusbefore adoption698a1b8

line 22why, one step back
22test('result.durationMs - sync', () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 23why, one step back
23 const {durationMs} = execaSync('empty.js');

TweaksSindre Sorhusbefore adoption698a1b8

line 24why, one step back
24 assertDurationMs(durationMs);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 25–26why, one step back
25});
26

TweaksSindre Sorhusbefore adoption698a1b8

lines 27–29why, one step back
27test('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 back
30});
31

TweaksSindre Sorhusbefore adoption698a1b8

lines 32–33why, one step back
32test('error.durationMs - sync', () => {
33 const {durationMs} = assertThrows(() => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 34–35why, one step back
34 execaSync('fail.js');
35 });

TweaksSindre Sorhusbefore adoption698a1b8

line 36why, one step back
36 assertDurationMs(durationMs);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 37–38why, one step back
37});
38

TweaksSindre Sorhusbefore adoption698a1b8

lines 39–41why, one step back
39test('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 back
42});
43

TweaksSindre Sorhusbefore adoption698a1b8

lines 44–46why, one step back
44test('error.durationMs - early validation, sync', () => {
45 const {durationMs} = assertThrows(getEarlyErrorSubprocessSync);46 assertDurationMs(durationMs);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 47–48why, one step back
47});
48

TweaksSindre Sorhusbefore adoption698a1b8

lines 49–51why, one step back
49test('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 back
52});
53

TweaksSindre Sorhusbefore adoption698a1b8

lines 54–56why, one step back
54test('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 back
57});
58

TweaksSindre Sorhusbefore adoption698a1b8

line 59why, one step back
59test('result.durationMs is accurate', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 60–61why, one step back
60 const minDurationMs = 1e3;
61 const {durationMs} = await execa('delay.js', [minDurationMs]);

TweaksSindre Sorhusbefore adoption698a1b8

line 62why, one step back
62 assert.ok(durationMs >= minDurationMs);

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 63why, one step back
63});