Skip to content

Commit

Permalink
chore: output result
Browse files Browse the repository at this point in the history
  • Loading branch information
thepassle committed Jul 17, 2024
1 parent 6ae2f53 commit 598ea99
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions scripts/scaffold-codemod.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import fs from 'fs';
import jscodeshift from 'jscodeshift';

/**
* Usage:
* node scripts/scaffold-codemod.js <name>
*
* e.g.:
* node scripts/scaffold-codemod.js is-whitespace
*/

const name = process.argv[2];

/** @param {string} s */
Expand All @@ -13,6 +21,10 @@ fs.writeFileSync(
`./test/fixtures/${name}/case-1/before.js`,
'// Add the code you want to transform here',
);
fs.writeFileSync(
`./test/fixtures/${name}/case-1/result.js`,
'// This file will contain the actual result of the codemod transformation after running the tests, this is expected to be equal to the `after.js` file. This file exists for easy debugging purposes.',
);
fs.writeFileSync(
`./test/fixtures/${name}/case-1/after.js`,
'// Add the expected output here',
Expand Down
4 changes: 4 additions & 0 deletions test/codemod.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ describe('codemod', () => {
},
jscodeshift,
});
fs.writeFileSync(
`./test/fixtures/${codemod.name}/${fixture}/result.js`,
result,
);
} catch (e) {
throw new Error(
`Codemod "${codemod.name}" failed on fixture "${fixture}"`,
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/is-whitespace/case-1/result.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let str = ' ';
let str2 = 'Hello';

console.log(str1.trim() === ''); // true
console.log(str2.trim() === ''); // false

0 comments on commit 598ea99

Please sign in to comment.