Skip to content

Commit 18c37e0

Browse files
author
Robert Jackson
committed
Add support for custom paths in runTransformTest
1 parent ab76ecc commit 18c37e0

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

commands/local/generate/codemod.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ function jsHandler(options) {
6464
6565
runTransformTest({
6666
name: '${codemodName}',
67+
path: require.resolve('./index.js'),
6768
});
6869
`,
6970
'utf8'

src/test-support/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function transformDetails(options) {
44
const { getTransformType, getTransformPath } = require('../transform-support');
55
const path = require('path');
66

7-
let transformPath = getTransformPath(process.cwd(), options.name);
7+
let transformPath = options.path ? options.path : getTransformPath(process.cwd(), options.name);
88
let root = path.dirname(transformPath);
99
let transformType = getTransformType(transformPath);
1010

tests/cli-test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,14 @@ QUnit.module('codemod-cli', function (hooks) {
258258
assert.equal(result.exitCode, 0, 'exited with zero');
259259
});
260260

261+
QUnit.test('should pass for an empty codemod in a custom directory', async function (assert) {
262+
await execa(EXECUTABLE_PATH, ['generate', 'codemod', 'main', '--codemod-dir', 'other-transform-path']);
263+
await execa(EXECUTABLE_PATH, ['generate', 'fixture', 'main', 'this-dot-owner', '--codemod-dir', 'other-transform-path']);
264+
265+
let result = await execa(EXECUTABLE_PATH, ['test']);
266+
assert.equal(result.exitCode, 0, 'exited with zero');
267+
});
268+
261269
QUnit.test('should fail when input and output do not match', async function (assert) {
262270
await execa(EXECUTABLE_PATH, ['generate', 'codemod', 'main']);
263271
await execa(EXECUTABLE_PATH, ['generate', 'fixture', 'main', 'this-dot-owner']);

0 commit comments

Comments
 (0)