Skip to content

Commit 05c07f6

Browse files
committed
cleanup
1 parent c5c3a66 commit 05c07f6

1 file changed

Lines changed: 43 additions & 50 deletions

File tree

tests/unittests/resources.mjs

Lines changed: 43 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,58 +6,51 @@ import { DefaultSuites } from "../../suites/default-suites.mjs";
66

77
const ROOT_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../");
88

9-
const Suites = {
10-
ExperimentalSuites,
11-
DefaultSuites,
12-
};
9+
const Suites = [...ExperimentalSuites, ...DefaultSuites];
1310

14-
for (const [name, suites] of Object.entries(Suites)) {
15-
describe(`${name}-resources`, () => {
16-
it("should have resources.txt listing only valid files via local filesystem", async function () {
17-
// validating all resource files can take a bit longer than the default timeout.
18-
this.timeout(10000);
19-
const brokenResourcesList = [];
20-
for (const suite of suites) {
21-
if (!suite.resources)
22-
continue;
23-
const resourcesPath = path.resolve(ROOT_DIR, suite.resources);
24-
let text;
25-
try {
26-
text = await fs.readFile(resourcesPath, "utf-8");
27-
} catch (error) {
28-
brokenResourcesList.push(`${suite.resources} (for ${suite.name}) [error: ${error.message}]`);
29-
continue;
30-
}
11+
describe("resources", () => {
12+
it("should have resources.txt listing only valid files via local filesystem", async function () {
13+
// validating all resource files can take a bit longer than the default timeout.
14+
this.timeout(10000);
15+
const brokenResourcesList = [];
16+
for (const suite of Suites) {
17+
if (!suite.resources)
18+
continue;
19+
const resourcesPath = path.resolve(ROOT_DIR, suite.resources);
20+
let text;
21+
try {
22+
text = await fs.readFile(resourcesPath, "utf-8");
23+
} catch (error) {
24+
brokenResourcesList.push(`${suite.resources} (for ${suite.name}) [error: ${error.message}]`);
25+
continue;
26+
}
3127

32-
if (text.trim().length === 0) {
33-
brokenResourcesList.push(`${suite.resources} (for ${suite.name}) [error: resources.txt is empty]`);
34-
continue;
35-
}
28+
if (text.trim().length === 0) {
29+
brokenResourcesList.push(`${suite.resources} (for ${suite.name}) [error: resources.txt is empty]`);
30+
continue;
31+
}
3632

37-
const files = text.trim().split("\n");
38-
for (const file of files)
39-
expect(file.trim().length).to.be.greaterThan(0, `Found empty line in resources.txt for ${suite.name}`);
33+
const files = text.trim().split("\n");
34+
for (const file of files)
35+
expect(file.trim().length).to.be.greaterThan(0, `Found empty line in resources.txt for ${suite.name}`);
4036

41-
await Promise.all(
42-
files.map(async (file) => {
43-
const cleanFile = file.trim();
44-
if (!cleanFile)
45-
return;
46-
const filePath = cleanFile.startsWith("/")
47-
? path.join(ROOT_DIR, cleanFile)
48-
: path.resolve(path.dirname(resourcesPath), cleanFile);
49-
try {
50-
const stat = await fs.stat(filePath);
51-
if (!stat.isFile())
52-
brokenResourcesList.push(`${cleanFile} (listed in ${suite.resources}) [error: not a file]`);
53-
} catch (error) {
54-
brokenResourcesList.push(`${cleanFile} (listed in ${suite.resources}) [error: ${error.message}]`);
55-
}
56-
})
57-
);
58-
}
59-
if (brokenResourcesList.length > 0)
60-
throw new Error(`Failed to check the following resources:\n${brokenResourcesList.join("\n")}`);
61-
});
37+
await Promise.all(
38+
files.map(async (file) => {
39+
const cleanFile = file.trim();
40+
if (!cleanFile)
41+
return;
42+
const filePath = cleanFile.startsWith("/") ? path.join(ROOT_DIR, cleanFile) : path.resolve(path.dirname(resourcesPath), cleanFile);
43+
try {
44+
const stat = await fs.stat(filePath);
45+
if (!stat.isFile())
46+
brokenResourcesList.push(`${cleanFile} (listed in ${suite.resources}) [error: not a file]`);
47+
} catch (error) {
48+
brokenResourcesList.push(`${cleanFile} (listed in ${suite.resources}) [error: ${error.message}]`);
49+
}
50+
})
51+
);
52+
}
53+
if (brokenResourcesList.length > 0)
54+
throw new Error(`Failed to check the following resources:\n${brokenResourcesList.join("\n")}`);
6255
});
63-
}
56+
});

0 commit comments

Comments
 (0)