From 598ea995915e504b38377e94aace589192ca4e6d Mon Sep 17 00:00:00 2001 From: thepassle Date: Wed, 17 Jul 2024 16:14:01 +0200 Subject: [PATCH] chore: output result --- scripts/scaffold-codemod.js | 12 ++++++++++++ test/codemod.test.js | 4 ++++ test/fixtures/is-whitespace/case-1/result.js | 5 +++++ 3 files changed, 21 insertions(+) create mode 100644 test/fixtures/is-whitespace/case-1/result.js diff --git a/scripts/scaffold-codemod.js b/scripts/scaffold-codemod.js index d5bca1e..3a9ea5b 100644 --- a/scripts/scaffold-codemod.js +++ b/scripts/scaffold-codemod.js @@ -1,6 +1,14 @@ import fs from 'fs'; import jscodeshift from 'jscodeshift'; +/** + * Usage: + * node scripts/scaffold-codemod.js + * + * e.g.: + * node scripts/scaffold-codemod.js is-whitespace + */ + const name = process.argv[2]; /** @param {string} s */ @@ -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', diff --git a/test/codemod.test.js b/test/codemod.test.js index af467e6..7c81fab 100644 --- a/test/codemod.test.js +++ b/test/codemod.test.js @@ -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}"`, diff --git a/test/fixtures/is-whitespace/case-1/result.js b/test/fixtures/is-whitespace/case-1/result.js new file mode 100644 index 0000000..ea0fccc --- /dev/null +++ b/test/fixtures/is-whitespace/case-1/result.js @@ -0,0 +1,5 @@ +let str = ' '; +let str2 = 'Hello'; + +console.log(str1.trim() === ''); // true +console.log(str2.trim() === ''); // false