Last active
April 18, 2026 20:48
-
-
Save brunocroh/2fd57e2730a3d4048d19db7d1bd606dd to your computer and use it in GitHub Desktop.
script to migrate test structure on userland-migrations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import fs from 'node:fs'; | |
| const baseUrl = './recipes/'; | |
| const recipes = fs.readdirSync('./recipes/'); | |
| const IGNORE = ['correct-ts-specifiers']; | |
| for (const dir of recipes) { | |
| if (IGNORE.includes(dir)) continue; | |
| const recipeTests = fs.readdirSync(`${baseUrl}${dir}/tests`); | |
| if ( | |
| recipeTests.length != 2 || | |
| !recipeTests.includes('expected') || | |
| !recipeTests.includes('input') | |
| ) | |
| continue; | |
| for (const input of fs.readdirSync(`${baseUrl}${dir}/tests/input`)) { | |
| let [filename, ext] = input.split('.'); | |
| if (ext === 'cjs' || ext === 'mjs') { | |
| filename = `${filename}-${ext === 'cjs' ? 'common' : 'module'}`; | |
| } | |
| fs.mkdirSync(`${baseUrl}${dir}/tests/${filename}/`); | |
| fs.copyFileSync( | |
| `${baseUrl}${dir}/tests/input/${input}`, | |
| `${baseUrl}${dir}/tests/${filename}/input.${ext}`, | |
| ); | |
| fs.copyFileSync( | |
| `${baseUrl}${dir}/tests/expected/${input}`, | |
| `${baseUrl}${dir}/tests/${filename}/expected.${ext}`, | |
| ); | |
| fs.rm(`${baseUrl}${dir}/tests/input`, { | |
| recursive: true, | |
| force: true, | |
| }); | |
| fs.rm(`${baseUrl}${dir}/tests/expected`, { | |
| recursive: true, | |
| force: true, | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment