Skip to content

Commit 36bb47d

Browse files
refactor: update testing to more idiomatic JS
Signed-off-by: Matthias Pichler <[email protected]>
1 parent 5ad9f30 commit 36bb47d

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

.ci/validation/src/index.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@
1616

1717
import { SWSchemaValidator } from "./index";
1818
import fs from "node:fs";
19-
import { join } from "node:path";
19+
import path from "node:path";
2020

2121
SWSchemaValidator.prepareSchemas();
2222

2323
const examplePath = "../../../examples";
2424

2525
describe(`Verify every example in the repository`, () => {
26-
fs.readdirSync(join(__dirname, examplePath), {
26+
fs.readdirSync(path.join(__dirname, examplePath), {
2727
encoding: SWSchemaValidator.defaultEncoding,
2828
recursive: false,
2929
withFileTypes: true,
3030
}).forEach((file) => {
3131
if (file.isFile() && file.name.endsWith(".yaml")) {
3232
test(`Example ${file.name}`, () => {
3333
const workflow = SWSchemaValidator.toJSON(
34-
join(__dirname, `${examplePath}/${file.name}`)
34+
path.join(__dirname, `${examplePath}/${file.name}`)
3535
);
3636
const results = SWSchemaValidator.validateSchema(workflow);
3737
if (results?.errors != null) {

.ci/validation/src/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import fs from "node:fs";
1818
import Ajv from "ajv";
1919
import addFormats from "ajv-formats";
20-
import { join } from "node:path";
20+
import path from "node:path";
2121
import yaml = require("js-yaml");
2222

2323
export module SWSchemaValidator {
@@ -30,7 +30,7 @@ export module SWSchemaValidator {
3030
export const defaultEncoding = "utf-8";
3131

3232
export function prepareSchemas() {
33-
fs.readdirSync(join(__dirname, schemaPath), {
33+
fs.readdirSync(path.join(__dirname, schemaPath), {
3434
encoding: defaultEncoding,
3535
recursive: false,
3636
withFileTypes: true,
@@ -41,20 +41,20 @@ export module SWSchemaValidator {
4141
});
4242
}
4343

44-
function syncReadSchema(filename: string) {
45-
return toJSON(join(__dirname, `${schemaPath}/${filename}`));
44+
function syncReadSchema(filename: string): any {
45+
return toJSON(path.join(__dirname, `${schemaPath}/${filename}`));
4646
}
4747

48-
export function toJSON(filename: string) {
48+
export function toJSON(filename: string): any {
4949
const yamlObj = yaml.load(fs.readFileSync(filename, defaultEncoding), {
5050
json: true,
5151
});
52-
return JSON.parse(JSON.stringify(yamlObj, null, 2));
52+
return structuredClone(yamlObj);
5353
}
5454

55-
export function validateSchema(workflow: JSON) {
55+
export function validateSchema(workflow: Record<string, unknown>) {
5656
const validate = ajv.getSchema(workflowSchemaId);
57-
if (validate != undefined) {
57+
if (validate) {
5858
const isValid = validate(workflow);
5959
return {
6060
valid: isValid,

0 commit comments

Comments
 (0)