Skip to content

Instantly share code, notes, and snippets.

@brunocroh
Last active April 18, 2026 20:48
Show Gist options
  • Select an option

  • Save brunocroh/2fd57e2730a3d4048d19db7d1bd606dd to your computer and use it in GitHub Desktop.

Select an option

Save brunocroh/2fd57e2730a3d4048d19db7d1bd606dd to your computer and use it in GitHub Desktop.
script to migrate test structure on userland-migrations
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