@@ -5,38 +5,74 @@ const fs = require('fs-extra');
55const cp = require ( 'child_process' ) ;
66const 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+
811describe ( '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} ) ;
0 commit comments