|
1 | | -import test from "node:test"; |
2 | | -import center from "./index.ts"; |
3 | | -import { featureCollection, lineString } from "@turf/helpers"; |
4 | | -import { coordEach, featureEach } from "@turf/meta"; |
5 | | -import bboxPolygon from "@turf/bbox-polygon"; |
6 | | -import bbox from "@turf/bbox"; |
7 | | -import type { Geometry } from "geojson"; |
8 | | -import { testFixtures } from "../../support/testFixtures.mts"; |
9 | | -import assert from "assert"; |
| 1 | +import test from "tape"; |
| 2 | +import { glob } from "glob"; |
| 3 | +import path from "path"; |
| 4 | +import { fileURLToPath } from "url"; |
| 5 | +import { loadJsonFileSync } from "load-json-file"; |
| 6 | +import { writeJsonFileSync } from "write-json-file"; |
| 7 | +import { bboxPolygon } from "@turf/bbox-polygon"; |
| 8 | +import { bbox } from "@turf/bbox"; |
| 9 | +import { featureEach, coordEach } from "@turf/meta"; |
| 10 | +import { lineString, featureCollection } from "@turf/helpers"; |
| 11 | +import { center } from "./index.js"; |
10 | 12 |
|
11 | | -await test("center fixtures", async (t) => { |
12 | | - await testFixtures(t, (geojson) => { |
13 | | - const options = geojson.options || {}; |
14 | | - options.properties = { "marker-symbol": "star", "marker-color": "#F00" }; |
15 | | - const centered = center(geojson, options); |
| 13 | +const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
16 | 14 |
|
17 | | - // Display Results |
18 | | - const results = featureCollection<Geometry>([centered]); |
19 | | - featureEach(geojson, (feature) => results.features.push(feature)); |
20 | | - const extent = bboxPolygon(bbox(geojson)); |
21 | | - extent.properties = { |
22 | | - stroke: "#00F", |
23 | | - "stroke-width": 1, |
24 | | - "fill-opacity": 0, |
25 | | - }; |
26 | | - coordEach(extent, (coord) => |
27 | | - results.features.push( |
28 | | - lineString([coord, centered.geometry.coordinates], { |
29 | | - stroke: "#00F", |
30 | | - "stroke-width": 1, |
31 | | - }) |
32 | | - ) |
33 | | - ); |
34 | | - results.features.push(extent); |
| 15 | +test("turf-center", (t) => { |
| 16 | + glob |
| 17 | + .sync(path.join(__dirname, "test", "in", "*.geojson")) |
| 18 | + .forEach((filepath) => { |
| 19 | + const geojson = loadJsonFileSync(filepath); |
| 20 | + const options = geojson.options || {}; |
| 21 | + options.properties = { "marker-symbol": "star", "marker-color": "#F00" }; |
| 22 | + const centered = center(geojson, options); |
35 | 23 |
|
36 | | - return results; |
37 | | - }); |
| 24 | + // Display Results |
| 25 | + const results = featureCollection([centered]); |
| 26 | + featureEach(geojson, (feature) => results.features.push(feature)); |
| 27 | + const extent = bboxPolygon(bbox(geojson)); |
| 28 | + extent.properties = { |
| 29 | + stroke: "#00F", |
| 30 | + "stroke-width": 1, |
| 31 | + "fill-opacity": 0, |
| 32 | + }; |
| 33 | + coordEach(extent, (coord) => |
| 34 | + results.features.push( |
| 35 | + lineString([coord, centered.geometry.coordinates], { |
| 36 | + stroke: "#00F", |
| 37 | + "stroke-width": 1, |
| 38 | + }) |
| 39 | + ) |
| 40 | + ); |
| 41 | + results.features.push(extent); |
| 42 | + |
| 43 | + const out = filepath.replace( |
| 44 | + path.join("test", "in"), |
| 45 | + path.join("test", "out") |
| 46 | + ); |
| 47 | + if (process.env.REGEN) writeJsonFileSync(out, results); |
| 48 | + t.deepEqual(results, loadJsonFileSync(out), path.parse(filepath).name); |
| 49 | + }); |
| 50 | + t.end(); |
38 | 51 | }); |
39 | 52 |
|
40 | | -test("turf-center -- properties", () => { |
| 53 | +test("turf-center -- properties", (t) => { |
41 | 54 | const line = lineString([ |
42 | 55 | [0, 0], |
43 | 56 | [1, 1], |
44 | 57 | ]); |
45 | 58 | const pt = center(line, { properties: { foo: "bar" } }); |
46 | | - assert.strictEqual(pt.properties.foo, "bar", "translate properties"); |
| 59 | + t.equal(pt.properties.foo, "bar", "translate properties"); |
| 60 | + t.end(); |
47 | 61 | }); |
0 commit comments