-
-
Notifications
You must be signed in to change notification settings - Fork 405
/
Copy pathcli.js
92 lines (77 loc) · 2.4 KB
/
cli.js
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
'use strict';
const path = require('path');
const assert = require('assert');
const {execFile} = require('child_process');
const mockery = require('mockery');
const sinon = require('sinon');
const pkg = require('../package.json');
describe('bin', () => {
describe('mocked', () => {
beforeEach(async function () {
this.origArgv = process.argv;
this.origExit = process.exit;
// eslint-disable-next-line node/no-unsupported-features/es-syntax
const {createEnv} = await import('yeoman-environment');
this.env = createEnv();
mockery.enable({
warnOnUnregistered: false
});
mockery.registerMock('yeoman-environment', {
createEnv: () => this.env
});
});
afterEach(function () {
mockery.disable();
process.argv = this.origArgv;
process.exit = this.origExit;
});
it('should exit with status 1 if there were errors', function (done) {
let called = false;
process.exit = arg => {
if (called) {
// Exit can be called more than once
return;
}
called = true;
assert(arg, 1, 'exit code should be 1');
done();
};
process.argv = ['node', path.resolve(__dirname, '..', pkg.bin.yo), 'non-existent'];
sinon.stub(this.env, 'lookup');
require('../lib/cli'); // eslint-disable-line import/no-unassigned-import
});
});
it('should return the version', cb => {
const cp = execFile('node', [
path.resolve(__dirname, '..', pkg.bin.yo),
'--version',
'--no-update-notifier'
]);
const expected = pkg.version;
cp.stdout.on('data', data => {
assert.strictEqual(data.toString().replace(/\r\n|\n/g, ''), expected);
cb();
});
});
it('should output available generators when `--generators` flag is supplied', cb => {
const cp = execFile('node', [path.resolve(__dirname, '..', pkg.bin.yo), '--generators', '--no-update-notifier']);
cp.stdout.once('data', data => {
assert(data.length > 0);
assert(!/\[/.test(data));
cb();
});
});
it('should support the `--local-only` flag', cb => {
const cp = execFile('node', [
path.resolve(__dirname, '..', pkg.bin.yo),
'--generators',
'--local-only',
'--no-update-notifier'
]);
cp.stdout.once('data', data => {
assert(data.length > 0);
assert(!/\[/.test(data));
cb();
});
});
});