Commit 981e1d06 authored by nanahira's avatar nanahira

allow yrp subdir

parent 2d0e8878
Pipeline #42895 passed with stages
in 2 minutes and 23 seconds
...@@ -11,18 +11,20 @@ async function main() { ...@@ -11,18 +11,20 @@ async function main() {
process.exit(1); process.exit(1);
} }
for (const yrpFilename of yrpFilenames) { for (const yrpFilename of yrpFilenames) {
const yrpParts = yrpFilename.split("/").filter((part) => part.length > 0);
const fullPath = path.resolve( const fullPath = path.resolve(
process.cwd(), process.cwd(),
"tests", "tests",
"yrp", "yrp",
`${yrpFilename}.yrp`, path.join(...yrpParts) + ".yrp",
); );
const destPath = path.resolve( const destPath = path.resolve(
process.cwd(), process.cwd(),
"tests", "tests",
"yrp-info", "yrp-info",
`${yrpFilename}.yaml`, path.join(...yrpParts) + ".yaml",
); );
await fs.promises.mkdir(path.dirname(destPath), { recursive: true });
console.log(`Will save YRP info from ${fullPath} to ${destPath}`); console.log(`Will save YRP info from ${fullPath} to ${destPath}`);
await createTest({ yrp: fullPath }, async (test) => { await createTest({ yrp: fullPath }, async (test) => {
const info = toYrpInfo(test); const info = toYrpInfo(test);
......
...@@ -7,22 +7,38 @@ import fs from "node:fs"; ...@@ -7,22 +7,38 @@ import fs from "node:fs";
describe("YRP", () => { describe("YRP", () => {
const yrpDirPath = path.resolve(process.cwd(), "tests", "yrp"); const yrpDirPath = path.resolve(process.cwd(), "tests", "yrp");
const yrpDir = readdirSync(yrpDirPath); const listYrpFiles = (dirPath: string, basePath: string): string[] => {
for (const yrpFilename of yrpDir) { const entries = readdirSync(dirPath, { withFileTypes: true });
if (!yrpFilename.endsWith(".yrp")) continue; const results: string[] = [];
const testName = `YRP: ${yrpFilename}`; for (const entry of entries) {
const entryPath = path.join(dirPath, entry.name);
if (entry.isDirectory()) {
results.push(...listYrpFiles(entryPath, basePath));
continue;
}
if (entry.isFile() && entry.name.endsWith(".yrp")) {
results.push(path.relative(basePath, entryPath));
}
}
return results;
};
const yrpFiles = listYrpFiles(yrpDirPath, yrpDirPath).sort();
for (const yrpRelativePath of yrpFiles) {
const testName = `YRP: ${yrpRelativePath}`;
it(testName, async () => { it(testName, async () => {
const yrpPath = path.resolve(yrpDirPath, yrpFilename); const yrpPath = path.resolve(yrpDirPath, yrpRelativePath);
await createTest({ yrp: yrpPath }, async (test) => { await createTest({ yrp: yrpPath }, async (test) => {
const yrpInfoPath = path.resolve( const yrpInfoPath = path.resolve(
__dirname, process.cwd(),
"tests",
"yrp-info", "yrp-info",
yrpFilename.slice(0, -4) + ".yaml", yrpRelativePath.replace(/\.yrp$/i, ".yaml"),
); );
const currentInfo = toYrpInfo(test); const currentInfo = toYrpInfo(test);
const hasYrpInfo = existsSync(yrpInfoPath); const hasYrpInfo = existsSync(yrpInfoPath);
console.log( console.log(
`Testing YRP: ${yrpFilename}\nYRP info yaml: ${hasYrpInfo ? "available" : "none"}\n${currentInfo.snapshotText}`, `Testing YRP: ${yrpRelativePath}\nYRP info yaml: ${hasYrpInfo ? "available" : "none"}\n${currentInfo.snapshotText}`,
); );
if (hasYrpInfo) { if (hasYrpInfo) {
// do further tests // do further tests
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment