-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshjs.js
More file actions
72 lines (59 loc) · 1.7 KB
/
shjs.js
File metadata and controls
72 lines (59 loc) · 1.7 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const path = require('path');
const test = require('ava');
const shell = require('shelljs');
const binPath = path.resolve(__dirname, '../bin/shjs');
function runWithShjs(name) {
// prefix with 'node ' for Windows, don't prefix for unix
const execPath = process.platform === 'win32'
? `${JSON.stringify(shell.config.execPath)} `
: '';
const script = path.resolve(__dirname, 'resources', 'shjs', name);
return shell.exec(`${execPath}${binPath} ${script}`, { silent: true });
}
//
// Valids
//
test('Non-zero exit code', t => {
const result = runWithShjs('exit-codes.js');
t.is(result.code, 42);
t.is(result.stdout, '');
t.falsy(result.stderr);
});
test('Zero exit code', t => {
const result = runWithShjs('exit-0.js');
t.is(result.code, 0);
t.is(result.stdout, '');
t.falsy(result.stderr);
});
test('Stdout/Stderr', t => {
const result = runWithShjs('stdout-stderr.js');
t.is(result.code, 0);
t.is(result.stdout, 'stdout: OK!\n');
t.is(result.stderr, 'stderr: OK!\n');
});
test('CoffeeScript', t => {
const result = runWithShjs('coffeescript.coffee');
t.is(result.code, 0);
t.is(result.stdout, 'CoffeeScript: OK!\n');
t.falsy(result.stderr);
});
test('JS extension inference', t => {
const result = runWithShjs('a-file');
t.is(result.code, 0);
t.is(result.stdout, 'OK!\n');
t.falsy(result.stderr);
});
test('CoffeeScript extension inference', t => {
const result = runWithShjs('coffeescript');
t.is(result.code, 0);
t.is(result.stdout, 'CoffeeScript: OK!\n');
t.falsy(result.stderr);
});
//
// Invalids
//
test('disallow require-ing', t => {
t.throws(() => require(binPath),
{ instanceOf: Error },
'Executable-only module should not be required');
});