File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55const { runInlineTest } = require ( 'jscodeshift/dist/testUtils' ) ;
66const fs = require ( 'fs-extra' ) ;
77const path = require ( 'path' ) ;
8+ const globby = require ( 'globby' ) ;
89
910function transformDetails ( options ) {
1011 let root = process . cwd ( ) + `/transforms/${ options . name } /` ;
@@ -23,8 +24,13 @@ function jscodeshiftTest(options) {
2324 let transform = require ( details . transformPath ) ;
2425
2526 describe ( details . name , function ( ) {
26- fs . readdirSync ( details . fixtureDir )
27- . filter ( filename => / \. i n p u t $ / . test ( path . basename ( filename , path . extname ( filename ) ) ) )
27+ globby
28+ . sync ( '**/*.input.*' , {
29+ cwd : details . fixtureDir ,
30+ absolute : true ,
31+ transform : entry =>
32+ entry . slice ( entry . indexOf ( '__testfixtures__' ) + '__testfixtures__' . length + 1 ) ,
33+ } )
2834 . forEach ( filename => {
2935 let extension = path . extname ( filename ) ;
3036 let testName = filename . replace ( `.input${ extension } ` , '' ) ;
Original file line number Diff line number Diff line change @@ -225,6 +225,48 @@ QUnit.module('codemod-cli', function(hooks) {
225225 assert . equal ( result . code , 0 , 'exited with zero' ) ;
226226 } )
227227 ) ;
228+
229+ QUnit . test (
230+ 'transform should receive a subfolder file path in tests' ,
231+ wrap ( function * ( assert ) {
232+ const realCodemodProjectPath = fs . realpathSync ( codemodProject . path ( ) ) ;
233+ const expectedPath = `${ realCodemodProjectPath } /transforms/main/__testfixtures__/foo/basic.input.js` ;
234+
235+ yield execa ( EXECUTABLE_PATH , [ 'generate' , 'codemod' , 'main' ] ) ;
236+
237+ codemodProject . write ( {
238+ transforms : {
239+ main : {
240+ 'index.js' : `
241+ const { getParser } = require('codemod-cli').jscodeshift;
242+
243+ module.exports = function transformer(file, api) {
244+ const j = getParser(api);
245+
246+ return j(file.source)
247+ .find(j.Literal)
248+ .forEach(path => {
249+ path.replace(
250+ j.stringLiteral(file.path)
251+ );
252+ })
253+ .toSource();
254+ }
255+ ` ,
256+ __testfixtures__ : {
257+ foo : {
258+ 'basic.input.js' : 'var foo = "foo";' ,
259+ 'basic.output.js' : `var foo = "${ expectedPath } ";` ,
260+ } ,
261+ } ,
262+ } ,
263+ } ,
264+ } ) ;
265+
266+ let result = yield execa ( EXECUTABLE_PATH , [ 'test' ] ) ;
267+ assert . equal ( result . code , 0 , 'exited with zero' ) ;
268+ } )
269+ ) ;
228270 } ) ;
229271 } ) ;
230272
You can’t perform that action at this time.
0 commit comments