-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathhelp-test.js
214 lines (154 loc) · 5.9 KB
/
help-test.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
'use strict';
const fs = require('fs');
const path = require('path');
const chai = require('chai');
let expect = chai.expect;
const EOL = require('os').EOL;
const processHelpString = require('../helpers/process-help-string');
const convertToJson = require('../helpers/convert-help-output-to-json');
const commandOptions = require('../factories/command-options');
const HelpCommand = require('../../lib/commands/help');
const requireAsHash = require('../../lib/utilities/require-as-hash');
const Command = require('../../lib/models/command');
let FooCommand = Command.extend({
name: 'foo',
description: 'Initializes the warp drive.',
works: 'insideProject',
availableOptions: [{ name: 'dry-run', type: Boolean, default: false, aliases: ['d'] }],
anonymousOptions: ['<speed>'],
});
describe('Acceptance: ember help', function () {
let options, command;
beforeEach(function () {
let commands = requireAsHash('../../lib/commands/*.js', Command);
options = commandOptions({
commands,
project: {
isEmberCLIProject() {
return true;
},
blueprintLookupPaths() {
return [];
},
},
});
command = new HelpCommand(options);
});
it('works', function () {
command.run(options, []);
let output = options.ui.output;
let fixturePath = path.join(__dirname, '..', 'fixtures', 'help', 'help.txt');
// makes updating this fixture much much easier...
if (process.env.WRITE_HELP_FIXTURES) {
fs.writeFileSync(fixturePath, output, { encoding: 'utf-8' });
}
let expected = loadTextFixture(fixturePath);
expect(output).to.equal(expected);
});
it('prints addon commands', function () {
options.project.eachAddonCommand = function (cb) {
cb('dummy-addon', { Foo: FooCommand });
};
command.run(options, []);
let output = options.ui.output;
let fixturePath = path.join(__dirname, '..', 'fixtures', 'help', 'help-with-addon.txt');
// makes updating this fixture much much easier...
if (process.env.WRITE_HELP_FIXTURES) {
fs.writeFileSync(fixturePath, output, { encoding: 'utf-8' });
}
let expected = loadTextFixture(fixturePath);
expect(output).to.equal(expected);
});
it('prints single addon commands', function () {
options.project.eachAddonCommand = function (cb) {
cb('dummy-addon', { Foo: FooCommand });
};
command.run(options, ['foo']);
let output = options.ui.output;
let fixturePath = path.join(__dirname, '..', 'fixtures', 'help', 'foo.txt');
let expected = loadTextFixture(fixturePath);
expect(output).to.equal(expected);
});
it('prints all blueprints', function () {
command.run(options, ['generate']);
let output = options.ui.output;
let fixturePath = path.join(__dirname, '..', 'fixtures', 'help', 'generate.txt');
// makes updating this fixture much much easier...
if (process.env.WRITE_HELP_FIXTURES) {
fs.writeFileSync(fixturePath, output, { encoding: 'utf-8' });
}
let expected = loadTextFixture(fixturePath);
expect(output).to.contain(expected);
});
it('prints helpful message for unknown command', function () {
command.run(options, ['asdf']);
let output = options.ui.output;
expect(output).to.contain("No help entry for 'asdf'");
expect(output).to.not.contain('undefined');
});
it('prints a single blueprints', function () {
command.run(options, ['generate', 'blueprint']);
let output = options.ui.output;
let fixturePath = path.join(__dirname, '..', 'fixtures', 'help', 'generate-blueprint.txt');
// makes updating this fixture much much easier...
if (process.env.WRITE_HELP_FIXTURES) {
fs.writeFileSync(fixturePath, output, { encoding: 'utf-8' });
}
let expected = loadTextFixture(fixturePath);
expect(output).to.equal(expected);
});
it('prints blueprints from addons', function () {
options.project.blueprintLookupPaths = function () {
return [path.join(__dirname, '..', 'fixtures', 'blueprints')];
};
command.run(options, ['generate']);
let output = options.ui.output;
let fixturePath = path.join(__dirname, '..', 'fixtures', 'help', 'generate-with-addon.txt');
// makes updating this fixture much much easier...
if (process.env.WRITE_HELP_FIXTURES) {
fs.writeFileSync(fixturePath, output, { encoding: 'utf-8' });
}
let expected = loadTextFixture(fixturePath);
expect(output).to.equal(expected);
});
describe('--json', function () {
beforeEach(function () {
options.json = true;
});
it('works', function () {
command.run(options, []);
let json = convertToJson(options.ui.output);
const expected = require('../fixtures/help/help.js');
expect(json).to.deep.equal(expected);
});
it('prints commands from addons', function () {
options.project.eachAddonCommand = function (cb) {
cb('dummy-addon', { Foo: FooCommand });
};
command.run(options, []);
let json = convertToJson(options.ui.output);
const expected = require('../fixtures/help/with-addon-commands.js');
expect(json).to.deep.equal(expected);
});
it('prints blueprints from addons', function () {
options.project.blueprintLookupPaths = function () {
return [path.join(__dirname, '..', 'fixtures', 'blueprints')];
};
command.run(options, []);
let json = convertToJson(options.ui.output);
const expected = require('../fixtures/help/with-addon-blueprints.js');
expect(json).to.deep.equal(expected);
});
});
});
function loadTextFixture(path) {
let content = fs.readFileSync(path, { encoding: 'utf8' });
let decoded = decodeUnicode(content);
let processed = processHelpString(decoded);
return processed.replace(/\n/g, EOL);
}
function decodeUnicode(str) {
return str.replace(/\\u([\d\w]{4})/gi, function (match, grp) {
return String.fromCharCode(parseInt(grp, 16));
});
}