1+ const assertDiff = require ( 'assert-diff' ) ;
2+ const fixturify = require ( 'fixturify' ) ;
3+ const fse = require ( 'fs-extra' ) ;
4+ const path = require ( 'path' ) ;
5+ const Migrator = require ( '../../../lib/migrator' ) ;
6+
7+ assertDiff . options . strict = true ;
8+
9+ describe ( 'structure = nested' , function ( ) {
10+ beforeEach ( function ( ) {
11+ this . tmpPath = 'tmp/process-files' ;
12+ fse . mkdirsSync ( this . tmpPath ) ;
13+ } ) ;
14+
15+ afterEach ( function ( ) {
16+ fse . removeSync ( this . tmpPath ) ;
17+ } ) ;
18+
19+
20+ describe ( 'For an app with component classes written in JavaScript' , function ( ) {
21+ beforeEach ( function ( ) {
22+ const fixturePath = path . resolve ( __dirname , '../../fixtures/example-js' ) ;
23+
24+ // Find input and output files
25+ const input = require ( `${ fixturePath } /input` ) ;
26+ this . expectedOutput = require ( `${ fixturePath } /classic-to-nested` ) ;
27+
28+ // Copy the input file to the temporary folder
29+ fixturify . writeSync ( this . tmpPath , input ) ;
30+
31+ // Create an instance of the Migrator class
32+ this . migrator = new Migrator ( {
33+ projectRoot : this . tmpPath ,
34+ structure : 'nested'
35+ } ) ;
36+ } ) ;
37+
38+
39+ it ( 'Codemod works as expected' , async function ( ) {
40+ await this . migrator . execute ( ) ;
41+
42+ const actualOutput = fixturify . readSync ( this . tmpPath ) ;
43+
44+ assertDiff . deepEqual ( actualOutput , this . expectedOutput ) ;
45+ } ) ;
46+
47+
48+ it ( 'Codemod is idempotent' , async function ( ) {
49+ await this . migrator . execute ( ) ;
50+ await this . migrator . execute ( ) ;
51+
52+ const actualOutput = fixturify . readSync ( this . tmpPath ) ;
53+
54+ assertDiff . deepEqual ( actualOutput , this . expectedOutput ) ;
55+ } ) ;
56+ } ) ;
57+
58+
59+ describe ( 'For an app with component classes written in TypeScript' , function ( ) {
60+ beforeEach ( function ( ) {
61+ const fixturePath = path . resolve ( __dirname , '../../fixtures/example-ts' ) ;
62+
63+ // Find input and output files
64+ const input = require ( `${ fixturePath } /input` ) ;
65+ this . expectedOutput = require ( `${ fixturePath } /classic-to-nested` ) ;
66+
67+ // Copy the input file to the temporary folder
68+ fixturify . writeSync ( this . tmpPath , input ) ;
69+
70+ // Create an instance of the Migrator class
71+ this . migrator = new Migrator ( {
72+ projectRoot : this . tmpPath ,
73+ structure : 'nested'
74+ } ) ;
75+ } ) ;
76+
77+
78+ it ( 'Codemod works as expected' , async function ( ) {
79+ await this . migrator . execute ( ) ;
80+
81+ const actualOutput = fixturify . readSync ( this . tmpPath ) ;
82+
83+ assertDiff . deepEqual ( actualOutput , this . expectedOutput ) ;
84+ } ) ;
85+
86+
87+ it ( 'Codemod is idempotent' , async function ( ) {
88+ await this . migrator . execute ( ) ;
89+ await this . migrator . execute ( ) ;
90+
91+ const actualOutput = fixturify . readSync ( this . tmpPath ) ;
92+
93+ assertDiff . deepEqual ( actualOutput , this . expectedOutput ) ;
94+ } ) ;
95+ } ) ;
96+ } ) ;
0 commit comments