Skip to content
Myr

promise.js

This file

Path

test/methods/promise.js

53 lines · 1.8 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 {assertRejects} from '../helpers/assert.js';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 4–8why, one step back
4import {execa} from '../../index.js';
5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';67setFixtureDirectory();8

TweaksSindre Sorhusbefore adoption698a1b8

line 9why, one step back
9test('subprocess properties are enumerable', () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 10why, one step back
10 const descriptors = Object.getOwnPropertyDescriptors(execa('noop.js'));

TweaksSindre Sorhusbefore adoption698a1b8

line 11why, one step back
11 assert.equal(descriptors.nodeChildProcess.enumerable, true);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 12–13why, one step back
12});
13

TweaksSindre Sorhusbefore adoption698a1b8

line 14why, one step back
14test('finally function is executed on success', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 15–18why, one step back
15 let isCalled = false;
16 const {stdout} = await execa('noop.js', ['foo']).finally(() => {17 isCalled = true;18 });

TweaksSindre Sorhusbefore adoption698a1b8

lines 19–20why, one step back
19 assert.equal(isCalled, true);
20 assert.equal(stdout, 'foo');

100% test coverage (#1018)ehmickybefore adoption9f65b86

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

TweaksSindre Sorhusbefore adoption698a1b8

line 23why, one step back
23test('finally function is executed on failure', async () => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 24why, one step back
24 let isError = false;

TweaksSindre Sorhusbefore adoption698a1b8

line 25why, one step back
25 const {stdout, stderr} = await assertRejects(execa('exit.js', ['2']).finally(() => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 26–27why, one step back
26 isError = true;
27 }));

TweaksSindre Sorhusbefore adoption698a1b8

lines 28–30why, one step back
28 assert.equal(isError, true);
29 assert.equal(typeof stdout, 'string');30 assert.equal(typeof stderr, 'string');

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 31–32why, one step back
31});
32

TweaksSindre Sorhusbefore adoption698a1b8

lines 33–34why, one step back
33test('throw in finally function bubbles up on success', async () => {
34 const {message} = await assertRejects(execa('noop.js', ['foo']).finally(() => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 35–36why, one step back
35 throw new Error('called');
36 }));

TweaksSindre Sorhusbefore adoption698a1b8

line 37why, one step back
37 assert.equal(message, 'called');

100% test coverage (#1018)ehmickybefore adoption9f65b86

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

TweaksSindre Sorhusbefore adoption698a1b8

lines 40–41why, one step back
40test('throw in finally bubbles up on error', async () => {
41 const {message} = await assertRejects(execa('exit.js', ['2']).finally(() => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 42–43why, one step back
42 throw new Error('called');
43 }));

TweaksSindre Sorhusbefore adoption698a1b8

line 44why, one step back
44 assert.equal(message, 'called');

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 45–46why, one step back
45});
46

TweaksSindre Sorhusbefore adoption698a1b8

line 47why, one step back
47const testNoAwait = async (fixtureName, options, message) => {

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 48why, one step back
48 const {stdout} = await execa('no-await.js', [JSON.stringify(options), fixtureName]);

TweaksSindre Sorhusbefore adoption698a1b8

line 49why, one step back
49 assert.ok(stdout.includes(message));

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 50–51why, one step back
50};
51

TweaksSindre Sorhusbefore adoption698a1b8

lines 52–53why, one step back
52test('Throws if promise is not awaited and subprocess fails', () => testNoAwait('fail.js', {}, 'exit code 2'));
53test('Throws if promise is not awaited and subprocess times out', () => testNoAwait('forever.js', {timeout: 1}, 'timed out'));