forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.spec.js
203 lines (171 loc) · 5.95 KB
/
init.spec.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
'use strict';
var ng = require('../helpers/ng');
var expect = require('chai').expect;
var walkSync = require('walk-sync');
var glob = require('glob');
var Blueprint = require('@angular/cli/ember-cli/lib/models/blueprint');
var path = require('path');
var tmp = require('../helpers/tmp');
var root = path.join(__dirname, '../../packages/@angular/cli');
var util = require('util');
var minimatch = require('minimatch');
var intersect = require('lodash/intersection');
var remove = require('lodash/remove');
var unique = require('lodash/uniq');
var forEach = require('lodash/forEach');
var any = require('lodash/some');
var EOL = require('os').EOL;
var existsSync = require('exists-sync');
var defaultIgnoredFiles = Blueprint.ignoredFiles;
describe('Acceptance: ng update', function () {
this.timeout(20000);
beforeEach(function () {
// Make a copy of defaultIgnoredFiles.
Blueprint.ignoredFiles = defaultIgnoredFiles.splice(0);
return tmp.setup('./tmp').then(function () {
process.chdir('./tmp');
});
});
afterEach(function () {
return tmp.teardown('./tmp');
});
function confirmBlueprinted(routing) {
routing = !!routing;
var blueprintPath = path.join(root, 'blueprints', 'ng2', 'files');
var expected = unique(walkSync(blueprintPath).sort());
var actual = walkSync('.').sort();
forEach(Blueprint.renamedFiles, function (destFile, srcFile) {
expected[expected.indexOf(srcFile)] = destFile;
});
expected.forEach(function (file, index) {
expected[index] = file.replace(/__name__/g, 'app');
expected[index] = expected[index].replace(/__styleext__/g, 'css');
expected[index] = expected[index].replace(/__path__/g, 'src');
});
if (!routing) {
expected = expected.filter(p => p.indexOf('app-routing.module.ts') < 0);
}
removeIgnored(expected);
removeIgnored(actual);
expected.sort();
expect(expected).to.deep.equal(
actual,
EOL + ' expected: ' + util.inspect(expected) + EOL + ' but got: ' + util.inspect(actual));
}
function confirmGlobBlueprinted(pattern) {
var blueprintPath = path.join(root, 'blueprints', 'ng2', 'files');
var actual = pickSync('.', pattern);
var expected = intersect(pickSync(blueprintPath, pattern), actual);
removeIgnored(expected);
removeIgnored(actual);
expected.sort();
expect(expected).to.deep.equal(
actual,
EOL + ' expected: ' + util.inspect(expected) + EOL + ' but got: ' + util.inspect(actual));
}
function pickSync(filePath, pattern) {
return glob.sync(path.join('**', pattern), { cwd: filePath, dot: true, mark: true, strict: true })
.sort();
}
function removeIgnored(array) {
remove(array, function (fn) {
return any(Blueprint.ignoredFiles, function (ignoredFile) {
return minimatch(fn, ignoredFile, { matchBase: true });
});
});
}
it('ng init does the same as ng update', function () {
return ng([
'init',
'--skip-install'
]).then(confirmBlueprinted);
});
it('ng update can run in created folder', function () {
return tmp.setup('./tmp/foo')
.then(function () {
process.chdir('./tmp/foo');
})
.then(function () {
return ng([
'init',
'--skip-install',
'--name',
'tmp'
]);
})
.then(confirmBlueprinted)
.then(function () {
return tmp.teardown('./tmp/foo');
});
});
it('init an already init\'d folder', function () {
return ng(['init', '--skip-install'])
.then(function () {
return ng(['init', '--skip-install']);
})
.then(confirmBlueprinted);
});
it('init a single file', function () {
return ng(['init', 'package.json', '--skip-install'])
.then(function () {
return 'package.json';
})
.then(confirmGlobBlueprinted);
});
it('init a single file on already init\'d folder', function () {
return ng(['init', '--skip-install'])
.then(function () {
return ng(['init', 'package.json', '--skip-install']);
})
.then(confirmBlueprinted);
});
it('init multiple files by glob pattern', function () {
return ng(['init', 'src/**', '--skip-install'])
.then(function () {
return 'src/**';
})
.then(confirmGlobBlueprinted);
});
it('init multiple files by glob pattern on already init\'d folder', function () {
return ng(['init', '--skip-install'])
.then(function () {
return ng(['init', 'src/**', '--skip-install']);
})
.then(confirmBlueprinted);
});
it('init multiple files by glob patterns', function () {
return ng(['init', 'src/**', 'package.json', '--skip-install'])
.then(function () {
return '{src/**,package.json}';
})
.then(confirmGlobBlueprinted);
});
it('init multiple files by glob patterns on already init\'d folder', function () {
return ng(['init', '--skip-install'])
.then(function () {
return ng(['init', 'src/**', 'package.json', '--skip-install']);
})
.then(confirmBlueprinted);
});
it('ng update --inline-template does not generate a template file', () => {
return ng(['init', '--skip-install', '--skip-git', '--inline-template'])
.then(() => {
const templateFile = path.join('src', 'app', 'app.component.html');
expect(existsSync(templateFile)).to.equal(false);
});
});
it('ng update --inline-style does not gener a style file', () => {
return ng(['init', '--skip-install', '--skip-git', '--inline-style'])
.then(() => {
const styleFile = path.join('src', 'app', 'app.component.css');
expect(existsSync(styleFile)).to.equal(false);
});
});
it('should skip spec files when passed --skip-tests', () => {
return ng(['init', '--skip-install', '--skip-git', '--skip-tests'])
.then(() => {
const specFile = path.join('src', 'app', 'app.component.spec.ts');
expect(existsSync(specFile)).to.equal(false);
});
});
});