Skip to content

Commit 4201061

Browse files
author
Kelly Selden
authored
Merge pull request #67 from kellyselden/not-ember-app-test
add test for not an ember app
2 parents 442f490 + 312d2b5 commit 4201061

2 files changed

Lines changed: 54 additions & 18 deletions

File tree

__tests__/bin-test.js

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,74 @@ const fs = require('fs-extra');
55
const cp = require('child_process');
66
const tmp = require('tmp');
77

8+
const inputFile = path.join(process.cwd(), '__testfixtures__/final-boss.input.js');
9+
const outputFile = path.join(process.cwd(), '__testfixtures__/final-boss.output.js');
10+
811
describe('bin acceptance', function() {
912
let tmpPath;
13+
let tmpFile;
14+
let tmpPackageJson;
1015

1116
beforeEach(function() {
1217
tmpPath = tmp.dirSync().name;
1318

14-
fs.ensureDirSync(path.join(tmpPath, 'app'));
19+
tmpPackageJson = path.join(tmpPath, 'package.json');
1520

16-
fs.writeJsonSync(path.join(tmpPath, 'package.json'), {
17-
devDependencies: {
18-
'ember-cli': ''
19-
}
20-
});
21-
});
21+
fs.ensureDirSync(path.join(tmpPath, 'app'));
2222

23-
it('works', function() {
24-
let inputFile = path.join(process.cwd(), '__testfixtures__/final-boss.input.js');
25-
let outputFile = path.join(process.cwd(), '__testfixtures__/final-boss.output.js');
26-
let tmpFile = path.join(tmpPath, 'app/final-boss.js');
23+
tmpFile = path.join(tmpPath, 'app/final-boss.js');
2724

2825
fs.copySync(
2926
path.join(process.cwd(), '__testfixtures__/final-boss.input.js'),
3027
tmpFile
3128
);
29+
});
30+
31+
it('handles non-ember projects', function() {
32+
let stderr = '';
33+
let exitCode;
34+
35+
return new Promise(resolve => {
36+
let ps = cp.spawn('node', [
37+
path.join(process.cwd(), 'bin/ember-modules-codemod')
38+
], {
39+
cwd: tmpPath
40+
});
3241

33-
cp.spawnSync('node', [
34-
path.join(process.cwd(), 'bin/ember-modules-codemod')
35-
], {
36-
cwd: tmpPath,
37-
stdio: 'inherit'
42+
ps.stderr.on('data', data => {
43+
stderr += data.toString();
44+
});
45+
46+
ps.on('exit', (code, signal) => {
47+
exitCode = code;
48+
49+
resolve();
50+
});
51+
}).then(() => {
52+
expect(exitCode).not.toEqual(0);
53+
54+
expect(stderr).toEqual(`It doesn't look like you're inside an Ember app. I couldn't find a package.json at ${tmpPackageJson}\n`);
55+
});
56+
});
57+
58+
describe('with valid package.json', function() {
59+
beforeEach(function() {
60+
fs.writeJsonSync(tmpPackageJson, {
61+
devDependencies: {
62+
'ember-cli': ''
63+
}
64+
});
3865
});
3966

40-
expect(fs.readFileSync(tmpFile, 'utf8')).toEqual(fs.readFileSync(outputFile, 'utf8'));
67+
it('works', function() {
68+
cp.spawnSync('node', [
69+
path.join(process.cwd(), 'bin/ember-modules-codemod')
70+
], {
71+
cwd: tmpPath,
72+
stdio: 'inherit'
73+
});
74+
75+
expect(fs.readFileSync(tmpFile, 'utf8')).toEqual(fs.readFileSync(outputFile, 'utf8'));
76+
});
4177
});
4278
});

bin/ember-modules-codemod.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const path = require("path");
88
const glob = require("glob");
99

1010
let cwd = process.cwd();
11-
let pkgPath = cwd + "/package.json";
11+
let pkgPath = path.join(cwd, 'package.json');
1212

1313
try {
1414
let pkg = JSON.parse(fs.readFileSync(pkgPath));

0 commit comments

Comments
 (0)