File: promise.js

package info (click to toggle)
node-execa 8.0.1%2Bdfsg1%2B~cs12.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,588 kB
  • sloc: javascript: 2,940; makefile: 11; sh: 1
file content (45 lines) | stat: -rw-r--r-- 1,310 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import test from 'ava';
import {execa} from '../index.js';
import {setFixtureDir} from './helpers/fixtures-dir.js';

setFixtureDir();

test('promise methods are not enumerable', t => {
	const descriptors = Object.getOwnPropertyDescriptors(execa('noop.js'));
	t.false(descriptors.then.enumerable);
	t.false(descriptors.catch.enumerable);
	t.false(descriptors.finally.enumerable);
});

test('finally function is executed on success', async t => {
	let isCalled = false;
	const {stdout} = await execa('noop.js', ['foo']).finally(() => {
		isCalled = true;
	});
	t.is(isCalled, true);
	t.is(stdout, 'foo');
});

test('finally function is executed on failure', async t => {
	let isError = false;
	const {stdout, stderr} = await t.throwsAsync(execa('exit.js', ['2']).finally(() => {
		isError = true;
	}));
	t.is(isError, true);
	t.is(typeof stdout, 'string');
	t.is(typeof stderr, 'string');
});

test('throw in finally function bubbles up on success', async t => {
	const {message} = await t.throwsAsync(execa('noop.js', ['foo']).finally(() => {
		throw new Error('called');
	}));
	t.is(message, 'called');
});

test('throw in finally bubbles up on error', async t => {
	const {message} = await t.throwsAsync(execa('exit.js', ['2']).finally(() => {
		throw new Error('called');
	}));
	t.is(message, 'called');
});