Skip to content

Commit c1cb782

Browse files
author
Kelly Selden
authored
Merge pull request #68 from kellyselden/exits-gracefully
add test for exiting gracefully
2 parents 4201061 + c3aa735 commit c1cb782

1 file changed

Lines changed: 55 additions & 17 deletions

File tree

__tests__/bin-test.js

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,12 @@ const outputFile = path.join(process.cwd(), '__testfixtures__/final-boss.output.
1010

1111
describe('bin acceptance', function() {
1212
let tmpPath;
13-
let tmpFile;
1413
let tmpPackageJson;
1514

1615
beforeEach(function() {
1716
tmpPath = tmp.dirSync().name;
1817

1918
tmpPackageJson = path.join(tmpPath, 'package.json');
20-
21-
fs.ensureDirSync(path.join(tmpPath, 'app'));
22-
23-
tmpFile = path.join(tmpPath, 'app/final-boss.js');
24-
25-
fs.copySync(
26-
path.join(process.cwd(), '__testfixtures__/final-boss.input.js'),
27-
tmpFile
28-
);
2919
});
3020

3121
it('handles non-ember projects', function() {
@@ -64,15 +54,63 @@ describe('bin acceptance', function() {
6454
});
6555
});
6656

67-
it('works', function() {
68-
cp.spawnSync('node', [
69-
path.join(process.cwd(), 'bin/ember-modules-codemod')
70-
], {
71-
cwd: tmpPath,
72-
stdio: 'inherit'
57+
it('exits gracefully when no files found', function() {
58+
let stderr = '';
59+
let exitCode;
60+
61+
return new Promise(resolve => {
62+
let ps = cp.spawn('node', [
63+
path.join(process.cwd(), 'bin/ember-modules-codemod')
64+
], {
65+
cwd: tmpPath
66+
});
67+
68+
ps.stderr.on('data', data => {
69+
stderr += data.toString();
70+
});
71+
72+
ps.on('exit', (code, signal) => {
73+
exitCode = code;
74+
75+
resolve();
76+
});
77+
}).then(() => {
78+
expect(exitCode).toEqual(0);
79+
80+
// jscodeshift can process in any order
81+
expect(stderr).toMatch('Skipping path app which does not exist.');
82+
expect(stderr).toMatch('Skipping path addon which does not exist.');
83+
expect(stderr).toMatch('Skipping path addon-test-support which does not exist.');
84+
expect(stderr).toMatch('Skipping path tests which does not exist.');
85+
expect(stderr).toMatch('Skipping path test-support which does not exist.');
86+
expect(stderr).toMatch('Skipping path lib which does not exist.');
7387
});
88+
});
89+
90+
describe('with valid file', function() {
91+
let tmpFile;
7492

75-
expect(fs.readFileSync(tmpFile, 'utf8')).toEqual(fs.readFileSync(outputFile, 'utf8'));
93+
beforeEach(function() {
94+
fs.ensureDirSync(path.join(tmpPath, 'app'));
95+
96+
tmpFile = path.join(tmpPath, 'app/final-boss.js');
97+
98+
fs.copySync(
99+
path.join(process.cwd(), '__testfixtures__/final-boss.input.js'),
100+
tmpFile
101+
);
102+
});
103+
104+
it('works', function() {
105+
cp.spawnSync('node', [
106+
path.join(process.cwd(), 'bin/ember-modules-codemod')
107+
], {
108+
cwd: tmpPath,
109+
stdio: 'inherit'
110+
});
111+
112+
expect(fs.readFileSync(tmpFile, 'utf8')).toEqual(fs.readFileSync(outputFile, 'utf8'));
113+
});
76114
});
77115
});
78116
});

0 commit comments

Comments
 (0)