Skip to content
Myr

errname.js

This file

Path

test/errname.js

27 lines · 723 bytes · JavaScript

Last changed by

[BREAKING] ES2015ify and require Node.js 4Sindre Sorhusbefore adoption8a7a51c

History of this file

Take it

reimplement errname lookup. (#38)James Talmagebefore adoptiona1d1764

lines 1–5why, one step back
1import test from 'ava';
2import errname from '../lib/errname';34const isWin = process.platform === 'win32';5

[BREAKING] ES2015ify and require Node.js 4Sindre Sorhusbefore adoption8a7a51c

lines 6–7why, one step back
6// simulates failure to capture `process.binding('uv');`
7const fallback = code => errname.__test__(null, code);

reimplement errname lookup. (#38)James Talmagebefore adoptiona1d1764

lines 8–17why, one step back
8
9function makeTests(name, m, expected) {10 test(`${name}: >=0 exit codes`, t => {11 // throws >= 012 t.throws(() => m(0), /err >= 0/);13 t.throws(() => m(1), /err >= 0/);14 t.throws(() => m('2'), /err >= 0/);15 t.throws(() => m('foo'), /err >= 0/);16 });17

[BREAKING] ES2015ify and require Node.js 4Sindre Sorhusbefore adoption8a7a51c

lines 18–21why, one step back
18 test(`${name}: negative exit codes`, t => {
19 t.is(m(-2), expected);20 t.is(m('-2'), expected);21 });

reimplement errname lookup. (#38)James Talmagebefore adoptiona1d1764

lines 22–27why, one step back
22}
2324const unknown = 'Unknown system error -2';2526makeTests('native', errname, isWin ? unknown : 'ENOENT');27makeTests('fallback', fallback, unknown);