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-github.js
166 lines (141 loc) · 4.74 KB
/
test-github.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
/*global describe, before, it*/
'use strict';
var fs = require('fs');
var exec = require('child_process').exec;
var assert = require('yeoman-generator').assert;
var chalk = require('chalk');
var testUtil = require('./util');
var deps = require('../app/deps');
describe('mobile:app - GitHub hosting', function () {
var checkGit;
before(function (done) {
deps.checkGit(function (res, data) {
checkGit = data;
done();
});
});
describe('project', function () {
before(function (done) {
testUtil.mockGitHub();
testUtil.runGenerator({
hostingChoice: 'github',
siteUrl: 'http://owner.github.io/repo',
githubTarget: 'owner/repo'
}, done);
});
it('has "gulp deploy" task', function () {
assert.fileContent('tasks/deploy.js', /gulp\.task\('deploy'/);
assert.fileContent('tasks/deploy.js', /'push', '-u', 'origin', 'gh-pages'/m);
});
it('has no CNAME file', function () {
assert.noFile('app/CNAME');
});
it('keeps "dist" in .gitignore', function () {
assert.fileContent('.gitignore', /^dist\/?$/m);
});
it('creates repo in dist/', function (done) {
if (checkGit.error) {
console.warn(chalk.yellow('skip because of git check: ' + checkGit.error));
done();
return;
}
assert.file('dist/.git');
exec('git status', {cwd: 'dist'}, function (err, stdout) {
assert.ok(!err, err);
assert.ok(/working directory clean/m.test(stdout), stdout);
done();
});
});
it('sets remote to github in dist/.git', function (done) {
if (checkGit.error) {
console.warn(chalk.yellow('skip because of git check: ' + checkGit.error));
done();
return;
}
exec('git remote -v', {cwd: 'dist'}, function (err, stdout) {
assert.ok(!err, err);
assert.ok(/^origin\s+git@github\.com:owner\/repo\s+/m.test(stdout), stdout);
done();
});
});
it('initalizes gh-pages branch in dist/.git', function (done) {
if (checkGit.error) {
console.warn(chalk.yellow('skip because of git check: ' + checkGit.error));
done();
return;
}
exec('git branch', {cwd: 'dist'}, function (err, stdout) {
assert.ok(!err, err);
assert.ok(/^\*\sgh-pages$/m.test(stdout), stdout);
done();
});
});
});
describe('org/user', function () {
before(function (done) {
testUtil.mockGitHub();
testUtil.runGenerator({
hostingChoice: 'github',
siteUrl: 'http://owner.github.io',
githubTarget: 'owner/owner.github.io'
}, done);
});
it('has no CNAME file', function () {
assert.noFile('app/CNAME');
});
it('has "gulp deploy" task', function () {
assert.fileContent('tasks/deploy.js', /gulp\.task\('deploy'/);
assert.fileContent('tasks/deploy.js', /'push', '-u', 'origin', 'master'/m);
});
it('initalizes master branch in dist/.git', function (done) {
if (checkGit.error) {
console.warn(chalk.yellow('skip because of git check: ' + checkGit.error));
done();
return;
}
exec('git branch', {cwd: 'dist'}, function (err, stdout) {
assert.ok(!err, err);
assert.ok(/^\*\smaster$/m.test(stdout), stdout);
done();
});
});
});
describe('custom domain', function () {
describe('for a user/org', function () {
before(function (done) {
testUtil.mockGitHub();
testUtil.runGenerator({
hostingChoice: 'github',
siteUrl: 'http://www.example.org',
githubTarget: 'owner/owner.github.io'
}, done);
});
it('creates a CNAME for an owner', function () {
var content = fs.readFileSync('app/CNAME', 'utf8');
assert.textEqual(content, 'www.example.org');
});
it('deploys to correct branch', function () {
assert.fileContent('tasks/deploy.js', /gulp\.task\('deploy'/);
assert.fileContent('tasks/deploy.js', /'push', '-u', 'origin', 'master'/m);
});
});
describe('as a repo', function () {
before(function (done) {
testUtil.mockGitHub();
testUtil.runGenerator({
hostingChoice: 'github',
siteUrl: 'http://www.example.org',
githubTarget: 'owner/www.example.org'
}, done);
});
it('creates a CNAME for repo with domain name', function () {
var content = fs.readFileSync('app/CNAME', 'utf8');
assert.textEqual(content, 'www.example.org');
});
it('deploys to correct branch', function () {
assert.fileContent('tasks/deploy.js', /gulp\.task\('deploy'/);
assert.fileContent('tasks/deploy.js', /'push', '-u', 'origin', 'gh-pages'/m);
});
});
});
});