@@ -189,7 +189,6 @@ QUnit.module('codemod-cli', function(hooks) {
189189 QUnit . test (
190190 'transform should receive options from ${name}.options.json' ,
191191 wrap ( function * ( assert ) {
192- const realCodemodProjectPath = fs . realpathSync ( codemodProject . path ( ) ) ;
193192 const expectedReplacement = 'AAAAHHHHHH' ;
194193
195194 yield execa ( EXECUTABLE_PATH , [ 'generate' , 'codemod' , 'main' ] ) ;
@@ -199,10 +198,10 @@ QUnit.module('codemod-cli', function(hooks) {
199198 main : {
200199 'index.js' : `
201200 const { getParser } = require('codemod-cli').jscodeshift;
202-
203- module.exports = function transformer(file, api, options) {
201+ const { getOptions } = require('codemod-cli');
202+ module.exports = function transformer(file, api) {
203+ const options = getOptions();
204204 const j = getParser(api);
205-
206205 return j(file.source)
207206 .find(j.Literal)
208207 .forEach(path => {
@@ -336,10 +335,7 @@ QUnit.module('codemod-cli', function(hooks) {
336335 'works with globs' ,
337336 wrap ( function * ( assert ) {
338337 userProject . write ( {
339- foo : {
340- 'something.js' : 'let blah = bar' ,
341- 'other.js' : 'let blah = bar' ,
342- } ,
338+ foo : { 'something.js' : 'let blah = bar' , 'other.js' : 'let blah = bar' } ,
343339 } ) ;
344340
345341 yield execa ( codemodProject . path ( 'bin/cli.js' ) , [ 'main' , 'foo/*thing.js' ] ) ;
@@ -397,6 +393,49 @@ QUnit.module('codemod-cli', function(hooks) {
397393 } )
398394 ) ;
399395
396+ QUnit . test (
397+ 'runs transform with options' ,
398+ wrap ( function * ( assert ) {
399+ codemodProject . write ( {
400+ transforms : {
401+ main : {
402+ 'index.js' : `
403+ const { getParser } = require('codemod-cli').jscodeshift;
404+ const { getOptions } = require('codemod-cli');
405+ module.exports = function transformer(file, api) {
406+ const options = getOptions();
407+ const j = getParser(api);
408+ return j(file.source)
409+ .find(j.Literal)
410+ .forEach(path => {
411+ path.replace(
412+ j.stringLiteral(options.biz + options.baz)
413+ );
414+ })
415+ .toSource();
416+ }
417+ ` ,
418+ } ,
419+ } ,
420+ } ) ;
421+ userProject . write ( {
422+ foo : { 'something.js' : `let blah = "bar";` } ,
423+ } ) ;
424+
425+ yield CodemodCLI . runTransform ( codemodProject . path ( 'bin' ) , 'main' , [
426+ '--biz' ,
427+ 'A' ,
428+ '--baz' ,
429+ 'B' ,
430+ 'foo/*ing.[jt]s' ,
431+ ] ) ;
432+
433+ assert . deepEqual ( userProject . read ( ) , {
434+ foo : { 'something.js' : `let blah = "AB";` } ,
435+ } ) ;
436+ } )
437+ ) ;
438+
400439 QUnit . test (
401440 'runs transform against class syntax' ,
402441 wrap ( function * ( assert ) {
0 commit comments