Skip to content

Commit 2d64288

Browse files
authored
Merge pull request #32 from cyril-sf/cyril/custom-path
Specify a path
2 parents bb21d2d + cf39b59 commit 2d64288

4 files changed

Lines changed: 50 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ Markdown report if any unknown globals are discovered.
8282
```sh
8383
yarn test // run all tests once
8484
yarn test -- --watchAll // continuously run tests
85+
yarn test:debug // run tests in debug mode (using Chrome's chrome://inspect tab)
8586
```
8687
8788
Tests for this codemod work by comparing a paired input and output file in the `__testfixtures__` directory. Pre-transform files should be of format `<test-name>.input.js`, expected output after the transform should be named `<test-name>.output.js`. Files must use the same `<test-name>` in their names so they can be compared.

__tests__/bin-test.js

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ const originalCwd = process.cwd();
99

1010
let tmpPath;
1111

12-
function run() {
12+
function run(codemodArgs) {
1313
let stdout = '';
1414
let stderr = '';
1515

1616
return new Promise(resolve => {
17-
let ps = cp.spawn('node', [
18-
path.join(originalCwd, 'bin/ember-modules-codemod')
19-
], {
17+
let codemodCmd = [path.join(originalCwd, 'bin/ember-modules-codemod')];
18+
if(codemodArgs) {
19+
codemodCmd = codemodCmd.concat(codemodArgs);
20+
}
21+
let ps = cp.spawn('node', codemodCmd, {
2022
cwd: tmpPath
2123
});
2224

@@ -153,5 +155,36 @@ describe('bin acceptance', function() {
153155
});
154156
});
155157
});
158+
159+
describe('with a custom path', function() {
160+
let tmpFile;
161+
const inputFile = path.join(originalCwd, '__testfixtures__/final-boss.input.js');
162+
const outputFile = path.join(originalCwd, '__testfixtures__/final-boss.output.js');
163+
164+
165+
beforeEach(function() {
166+
fs.ensureDirSync(path.join(tmpPath, 'custom-path'));
167+
168+
tmpFile = path.join(tmpPath, 'custom-path/final-boss.js');
169+
170+
fs.copySync(
171+
inputFile,
172+
tmpFile
173+
);
174+
});
175+
176+
it('works', function() {
177+
return run('custom-path').then(result => {
178+
let exitCode = result.exitCode;
179+
let stdout = result.stdout;
180+
181+
expect(exitCode).toEqual(0);
182+
183+
expect(stdout).toMatch('Done! All uses of the Ember global have been updated.\n');
184+
185+
expect(fs.readFileSync(tmpFile, 'utf8')).toEqual(fs.readFileSync(outputFile, 'utf8'));
186+
});
187+
});
188+
});
156189
});
157190
});

bin/ember-modules-codemod.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,16 @@ try {
2222
EMBER_MODULES_CODEMOD: true
2323
}, process.env);
2424

25-
let transform = execa(binPath, ["-t", transformPath, "app", "addon", "addon-test-support", "tests", "test-support", "lib"], {
25+
const args = process.argv;
26+
let jscodeshiftPaths;
27+
if (args[2]) {
28+
jscodeshiftPaths = [args[2]];
29+
} else {
30+
jscodeshiftPaths = ["app", "addon", "addon-test-support", "tests", "test-support", "lib"];
31+
}
32+
const jscodeshiftArgs = ["-t", transformPath].concat(jscodeshiftPaths);
33+
34+
let transform = execa(binPath, jscodeshiftArgs, {
2635
stdio: "inherit",
2736
env: env
2837
});

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"repository": "https://github.com/ember-cli/ember-modules-codemod",
77
"bin": "./bin/ember-modules-codemod.js",
88
"scripts": {
9-
"test": "jest"
9+
"test": "jest",
10+
"test:debug": "node --inspect node_modules/.bin/jest --runInBand"
1011
},
1112
"dependencies": {
1213
"chalk": "^1.1.3",

0 commit comments

Comments
 (0)