Skip to content

Commit 17106ec

Browse files
committed
test: refactor shjs tests to AVA
1 parent 1548b3d commit 17106ec

2 files changed

Lines changed: 54 additions & 30 deletions

File tree

‎ava-test/shjs.js‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import path from 'path';
2+
3+
import test from 'ava';
4+
5+
import shell from '..';
6+
7+
function runWithShjs(name) {
8+
// prefix with 'node ' for Windows, don't prefix for unix
9+
const binPath = path.resolve(__dirname, '../bin/shjs');
10+
const execPath = process.platform === 'win32'
11+
? `${JSON.stringify(process.execPath)} `
12+
: '';
13+
const script = path.resolve(__dirname, 'resources', 'shjs', name);
14+
return shell.exec(`${execPath}${binPath} ${script}`, { silent: true });
15+
}
16+
17+
//
18+
// Valids
19+
//
20+
21+
test('Non-zero exit code', t => {
22+
const result = runWithShjs('exit-codes.js');
23+
t.is(result.code, 42);
24+
t.is(result.stdout, '');
25+
t.falsy(result.stderr);
26+
});
27+
28+
test('Zero exit code', t => {
29+
const result = runWithShjs('exit-0.js');
30+
t.is(result.code, 0);
31+
t.is(result.stdout, '');
32+
t.falsy(result.stderr);
33+
});
34+
35+
test('Stdout/Stderr', t => {
36+
const result = runWithShjs('stdout-stderr.js');
37+
t.is(result.code, 0);
38+
t.is(result.stdout, 'stdout: OK!\n');
39+
t.is(result.stderr, 'stderr: OK!\n');
40+
});
41+
42+
test('CoffeeScript', t => {
43+
const result = runWithShjs('coffeescript.coffee');
44+
t.is(result.code, 0);
45+
t.is(result.stdout, 'CoffeeScript: OK!\n');
46+
t.falsy(result.stderr);
47+
});
48+
49+
test('Extension detection', t => {
50+
const result = runWithShjs('a-file');
51+
t.is(result.code, 0);
52+
t.is(result.stdout, 'OK!\n');
53+
t.falsy(result.stderr);
54+
});

‎test/shjs.js‎

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)