@@ -8,8 +8,38 @@ const tmp = require('tmp');
88const inputFile = path . join ( process . cwd ( ) , '__testfixtures__/final-boss.input.js' ) ;
99const outputFile = path . join ( process . cwd ( ) , '__testfixtures__/final-boss.output.js' ) ;
1010
11+ let tmpPath ;
12+
13+ function run ( ) {
14+ let stdout = '' ;
15+ let stderr = '' ;
16+
17+ return new Promise ( resolve => {
18+ let ps = cp . spawn ( 'node' , [
19+ path . join ( process . cwd ( ) , 'bin/ember-modules-codemod' )
20+ ] , {
21+ cwd : tmpPath
22+ } ) ;
23+
24+ ps . stdout . on ( 'data' , data => {
25+ stdout += data . toString ( ) ;
26+ } ) ;
27+
28+ ps . stderr . on ( 'data' , data => {
29+ stderr += data . toString ( ) ;
30+ } ) ;
31+
32+ ps . on ( 'exit' , code => {
33+ resolve ( {
34+ exitCode : code ,
35+ stdout,
36+ stderr
37+ } ) ;
38+ } ) ;
39+ } ) ;
40+ }
41+
1142describe ( 'bin acceptance' , function ( ) {
12- let tmpPath ;
1343 let tmpPackageJson ;
1444
1545 beforeEach ( function ( ) {
@@ -19,26 +49,10 @@ describe('bin acceptance', function() {
1949 } ) ;
2050
2151 it ( 'handles non-ember projects' , function ( ) {
22- let stderr = '' ;
23- let exitCode ;
24-
25- return new Promise ( resolve => {
26- let ps = cp . spawn ( 'node' , [
27- path . join ( process . cwd ( ) , 'bin/ember-modules-codemod' )
28- ] , {
29- cwd : tmpPath
30- } ) ;
31-
32- ps . stderr . on ( 'data' , data => {
33- stderr += data . toString ( ) ;
34- } ) ;
52+ return run ( ) . then ( result => {
53+ let exitCode = result . exitCode ;
54+ let stderr = result . stderr ;
3555
36- ps . on ( 'exit' , ( code , signal ) => {
37- exitCode = code ;
38-
39- resolve ( ) ;
40- } ) ;
41- } ) . then ( ( ) => {
4256 expect ( exitCode ) . not . toEqual ( 0 ) ;
4357
4458 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,26 +69,10 @@ describe('bin acceptance', function() {
5569 } ) ;
5670
5771 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- } ) ;
72+ return run ( ) . then ( result => {
73+ let exitCode = result . exitCode ;
74+ let stderr = result . stderr ;
6775
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 ( ( ) => {
7876 expect ( exitCode ) . toEqual ( 0 ) ;
7977
8078 // jscodeshift can process in any order
@@ -102,26 +100,10 @@ describe('bin acceptance', function() {
102100 } ) ;
103101
104102 it ( 'works' , function ( ) {
105- let stdout = '' ;
106- let exitCode ;
107-
108- return new Promise ( resolve => {
109- let ps = cp . spawn ( 'node' , [
110- path . join ( process . cwd ( ) , 'bin/ember-modules-codemod' )
111- ] , {
112- cwd : tmpPath
113- } ) ;
114-
115- ps . stdout . on ( 'data' , data => {
116- stdout += data . toString ( ) ;
117- } ) ;
118-
119- ps . on ( 'exit' , ( code , signal ) => {
120- exitCode = code ;
121-
122- resolve ( ) ;
123- } ) ;
124- } ) . then ( ( ) => {
103+ return run ( ) . then ( result => {
104+ let exitCode = result . exitCode ;
105+ let stdout = result . stdout ;
106+
125107 expect ( exitCode ) . toEqual ( 0 ) ;
126108
127109 expect ( stdout ) . toMatch ( 'Done! All uses of the Ember global have been updated.\n' ) ;
0 commit comments