forked from ember-cli/ember-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
brocfile-smoke-test-slow.js
415 lines (318 loc) · 15.2 KB
/
brocfile-smoke-test-slow.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
'use strict';
const co = require('co');
const RSVP = require('rsvp');
const path = require('path');
const fs = require('fs-extra');
let remove = RSVP.denodeify(fs.remove);
const runCommand = require('../helpers/run-command');
const acceptance = require('../helpers/acceptance');
const copyFixtureFiles = require('../helpers/copy-fixture-files');
let createTestTargets = acceptance.createTestTargets;
let teardownTestTargets = acceptance.teardownTestTargets;
let linkDependencies = acceptance.linkDependencies;
let cleanupRun = acceptance.cleanupRun;
const chai = require('../chai');
let expect = chai.expect;
let file = chai.file;
let dir = chai.dir;
let appName = 'some-cool-app';
let appRoot;
describe('Acceptance: brocfile-smoke-test', function() {
this.timeout(500000);
before(function() {
return createTestTargets(appName);
});
after(teardownTestTargets);
beforeEach(function() {
appRoot = linkDependencies(appName);
});
afterEach(function() {
cleanupRun(appName);
expect(dir(appRoot)).to.not.exist;
});
it('a custom EmberENV in config/environment.js is used for window.EmberENV', co.wrap(function *() {
yield copyFixtureFiles('brocfile-tests/custom-ember-env');
yield runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');
let vendorContents = fs.readFileSync(path.join('dist', 'assets', 'vendor.js'), {
encoding: 'utf8',
});
let expected = 'window.EmberENV = {"asdflkmawejf":";jlnu3yr23"};';
expect(vendorContents).to.contain(expected, 'EmberENV should be in assets/vendor.js');
}));
it('a custom environment config can be used in Brocfile.js', co.wrap(function *() {
yield copyFixtureFiles('brocfile-tests/custom-environment-config');
yield runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'test');
}));
it('without app/templates', co.wrap(function *() {
yield copyFixtureFiles('brocfile-tests/pods-templates');
yield remove(path.join(process.cwd(), 'app/templates'));
yield runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'test');
}));
it('strips app/styles or app/templates from JS', co.wrap(function *() {
yield copyFixtureFiles('brocfile-tests/styles-and-templates-stripped');
yield runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');
let appFileContents = fs.readFileSync(path.join(appRoot, 'dist', 'assets', `${appName}.js`), {
encoding: 'utf8',
});
expect(appFileContents).to.include('//app/templates-stuff.js');
expect(appFileContents).to.include('//app/styles-manager.js');
}));
it('should fall back to the Brocfile', co.wrap(function *() {
yield copyFixtureFiles('brocfile-tests/no-ember-cli-build');
fs.removeSync('./ember-cli-build.js');
yield runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');
expect(file('Brocfile.js')).to.exist;
expect(file('ember-cli-build.js')).to.not.exist;
}));
it('should use the Brocfile if both a Brocfile and ember-cli-build exist', co.wrap(function *() {
yield copyFixtureFiles('brocfile-tests/both-build-files');
let result = yield runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');
let vendorContents = fs.readFileSync(path.join('dist', 'assets', 'vendor.js'), {
encoding: 'utf8',
});
let expected = 'var usingBrocfile = true;';
expect(vendorContents).to.contain(expected, 'includes file imported from Brocfile');
expect(result.output.join('\n')).to.include('Brocfile.js has been deprecated');
}));
it('should throw if no build file is found', co.wrap(function *() {
fs.removeSync('./ember-cli-build.js');
try {
yield runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');
} catch (err) {
expect(err.code).to.eql(1);
}
}));
it('using autoRun: true', co.wrap(function *() {
yield copyFixtureFiles('brocfile-tests/auto-run-true');
yield runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');
let appFileContents = fs.readFileSync(path.join(appRoot, 'dist', 'assets', `${appName}.js`), {
encoding: 'utf8',
});
expect(appFileContents).to.match(/\/app"\)\["default"\]\.create\(/);
}));
it('using autoRun: false', co.wrap(function *() {
yield copyFixtureFiles('brocfile-tests/auto-run-false');
yield runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');
let appFileContents = fs.readFileSync(path.join(appRoot, 'dist', 'assets', `${appName}.js`), {
encoding: 'utf8',
});
expect(appFileContents).to.not.match(/\/app"\)\["default"\]\.create\(/);
}));
it('app.import works properly with test tree files', co.wrap(function *() {
yield copyFixtureFiles('brocfile-tests/app-test-import');
let packageJsonPath = path.join(appRoot, 'package.json');
let packageJson = fs.readJsonSync(packageJsonPath);
packageJson.devDependencies['ember-test-addon'] = 'latest';
fs.writeJsonSync(packageJsonPath, packageJson);
yield runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');
let subjectFileContents = fs.readFileSync(path.join(appRoot, 'dist', 'assets', 'test-support.js'), {
encoding: 'utf8',
});
expect(subjectFileContents).to.contain('// File for test tree imported and added via postprocessTree()');
}));
it('app.import works properly with non-js/css files', co.wrap(function *() {
yield copyFixtureFiles('brocfile-tests/app-import');
let packageJsonPath = path.join(appRoot, 'package.json');
let packageJson = fs.readJsonSync(packageJsonPath);
packageJson.devDependencies['ember-random-addon'] = 'latest';
fs.writeJsonSync(packageJsonPath, packageJson);
yield runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');
let subjectFileContents = fs.readFileSync(path.join(appRoot, 'dist', 'assets', 'file-to-import.txt'), {
encoding: 'utf8',
});
expect(subjectFileContents).to.equal('EXAMPLE TEXT FILE CONTENT\n');
}));
it('addons can have a public tree that is merged and returned namespaced by default', co.wrap(function *() {
yield copyFixtureFiles('brocfile-tests/public-tree');
let packageJsonPath = path.join(appRoot, 'package.json');
let packageJson = fs.readJsonSync(packageJsonPath);
packageJson.devDependencies['ember-random-addon'] = 'latest';
fs.writeJsonSync(packageJsonPath, packageJson);
yield runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');
let subjectFileContents = fs.readFileSync(path.join(appRoot, 'dist', 'ember-random-addon', 'some-root-file.txt'), {
encoding: 'utf8',
});
expect(subjectFileContents).to.equal('ROOT FILE\n');
}));
it('using pods based templates', co.wrap(function *() {
yield copyFixtureFiles('brocfile-tests/pods-templates');
yield runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'test');
}));
it('using pods based templates with a podModulePrefix', co.wrap(function *() {
yield copyFixtureFiles('brocfile-tests/pods-with-prefix-templates');
yield runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'test');
}));
it('addon trees are not jshinted', co.wrap(function *() {
yield copyFixtureFiles('brocfile-tests/jshint-addon');
let packageJsonPath = path.join(appRoot, 'package.json');
let packageJson = fs.readJsonSync(packageJsonPath);
packageJson['ember-addon'] = {
paths: ['./lib/ember-random-thing'],
};
fs.writeJsonSync(packageJsonPath, packageJson);
yield runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'test', '--filter=jshint');
}));
it('specifying custom output paths works properly', co.wrap(function *() {
yield copyFixtureFiles('brocfile-tests/custom-output-paths');
let themeCSSPath = path.join(appRoot, 'app', 'styles', 'theme.css');
fs.writeFileSync(themeCSSPath, 'html, body { margin: 20%; }');
yield runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');
let files = [
'/css/app.css',
'/css/theme/a.css',
'/js/app.js',
'/css/vendor.css',
'/js/vendor.js',
'/css/test-support.css',
'/js/test-support.js',
'/my-app.html',
];
let basePath = path.join(appRoot, 'dist');
files.forEach(function(f) {
expect(file(path.join(basePath, f))).to.exist;
});
}));
it('multiple css files in app/styles/ are output when a preprocessor is not used', co.wrap(function *() {
yield copyFixtureFiles('brocfile-tests/multiple-css-files');
yield runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');
let files = [
'/assets/some-cool-app.css',
'/assets/other.css',
];
let basePath = path.join(appRoot, 'dist');
files.forEach(function(f) {
expect(file(path.join(basePath, f))).to.exist;
});
}));
it('specifying outputFile results in an explicitly generated assets', co.wrap(function *() {
yield copyFixtureFiles('brocfile-tests/app-import-output-file');
yield runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');
let files = [
'/assets/output-file.js',
'/assets/output-file.css',
'/assets/vendor.css',
'/assets/vendor.js',
];
let basePath = path.join(appRoot, 'dist');
files.forEach(function(f) {
expect(file(path.join(basePath, f))).to.exist;
});
}));
it('can use transformation to turn anonymous AMD into named AMD', co.wrap(function *() {
yield copyFixtureFiles('brocfile-tests/app-import-anonymous-amd');
yield runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');
let outputJS = fs.readFileSync(path.join(appRoot, 'dist', 'assets', 'output.js'), {
encoding: 'utf8',
});
(function() {
let defineCount = 0;
// eslint-disable-next-line no-unused-vars
function define(name, deps, factory) {
expect(name).to.equal('hello-world');
expect(deps).to.deep.equal([]);
expect(factory()()).to.equal('Hello World');
defineCount++;
}
/* eslint-disable no-eval */
eval(outputJS);
/* eslint-enable no-eval */
expect(defineCount).to.eql(1);
})();
}));
it('can do amd transform from addon', co.wrap(function *() {
yield copyFixtureFiles('brocfile-tests/app-import-custom-transform');
let packageJsonPath = path.join(appRoot, 'package.json');
let packageJson = fs.readJsonSync(packageJsonPath);
packageJson.devDependencies['ember-transform-addon'] = 'latest';
fs.writeJsonSync(packageJsonPath, packageJson);
yield runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');
let addonOutputJs = fs.readFileSync(path.join(appRoot, 'dist', 'assets', 'addon-output.js'), {
encoding: 'utf8',
});
(function() {
let defineCount = 0;
// eslint-disable-next-line no-unused-vars
function define(name, deps, factory) {
expect(name).to.equal('addon-vendor');
expect(deps).to.deep.equal([]);
expect(factory()()).to.equal('Hello World');
defineCount++;
}
/* eslint-disable no-eval */
eval(addonOutputJs);
/* eslint-enable no-eval */
expect(defineCount).to.eql(1);
})();
}));
it('can use transformation to turn library into custom transformation', co.wrap(function *() {
yield copyFixtureFiles('brocfile-tests/app-import-custom-transform');
let packageJsonPath = path.join(appRoot, 'package.json');
let packageJson = fs.readJsonSync(packageJsonPath);
packageJson.devDependencies['ember-transform-addon'] = 'latest';
fs.writeJsonSync(packageJsonPath, packageJson);
yield runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');
let outputJS = fs.readFileSync(path.join(appRoot, 'dist', 'assets', 'output.js'), {
encoding: 'utf8',
});
expect(outputJS).to.be.equal('if (typeof FastBoot === \'undefined\') { window.hello = "hello world"; }//# sourceMappingURL=output.map\n');
}));
// skipped because of potentially broken assertion that should be fixed correctly at a later point
it.skip('specifying partial `outputPaths` hash deep merges options correctly', co.wrap(function *() {
yield copyFixtureFiles('brocfile-tests/custom-output-paths');
let themeCSSPath = path.join(appRoot, 'app', 'styles', 'theme.css');
fs.writeFileSync(themeCSSPath, 'html, body { margin: 20%; }');
let brocfilePath = path.join(appRoot, 'ember-cli-build.js');
let brocfile = fs.readFileSync(brocfilePath, 'utf8');
// remove outputPaths.app.js option
brocfile = brocfile.replace(/js: '\/js\/app.js'/, '');
// remove outputPaths.app.css.app option
brocfile = brocfile.replace(/'app': '\/css\/app\.css',/, '');
fs.writeFileSync(brocfilePath, brocfile, 'utf8');
yield runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');
let files = [
'/css/theme/a.css',
'/assets/some-cool-app.js',
'/css/vendor.css',
'/js/vendor.js',
'/css/test-support.css',
'/js/test-support.js',
];
let basePath = path.join(appRoot, 'dist');
files.forEach(function(f) {
expect(file(path.join(basePath, f))).to.exist;
});
expect(file(path.join(basePath, '/assets/some-cool-app.css'))).to.not.exist;
}));
it('multiple paths can be CSS preprocessed', co.wrap(function *() {
yield copyFixtureFiles('brocfile-tests/multiple-sass-files');
let packageJsonPath = path.join(appRoot, 'package.json');
let packageJson = fs.readJsonSync(packageJsonPath);
packageJson.devDependencies['ember-cli-sass'] = 'latest';
fs.writeJsonSync(packageJsonPath, packageJson);
yield runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');
expect(file('dist/assets/main.css'))
.to.equal('body { background: black; }\n', 'main.css contains correct content');
expect(file('dist/assets/theme/a.css'))
.to.equal('.theme { color: red; }\n', 'theme/a.css contains correct content');
}));
it('app.css is output to <app name>.css by default', co.wrap(function *() {
yield runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');
expect(file(`dist/assets/${appName}.css`)).to.exist;
}));
// for backwards compat.
it('app.scss is output to <app name>.css by default', co.wrap(function *() {
yield copyFixtureFiles('brocfile-tests/multiple-sass-files');
let brocfilePath = path.join(appRoot, 'ember-cli-build.js');
let brocfile = fs.readFileSync(brocfilePath, 'utf8');
// remove custom preprocessCss paths, use app.scss instead
brocfile = brocfile.replace(/outputPaths.*/, '');
fs.writeFileSync(brocfilePath, brocfile, 'utf8');
let packageJsonPath = path.join(appRoot, 'package.json');
let packageJson = fs.readJsonSync(packageJsonPath);
packageJson.devDependencies['ember-cli-sass'] = 'latest';
fs.writeJsonSync(packageJsonPath, packageJson);
yield runCommand(path.join('.', 'node_modules', 'ember-cli', 'bin', 'ember'), 'build');
expect(file(`dist/assets/${appName}.css`))
.to.equal('body { background: green; }\n');
}));
});