-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
100 lines (84 loc) · 3.14 KB
/
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
'use strict';
require('mocha');
var assert = require('assert');
var Base = require('base');
var extend = require('extend-shallow');
var askWhen = require('ask-when');
var hints = require('./lib/hints');
var questions = require('./');
var pkg = require('./package');
var app;
describe('common-questions', function() {
beforeEach(function() {
app = new Base({isApp: true});
app.use(questions());
app.use(askWhen());
});
describe('plugin', function() {
it('should export a function', function() {
assert.equal(typeof questions, 'function');
});
it('should work as a plugin', function(cb) {
var opts = {name: 'foo', askWhen: 'not-answered'};
app.askWhen('name', opts, function(err, answers) {
if (err) return cb(err);
assert.equal(answers.name, 'foo');
assert(app.questions.cache.hasOwnProperty('project.name'));
assert(app.questions.cache.hasOwnProperty('project.alias'));
assert(app.questions.cache.hasOwnProperty('project.owner'));
assert(app.questions.cache.hasOwnProperty('project.description'));
assert(app.questions.cache.hasOwnProperty('author.name'));
assert(app.questions.cache.hasOwnProperty('author.url'));
cb();
});
});
});
describe('hints', function() {
it('should add a hint to the `name` question', function() {
var question = app.questions.get('name');
assert.equal(question.default, pkg.name);
});
it('should add a hint to the `alias` question', function() {
var question = app.questions.get('alias');
assert.equal(question.default, 'commonQuestions');
});
it('should add a hint to the `owner` question', function() {
var question = app.questions.get('owner');
assert.equal(question.default, 'generate');
});
it('should add a hint to the `owner` question, using app.cache.data', function() {
app.registered = {};
app.set('cache.data.owner', 'foo');
app.use(questions());
var question = app.questions.get('owner');
assert.equal(question.default, 'foo');
});
it('should add a hint to the `description` question', function() {
var question = app.questions.get('description');
assert.equal(question.default, pkg.description);
});
it('should add a hint to the `version` question', function() {
var question = app.questions.get('version');
assert.equal(question.default, pkg.version);
});
it('should add a hint to the `license` question', function() {
var question = app.questions.get('license');
assert.equal(question.default, 'MIT');
});
it('should add a hint for author.name', function() {
if (process.env.CI) {
this.skip();
return;
}
var question = app.questions.get('author.name');
assert.equal(question.default, 'Jon Schlinkert');
});
it('should get author.name from app.cache.data', function() {
app.registered = {};
app.set('cache.data.author.name', 'Brian Woodward');
app.use(questions());
var question = app.questions.get('author.name');
assert.equal(question.default, 'Brian Woodward');
});
});
});