promise.js
This file
Path
test/methods/promise.js
53 lines · 1.8 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 {assertRejects} from '../helpers/assert.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 4–8why, one step back4import {execa} from '../../index.js';5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';67setFixtureDirectory();8TweaksSindre Sorhusbefore adoption698a1b8
line 9why, one step back9test('subprocess properties are enumerable', () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 10why, one step back10 const descriptors = Object.getOwnPropertyDescriptors(execa('noop.js'));TweaksSindre Sorhusbefore adoption698a1b8
line 11why, one step back11 assert.equal(descriptors.nodeChildProcess.enumerable, true);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 12–13why, one step back12});13TweaksSindre Sorhusbefore adoption698a1b8
line 14why, one step back14test('finally function is executed on success', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 15–18why, one step back15 let isCalled = false;16 const {stdout} = await execa('noop.js', ['foo']).finally(() => {17 isCalled = true;18 });TweaksSindre Sorhusbefore adoption698a1b8
lines 19–20why, one step back19 assert.equal(isCalled, true);20 assert.equal(stdout, 'foo');100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 21–22why, one step back21});22TweaksSindre Sorhusbefore adoption698a1b8
line 23why, one step back23test('finally function is executed on failure', async () => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 24why, one step back24 let isError = false;TweaksSindre Sorhusbefore adoption698a1b8
line 25why, one step back25 const {stdout, stderr} = await assertRejects(execa('exit.js', ['2']).finally(() => {100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 26–27why, one step back26 isError = true;27 }));TweaksSindre Sorhusbefore adoption698a1b8
lines 28–30why, one step back28 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 back31});32TweaksSindre Sorhusbefore adoption698a1b8
lines 33–34why, one step back33test('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 back35 throw new Error('called');36 }));TweaksSindre Sorhusbefore adoption698a1b8
line 37why, one step back37 assert.equal(message, 'called');100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 38–39why, one step back38});39TweaksSindre Sorhusbefore adoption698a1b8
lines 40–41why, one step back40test('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 back42 throw new Error('called');43 }));TweaksSindre Sorhusbefore adoption698a1b8
line 44why, one step back44 assert.equal(message, 'called');100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 45–46why, one step back45});46TweaksSindre Sorhusbefore adoption698a1b8
line 47why, one step back47const testNoAwait = async (fixtureName, options, message) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 48why, one step back48 const {stdout} = await execa('no-await.js', [JSON.stringify(options), fixtureName]);TweaksSindre Sorhusbefore adoption698a1b8
line 49why, one step back49 assert.ok(stdout.includes(message));100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 50–51why, one step back50};51TweaksSindre Sorhusbefore adoption698a1b8
lines 52–53why, one step back52test('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'));