This repository was archived by the owner on Mar 26, 2018. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathtest-prompt.js
119 lines (100 loc) · 4.45 KB
/
test-prompt.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
/*global describe, before, it*/
'use strict';
var assert = require('yeoman-generator').assert;
var prompt = require('../app/prompt');
describe('prompts module', function () {
it('extracts domain from url', function () {
assert.equal(prompt.extractDomain('http://www.example.org'), 'www.example.org');
assert.equal(prompt.extractDomain('https://www.example.org'), 'www.example.org');
assert.equal(prompt.extractDomain('https://www.example.org/some/path'), 'www.example.org');
assert.equal(prompt.extractDomain('http://www.example.org:1234/some/path'), 'www.example.org:1234');
assert.equal(prompt.extractDomain('example.org'), 'example.org');
assert.equal(prompt.extractDomain('example.org/some/page'), 'example.org');
});
it('recognizes GitHub domain', function () {
assert(prompt.isGitHub('http://example.github.io'), 'http://example.github.io');
assert(prompt.isGitHub('https://example.github.io'), 'https://example.github.io');
assert(prompt.isGitHub('http://owner.github.io/project'), 'http://owner.github.io/project');
assert(!prompt.isGitHub('http://www.example.org'), 'http://www.example.org');
});
describe('githubTarget', function () {
var ghTarget;
before(function () {
for (var i = 0, qq = prompt.questions(), q; (q = qq[i]); i++) {
if (q.name === 'githubTarget') {
ghTarget = q;
break;
}
}
if (!ghTarget) {
assert.fail('Could not find "githubTarget" question');
}
});
it('validates input', function () {
assert.equal(ghTarget.validate('owner/repo'), true, 'owner/repo');
assert.equal(ghTarget.validate('owner/www.example.org'), true, 'owner/repo');
assert.equal(ghTarget.validate('owner/owner.github.io'), true, 'owner/repo');
assert.equal(ghTarget.validate('owner'), true, 'owner');
assert.equal(typeof ghTarget.validate('in.val.id'), 'string', 'in.val.id');
});
it('filters input', function () {
assert.equal(ghTarget.filter('owner/repo'), 'owner/repo');
assert.equal(ghTarget.filter('"owner/repo"'), 'owner/repo');
assert.equal(ghTarget.filter('\'owner/repo\''), 'owner/repo');
assert.equal(ghTarget.filter(''), '');
assert.equal(ghTarget.filter(null), '');
assert.equal(ghTarget.filter(undefined), '');
});
it('knows when to ask the question', function () {
assert.equal(ghTarget.when({hostingChoice: 'gae'}), false);
assert.equal(ghTarget.when({hostingChoice: null}), false);
assert.equal(ghTarget.when({hostingChoice: 'github'}), true);
});
it('infers default value from github.io siteUrl', function () {
assert.equal(ghTarget.default({siteUrl: 'http://owner.github.io/repo'}),
'owner/repo');
assert.equal(ghTarget.default({siteUrl: 'http://owner.github.io'}),
'owner/owner.github.io');
});
});
describe('populateMissing', function () {
it('infers githubTarget from siteUrl', function () {
var a = {siteUrl: 'https://owner.github.io'};
prompt.populateMissing(a);
assert.equal(a.githubTarget, 'owner/owner.github.io');
a = {siteUrl: 'https://owner.github.io/repo'};
prompt.populateMissing(a);
assert.equal(a.githubTarget, 'owner/repo');
});
it('infers siteUrl from githubTarget', function () {
var a = {githubTarget: 'owner/repo'};
prompt.populateMissing(a);
assert.equal(a.siteUrl, 'https://owner.github.io/repo');
a = {githubTarget: 'owner/owner.github.io'};
prompt.populateMissing(a);
assert.equal(a.siteUrl, 'https://owner.github.io');
});
it('infers siteHost from siteUrl', function () {
var a = {siteUrl: 'http://www.example.org/path'};
prompt.populateMissing(a);
assert.equal(a.siteHost, 'www.example.org');
});
it('infers githubBranch', function () {
var a = {siteUrl: 'http://owner.github.io'};
prompt.populateMissing(a);
assert.equal(a.githubBranch, 'master');
a = {siteUrl: 'http://owner.github.io/repo'};
prompt.populateMissing(a);
assert.equal(a.githubBranch, 'gh-pages');
a = {githubTarget: 'owner/repo'};
prompt.populateMissing(a);
assert.equal(a.githubBranch, 'gh-pages');
a = {githubTarget: 'owner/owner.github.io'};
prompt.populateMissing(a);
assert.equal(a.githubBranch, 'master');
a = {siteUrl: 'http://www.example.org/path'};
prompt.populateMissing(a);
assert.equal(a.githubBranch, undefined);
});
});
});