@@ -7,20 +7,19 @@ const acorn = require('acorn');
77
88const { commonjs } = require ( './helpers/util.js' ) ;
99
10- const { createAvaAssertions } = require ( './helpers/ava-assertions.js' ) ;
11-
12- const t = createAvaAssertions ( ) ;
13-
1410process . chdir ( __dirname ) ;
15-
1611const transformContext = {
1712 error : ( base , props ) => {
1813 let error = base ;
1914 if ( ! ( base instanceof Error ) ) error = Object . assign ( new Error ( base . message ) , base ) ;
2015 if ( props ) Object . assign ( error , props ) ;
2116 throw error ;
2217 } ,
23- load : ( { id } ) => Promise . resolve ( { id, meta : { } } ) ,
18+ load : ( { id } ) =>
19+ Promise . resolve ( {
20+ id,
21+ meta : { }
22+ } ) ,
2423 parse : ( input , options ) =>
2524 acorn . parse ( input , {
2625 ecmaVersion : 9 ,
@@ -33,78 +32,81 @@ const transformContext = {
3332 } )
3433} ;
3534
36- // Do not run on Windows as we have full path names in the output
37- if ( path . sep === '/' ) {
38- fs . readdirSync ( './fixtures/form' ) . forEach ( ( dir ) => {
39- let config ;
40-
41- try {
42- config = require ( `./fixtures/form/${ dir } /_config.js` ) ;
43- } catch ( err ) {
44- config = { } ;
45- }
46-
47- const inputEntries = [ ] ;
48-
49- if ( typeof config . multi === 'object' ) {
50- for ( const [ key , entry ] of Object . entries ( config . multi ) ) {
51- inputEntries . push ( [ key , `fixtures/form/${ dir } /${ entry } ` ] ) ;
52- }
53- } else {
54- inputEntries . push ( [ 'output' , `fixtures/form/${ dir } /input.js` ] ) ;
35+ const runFormTest = test . skipIf ( path . sep !== '/' ) ;
36+
37+ fs . readdirSync ( './fixtures/form' ) . forEach ( ( dir ) => {
38+ let config ;
39+ try {
40+ config = require ( `./fixtures/form/${ dir } /_config.js` ) ;
41+ } catch ( err ) {
42+ config = { } ;
43+ }
44+ const inputEntries = [ ] ;
45+ if ( typeof config . multi === 'object' ) {
46+ for ( const [ key , entry ] of Object . entries ( config . multi ) ) {
47+ inputEntries . push ( [ key , `fixtures/form/${ dir } /${ entry } ` ] ) ;
5548 }
56-
57- ( config . solo ? test . only : test ) ( dir , ( ) =>
58- Promise . all (
59- inputEntries . map ( async ( [ outputName , id ] ) => {
60- const { buildStart, transform } = commonjs ( config . options ) ;
61- buildStart . call ( { meta : { rollupVersion : '99.0.0' } } , { plugins : [ ] } ) ;
62- transformContext . getModuleInfo = ( moduleId ) => {
63- return {
64- isEntry : config . entry && moduleId === id ,
65- importers :
66- config . importers && config . importers [ outputName ]
67- ? config . importers [ outputName ] . map ( ( x ) => `fixtures/form/${ dir } /${ x } ` )
68- : [ ] ,
69- meta : { }
70- } ;
71- } ;
72- const input = fs . readFileSync ( id , 'utf-8' ) ;
73-
74- let outputFile = `fixtures/form/${ dir } /${ outputName } ` ;
75- if ( fs . existsSync ( `${ outputFile } .${ process . platform } .js` ) ) {
76- outputFile += `.${ process . platform } .js` ;
77- } else {
78- outputFile += '.js' ;
79- }
80-
81- const expected = fs . readFileSync ( outputFile , 'utf-8' ) . trim ( ) ;
82- // eslint-disable-next-line no-await-in-loop
83- const transformed = await transform . call ( transformContext , input , id ) ;
84- let actual = ( transformed ? transformed . code : input ) . trim ( ) . replace ( / \0 / g, '_' ) ;
85- const cwd = process . cwd ( ) ;
86- while ( actual . indexOf ( cwd ) >= 0 ) {
87- actual = actual . replace ( process . cwd ( ) , 'CWD' ) ;
49+ } else {
50+ inputEntries . push ( [ 'output' , `fixtures/form/${ dir } /input.js` ] ) ;
51+ }
52+ ( config . solo ? runFormTest . only : runFormTest ) ( dir , ( ) =>
53+ Promise . all (
54+ inputEntries . map ( async ( [ outputName , id ] ) => {
55+ const { buildStart, transform } = commonjs ( config . options ) ;
56+ buildStart . call (
57+ {
58+ meta : {
59+ rollupVersion : '99.0.0'
60+ }
61+ } ,
62+ {
63+ plugins : [ ]
8864 }
89-
90- // uncomment to update snapshots
91- // fs.writeFileSync(outputFile, `${actual}\n`);
92-
93- // trim whitespace from line endings,
94- // this will benefit issues like `form/try-catch-remove` where whitespace is left in the line,
95- // and testing on windows (\r\n)
96- t . is (
97- actual
98- . split ( '\n' )
99- . map ( ( x ) => x . trimEnd ( ) )
100- . join ( '\n' ) ,
101- expected
102- . split ( '\n' )
103- . map ( ( x ) => x . trimEnd ( ) )
104- . join ( '\n' )
105- ) ;
106- } )
107- )
108- ) ;
109- } ) ;
110- }
65+ ) ;
66+ transformContext . getModuleInfo = ( moduleId ) => {
67+ return {
68+ isEntry : config . entry && moduleId === id ,
69+ importers :
70+ config . importers && config . importers [ outputName ]
71+ ? config . importers [ outputName ] . map ( ( x ) => `fixtures/form/${ dir } /${ x } ` )
72+ : [ ] ,
73+ meta : { }
74+ } ;
75+ } ;
76+ const input = fs . readFileSync ( id , 'utf-8' ) ;
77+ let outputFile = `fixtures/form/${ dir } /${ outputName } ` ;
78+ if ( fs . existsSync ( `${ outputFile } .${ process . platform } .js` ) ) {
79+ outputFile += `.${ process . platform } .js` ;
80+ } else {
81+ outputFile += '.js' ;
82+ }
83+ const expected = fs . readFileSync ( outputFile , 'utf-8' ) . trim ( ) ;
84+ // eslint-disable-next-line no-await-in-loop
85+ const transformed = await transform . call ( transformContext , input , id ) ;
86+ let actual = ( transformed ? transformed . code : input ) . trim ( ) . replace ( / \0 / g, '_' ) ;
87+ const cwd = process . cwd ( ) ;
88+ while ( actual . indexOf ( cwd ) >= 0 ) {
89+ actual = actual . replace ( process . cwd ( ) , 'CWD' ) ;
90+ }
91+
92+ // uncomment to update snapshots
93+ // fs.writeFileSync(outputFile, `${actual}\n`);
94+
95+ // trim whitespace from line endings,
96+ // this will benefit issues like `form/try-catch-remove` where whitespace is left in the line,
97+ // and testing on windows (\r\n)
98+ expect (
99+ actual
100+ . split ( '\n' )
101+ . map ( ( x ) => x . trimEnd ( ) )
102+ . join ( '\n' )
103+ ) . toBe (
104+ expected
105+ . split ( '\n' )
106+ . map ( ( x ) => x . trimEnd ( ) )
107+ . join ( '\n' )
108+ ) ;
109+ } )
110+ )
111+ ) ;
112+ } ) ;
0 commit comments