Skip to content

Commit 174168b

Browse files
authored
Merge pull request #17 from simonihmig/bin-test
Add test for bin command
2 parents 43da245 + 767ec6c commit 174168b

4 files changed

Lines changed: 135 additions & 5 deletions

File tree

__testfixtures__/find.output.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
test('it renders', function(assert) {
32
assert.equal(this.element.querySelector('.foo').textContent.trim(), 'bar');
43
assert.equal(this.element.querySelectorAll('.bar').length, 2);

__tests__/bin-test.js

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
const fs = require('fs-extra');
5+
const cp = require('child_process');
6+
const tmp = require('tmp');
7+
8+
const originalCwd = process.cwd();
9+
10+
let tmpPath;
11+
12+
function run(type, dir) {
13+
let stdout = '';
14+
let stderr = '';
15+
16+
return new Promise(resolve => {
17+
let ps = cp.spawn('node', [
18+
path.join(originalCwd, 'bin/ember-test-helpers-codemod'),
19+
`--type=${type}`,
20+
dir
21+
], {
22+
cwd: tmpPath
23+
});
24+
25+
ps.stdout.on('data', data => {
26+
stdout += data.toString();
27+
});
28+
29+
ps.stderr.on('data', data => {
30+
stderr += data.toString();
31+
});
32+
33+
ps.on('exit', code => {
34+
resolve({
35+
exitCode: code,
36+
stdout,
37+
stderr
38+
});
39+
});
40+
});
41+
}
42+
43+
const testScenarios = [
44+
{
45+
type: 'integration',
46+
inputFile: path.join(originalCwd, '__testfixtures__/integration/all.input.js'),
47+
outputFile: path.join(originalCwd, '__testfixtures__/integration/all.output.js')
48+
},
49+
{
50+
type: 'acceptance',
51+
inputFile: path.join(originalCwd, '__testfixtures__/acceptance/visit.input.js'),
52+
outputFile: path.join(originalCwd, '__testfixtures__/acceptance/visit.output.js')
53+
},
54+
{
55+
type: 'native-dom',
56+
inputFile: path.join(originalCwd, '__testfixtures__/native-dom/acceptance.input.js'),
57+
outputFile: path.join(originalCwd, '__testfixtures__/native-dom/acceptance.output.js')
58+
},
59+
{
60+
type: 'find',
61+
inputFile: path.join(originalCwd, '__testfixtures__/find.input.js'),
62+
outputFile: path.join(originalCwd, '__testfixtures__/find.output.js')
63+
}
64+
];
65+
66+
describe('bin acceptance', function() {
67+
let tmpPackageJson;
68+
69+
beforeEach(function() {
70+
tmpPath = tmp.dirSync().name;
71+
72+
process.chdir(tmpPath);
73+
74+
tmpPackageJson = path.join(process.cwd(), 'package.json');
75+
});
76+
77+
afterAll(function() {
78+
process.chdir(originalCwd);
79+
});
80+
81+
testScenarios.forEach(scenario => {
82+
describe(scenario.type, function() {
83+
let tmpFile;
84+
85+
beforeEach(function() {
86+
fs.ensureDirSync(path.join(tmpPath, 'tests'));
87+
88+
tmpFile = path.join(tmpPath, 'tests/test-file.js');
89+
90+
fs.copySync(
91+
scenario.inputFile,
92+
tmpFile
93+
);
94+
});
95+
96+
it('works', function() {
97+
return run(scenario.type, tmpPath).then(result => {
98+
let exitCode = result.exitCode;
99+
100+
expect(exitCode).toEqual(0);
101+
expect(fs.readFileSync(tmpFile, 'utf8')).toEqual(fs.readFileSync(scenario.outputFile, 'utf8'));
102+
});
103+
}, 20000);
104+
});
105+
});
106+
});

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
"jscodeshift": "^0.3.30"
1717
},
1818
"devDependencies": {
19+
"fs-extra": "^5.0.0",
1920
"jest": "^21.2.1",
20-
"temp": "^0.8.3"
21+
"tmp": "^0.0.33"
2122
},
2223
"engines": {
2324
"node": ">= 4"

yarn.lock

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,14 @@ form-data@~2.3.1:
15911591
combined-stream "^1.0.5"
15921592
mime-types "^2.1.12"
15931593

1594+
fs-extra@^5.0.0:
1595+
version "5.0.0"
1596+
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-5.0.0.tgz#414d0110cdd06705734d055652c5411260c31abd"
1597+
dependencies:
1598+
graceful-fs "^4.1.2"
1599+
jsonfile "^4.0.0"
1600+
universalify "^0.1.0"
1601+
15941602
fs-readdir-recursive@^0.1.0:
15951603
version "0.1.2"
15961604
resolved "https://registry.yarnpkg.com/fs-readdir-recursive/-/fs-readdir-recursive-0.1.2.tgz#315b4fb8c1ca5b8c47defef319d073dad3568059"
@@ -1700,7 +1708,7 @@ globals@^9.18.0:
17001708
version "9.18.0"
17011709
resolved "https://registry.yarnpkg.com/globals/-/globals-9.18.0.tgz#aa3896b3e69b487f17e31ed2143d69a8e30c2d8a"
17021710

1703-
graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.4:
1711+
graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.4, graceful-fs@^4.1.6:
17041712
version "4.1.11"
17051713
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
17061714

@@ -2370,6 +2378,12 @@ json5@^0.5.0, json5@^0.5.1:
23702378
version "0.5.1"
23712379
resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821"
23722380

2381+
jsonfile@^4.0.0:
2382+
version "4.0.0"
2383+
resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb"
2384+
optionalDependencies:
2385+
graceful-fs "^4.1.6"
2386+
23732387
jsonify@~0.0.0:
23742388
version "0.0.0"
23752389
resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73"
@@ -2706,7 +2720,7 @@ os-locale@^2.0.0:
27062720
lcid "^1.0.0"
27072721
mem "^1.1.0"
27082722

2709-
os-tmpdir@^1.0.0, os-tmpdir@^1.0.1:
2723+
os-tmpdir@^1.0.0, os-tmpdir@^1.0.1, os-tmpdir@~1.0.2:
27102724
version "1.0.2"
27112725
resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274"
27122726

@@ -3398,7 +3412,7 @@ tar@^2.2.1:
33983412
fstream "^1.0.2"
33993413
inherits "2"
34003414

3401-
temp@^0.8.1, temp@^0.8.3:
3415+
temp@^0.8.1:
34023416
version "0.8.3"
34033417
resolved "https://registry.yarnpkg.com/temp/-/temp-0.8.3.tgz#e0c6bc4d26b903124410e4fed81103014dfc1f59"
34043418
dependencies:
@@ -3423,6 +3437,12 @@ through@~2.3.8:
34233437
version "2.3.8"
34243438
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
34253439

3440+
tmp@^0.0.33:
3441+
version "0.0.33"
3442+
resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9"
3443+
dependencies:
3444+
os-tmpdir "~1.0.2"
3445+
34263446
34273447
version "1.0.4"
34283448
resolved "https://registry.yarnpkg.com/tmpl/-/tmpl-1.0.4.tgz#23640dd7b42d00433911140820e5cf440e521dd1"
@@ -3494,6 +3514,10 @@ underscore@~1.6.0:
34943514
version "1.6.0"
34953515
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.6.0.tgz#8b38b10cacdef63337b8b24e4ff86d45aea529a8"
34963516

3517+
universalify@^0.1.0:
3518+
version "0.1.1"
3519+
resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.1.tgz#fa71badd4437af4c148841e3b3b165f9e9e590b7"
3520+
34973521
user-home@^1.1.1:
34983522
version "1.1.1"
34993523
resolved "https://registry.yarnpkg.com/user-home/-/user-home-1.1.1.tgz#2b5be23a32b63a7c9deb8d0f28d485724a3df190"

0 commit comments

Comments
 (0)