Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions test/validate.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env node

import { describe, test } from "vitest";
import { describe, test, expect } from "vitest";
import { readFile } from "fs/promises";
import { join } from "path";
import Ajv2020 from "ajv/dist/2020.js";
import addFormats from "ajv-formats";
import { stations } from "../src/index.js";
import tidePredictor from "@neaps/tide-predictor";

const ROOT = new URL("..", import.meta.url).pathname;
const SCHEMA_PATH = join(ROOT, "schemas", "station.schema.json");
Expand All @@ -17,13 +18,26 @@

describe("schema", () => {
stations.forEach((station) => {
test(`Station ${station.id}`, () => {
const valid = validate(station);
if (!valid)
throw new Error(
ajv.errorsText(validate.errors) +
`\n${JSON.stringify(validate.errors, null, 2)}`,
);
describe(station.id, () => {
test("is valid", () => {
const valid = validate(station);
if (!valid)
throw new Error(
ajv.errorsText(validate.errors) +
`\n${JSON.stringify(validate.errors, null, 2)}`,
);
});

if (station.harmonic_constituents) {
test("uses constituents supported by neaps", () => {
station.harmonic_constituents.forEach((hc) => {
expect(
tidePredictor.constituents[hc.name],
`Unsupported constituent: ${hc.name}`,
).toBeDefined();

Check failure on line 37 in test/validate.test.ts

View workflow job for this annotation

GitHub Actions / test

test/validate.test.ts > schema > us/ak/anchorage-knik-arm > uses constituents supported by neaps

AssertionError: Unsupported constituent: SIGMA1: expected undefined to be defined ❯ test/validate.test.ts:37:15 ❯ test/validate.test.ts:33:41
});
});
}
});
});
});
Expand Down
Loading