Skip to content

Commit e5fb37d

Browse files
committed
Make testUtils understand custom parsers
Also completes the API, passing the missing `stats` function.
1 parent 51013b8 commit e5fb37d

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/testUtils.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,23 @@ function runTest(dirName, transformName, options, testFilePrefix) {
4646
'utf8'
4747
);
4848
// Assumes transform is one level up from __tests__ directory
49-
let transform = require(path.join(dirName, '..', transformName + '.js'));
49+
const module = require(path.join(dirName, '..', transformName + '.js'));
5050
// Handle ES6 modules using default export for the transform
51-
if (transform.default) {
52-
transform = transform.default;
53-
}
51+
const transform = module.default ? module.default : module;
5452

5553
// Jest resets the module registry after each test, so we need to always get
5654
// a fresh copy of jscodeshift on every test run.
57-
const jscodeshift = require('./core');
55+
let jscodeshift = require('./core');
56+
if (module.parser) {
57+
jscodeshift = jscodeshift.withParser(module.parser);
58+
}
5859

5960
const output = transform(
6061
{path: inputPath, source},
61-
{jscodeshift},
62+
{
63+
jscodeshift,
64+
stats: () => {},
65+
},
6266
options || {}
6367
);
6468
expect((output || '').trim()).toEqual(expectedOutput.trim());

0 commit comments

Comments
 (0)