Skip to content

Commit 65e8f29

Browse files
committed
Better naming, a few more utilities
1 parent c94b8e3 commit 65e8f29

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

node-tests/acceptance/build-test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ describe('Acceptance: build', function() {
4545
var foo = exports.foo = 'hello';
4646
`);
4747
}));
48+
49+
it('fails the build when noEmitOnError is set and an error is emitted', co.wrap(function*() {
50+
this.app.writeFile('app/app.ts', `import { foo } from 'nonexistent';`);
51+
52+
yield expect(this.app.build()).to.be.rejectedWith(`Cannot find module 'nonexistent'`);
53+
}));
4854
});
4955

5056
function extractModuleBody(script, moduleName) {

node-tests/helpers/skeleton-app.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
'use strict';
22

33
const fs = require('fs-extra');
4+
const path = require('path');
45
const mktemp = require('mktemp');
56
const execa = require('execa');
67
const EventEmitter = require('events').EventEmitter;
78

89
module.exports = class SkeletonApp {
910
constructor() {
1011
this._watched = null;
11-
this.appDir = mktemp.createDirSync('test-skeleton-app-XXXXXX');
12-
fs.copySync(`${__dirname}/../fixtures/skeleton-app`, this.appDir);
12+
this.root = mktemp.createDirSync('test-skeleton-app-XXXXXX');
13+
fs.copySync(`${__dirname}/../fixtures/skeleton-app`, this.root);
1314
}
1415

1516
build() {
@@ -24,40 +25,52 @@ module.exports = class SkeletonApp {
2425
return this._watched = new WatchedBuild(this._ember(['serve']));
2526
}
2627

27-
writeFile(path, contents) {
28-
fs.writeFileSync(`${this.appDir}/${path}`, contents, 'utf-8');
28+
updatePackageJSON(callback) {
29+
let pkgPath = `${this.root}/package.json`;
30+
let pkg = fs.readJSONSync(pkgPath);
31+
fs.writeJSONSync(pkgPath, callback(pkg) || pkg, { spaces: 2 });
32+
}
33+
34+
writeFile(filePath, contents) {
35+
let fullPath = `${this.root}/${filePath}`;
36+
fs.ensureDirSync(path.dirname(fullPath));
37+
fs.writeFileSync(fullPath, contents, 'utf-8');
2938
}
3039

3140
readFile(path) {
32-
return fs.readFileSync(`${this.appDir}/${path}`, 'utf-8');
41+
return fs.readFileSync(`${this.root}/${path}`, 'utf-8');
42+
}
43+
44+
removeFile(path) {
45+
return fs.unlinkSync(`${this.root}/${path}`);
3346
}
3447

3548
teardown() {
3649
if (this._watched) {
3750
this._watched.kill();
3851
}
3952

40-
this._cleanupAppDir({ retries: 1 });
53+
this._cleanupRootDir({ retries: 1 });
4154
}
4255

4356
_ember(args) {
4457
let ember = require.resolve('ember-cli/bin/ember');
45-
return execa('node', [ember].concat(args), { cwd: this.appDir });
58+
return execa('node', [ember].concat(args), { cwd: this.root });
4659
}
4760

48-
_cleanupAppDir(options) {
61+
_cleanupRootDir(options) {
4962
let retries = options && options.retries || 0;
5063

5164
try {
52-
fs.removeSync(this.appDir);
65+
fs.removeSync(this.root);
5366
} catch (error) {
5467
if (retries > 0) {
5568
// Windows doesn't necessarily kill the process immediately, so
5669
// leave a little time before trying to remove the directory.
57-
setTimeout(() => this._cleanupAppDir({ retries: retries - 1 }), 250);
70+
setTimeout(() => this._cleanupRootDir({ retries: retries - 1 }), 250);
5871
} else {
5972
// eslint-disable-next-line no-console
60-
console.warn(`Warning: unable to remove skeleton-app tmpdir ${this.appDir} (${error.code})`);
73+
console.warn(`Warning: unable to remove skeleton-app tmpdir ${this.root} (${error.code})`);
6174
}
6275
}
6376
}

0 commit comments

Comments
 (0)