UNPKG

@seasketch/geoprocessing

Version:

Geoprocessing and reporting framework for SeaSketch 2.0

50 lines 2.29 kB
import { getExampleFeatures, writeResultOutput } from "./index.js"; import { ValidationError } from "../../src/index.js"; import { booleanValid } from "@turf/turf"; /** * Runs smoke test for a preprocessor function taking polygon input * Runs preprocessor function for all example polygon sketches */ export const polygonPreprocessorSmokeTest = (preprocessorFunc, /** */ preprocessorName, options = {}) => { const { partialName, timeout = 10_000, debug = false } = options; describe("Basic smoke tests", () => { test("handler function is present", () => { expect(typeof preprocessorFunc).toBe("function"); }); test(`${preprocessorName}Smoke`, async () => { const examples = await getExampleFeatures(partialName); if (examples.length === 0) { console.log(`No example sketches found. Have you put any Sketch Polygon JSON files in your examples/sketches directory? ${partialName && partialName.length > 0 ? "Does your partialName " + partialName + " not match the name of any example polygon sketches?" : ""}`); } for (const example of examples) { if (debug) { console.log("Example:", example.properties?.name); } try { const result = await preprocessorFunc(example); expect(result).toBeTruthy(); expect(booleanValid(result)); expect(result.geometry.type === "Polygon" || result.geometry.type === "MultiPolygon"); writeResultOutput(result, preprocessorName, example?.properties?.name); } catch (error) { console.log("error", example?.properties?.name, error); if (error instanceof ValidationError) { // ValidationErrors don't indicate failures, just comprehensive tests } else { throw error; } } } }, timeout); }); }; //# sourceMappingURL=polygonPreprocessorSmokeTest.js.map