11#!/usr/bin/env node
22
3- import { describe , test } from "vitest" ;
3+ import { describe , test , expect } from "vitest" ;
44import { readFile } from "fs/promises" ;
55import { join } from "path" ;
66import Ajv2020 from "ajv/dist/2020.js" ;
77import addFormats from "ajv-formats" ;
88import { stations } from "../src/index.js" ;
9+ import tidePredictor from "@neaps/tide-predictor" ;
910
1011const ROOT = new URL ( ".." , import . meta. url ) . pathname ;
1112const SCHEMA_PATH = join ( ROOT , "schemas" , "station.schema.json" ) ;
@@ -17,13 +18,26 @@ const validate = ajv.compile(schema);
1718
1819describe ( "schema" , ( ) => {
1920 stations . forEach ( ( station ) => {
20- test ( `Station ${ station . id } ` , ( ) => {
21- const valid = validate ( station ) ;
22- if ( ! valid )
23- throw new Error (
24- ajv . errorsText ( validate . errors ) +
25- `\n${ JSON . stringify ( validate . errors , null , 2 ) } ` ,
26- ) ;
21+ describe ( station . id , ( ) => {
22+ test ( "is valid" , ( ) => {
23+ const valid = validate ( station ) ;
24+ if ( ! valid )
25+ throw new Error (
26+ ajv . errorsText ( validate . errors ) +
27+ `\n${ JSON . stringify ( validate . errors , null , 2 ) } ` ,
28+ ) ;
29+ } ) ;
30+
31+ if ( station . harmonic_constituents ) {
32+ test ( "uses constituents supported by neaps" , ( ) => {
33+ station . harmonic_constituents . forEach ( ( hc ) => {
34+ expect (
35+ tidePredictor . constituents [ hc . name ] ,
36+ `Unsupported constituent: ${ hc . name } ` ,
37+ ) . toBeDefined ( ) ;
38+ } ) ;
39+ } ) ;
40+ }
2741 } ) ;
2842 } ) ;
2943} ) ;
0 commit comments