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+ } ) ;
0 commit comments