diff --git a/.monorepolint.config.mjs b/.monorepolint.config.mjs index 013f83f836..56b684a2fc 100644 --- a/.monorepolint.config.mjs +++ b/.monorepolint.config.mjs @@ -217,7 +217,7 @@ export default { options: { scripts: { bench: "node bench.ts", - "test:node": "node --test", + "test:node": "node --test test.ts", "test:tape": REMOVE, }, }, diff --git a/package.json b/package.json index 649d7d5124..2cd8e4b4e5 100644 --- a/package.json +++ b/package.json @@ -36,10 +36,10 @@ "@monorepolint/config": "0.6.0-alpha.6", "@monorepolint/core": "0.6.0-alpha.6", "@monorepolint/rules": "0.6.0-alpha.6", - "@types/benchmark": "^2.1.5", - "@types/node": "22.15.3", + "@types/benchmark": "catalog:", + "@types/node": "catalog:", "acorn": "^8.14.1", - "benchmark": "^2.1.4", + "benchmark": "catalog:", "camelcase": "^8.0.0", "d3-queue": "*", "decamelize": "^6.0.0", @@ -59,8 +59,8 @@ "meow": "^13.2.0", "prettier": "^3.5.3", "progress": "^2.0.3", - "tsup": "^8.4.0", - "typescript": "^5.8.3", + "tsup": "catalog:", + "typescript": "catalog:", "typescript-eslint": "^8.38.0", "yaml": "^2.8.2" } diff --git a/packages/turf-area/bench.ts b/packages/turf-area/bench.ts index 31b3fc06c4..bb4d8ab2eb 100644 --- a/packages/turf-area/bench.ts +++ b/packages/turf-area/bench.ts @@ -1,31 +1,6 @@ -import fs from "fs"; -import path from "path"; -import { fileURLToPath } from "url"; -import { loadJsonFileSync } from "load-json-file"; -import Benchmark from "benchmark"; -import { area } from "./index.js"; +import { area } from "./index.ts"; +import { benchFixtures } from "../../support/benchFixtures.mts"; -const __dirname = path.dirname(fileURLToPath(import.meta.url)); - -// Define fixtures -const directory = path.join(__dirname, "test", "in") + path.sep; -const fixtures = fs.readdirSync(directory).map((filename) => { - return { - filename, - name: path.parse(filename).name, - geojson: loadJsonFileSync(directory + filename), - }; -}); - -/** - * Benmark Results - * - * polygon x 8,510,024 ops/sec ±0.28% (96 runs sampled) - */ - -// Define benchmark -const suite = new Benchmark.Suite("turf-area"); -for (const { name, geojson } of fixtures) { - suite.add(name, () => area(geojson)); -} -suite.on("cycle", (e) => console.log(String(e.target))).run(); +// Benchmark Results +// polygon.geojson x 22,944,912 ops/sec ±0.28% (98 runs sampled) +await benchFixtures("turf-area", (input) => area(input)); diff --git a/packages/turf-area/index.ts b/packages/turf-area/index.ts index ff016ec7bc..17cca46a2a 100644 --- a/packages/turf-area/index.ts +++ b/packages/turf-area/index.ts @@ -1,4 +1,4 @@ -import { Feature, FeatureCollection, Geometry } from "geojson"; +import type { Feature, FeatureCollection, Geometry } from "geojson"; import { earthRadius } from "@turf/helpers"; import { geomReduce } from "@turf/meta"; diff --git a/packages/turf-area/package.json b/packages/turf-area/package.json index bd2e819b28..e289f36abd 100644 --- a/packages/turf-area/package.json +++ b/packages/turf-area/package.json @@ -44,21 +44,14 @@ "dist" ], "scripts": { - "bench": "tsx bench.ts", + "bench": "node bench.ts", "build": "tsup --config ../../tsup.config.ts", "test": "pnpm run /test:.*/", - "test:tape": "tsx test.ts" + "test:node": "node --test test.ts" }, "devDependencies": { - "@types/benchmark": "catalog:", - "@types/tape": "catalog:", - "benchmark": "catalog:", - "load-json-file": "^7.0.1", - "tape": "catalog:", "tsup": "catalog:", - "tsx": "catalog:", - "typescript": "catalog:", - "write-json-file": "^6.0.0" + "typescript": "catalog:" }, "dependencies": { "@turf/helpers": "workspace:*", diff --git a/packages/turf-area/test.ts b/packages/turf-area/test.ts index 40f008002c..b0690ce9c2 100644 --- a/packages/turf-area/test.ts +++ b/packages/turf-area/test.ts @@ -1,40 +1,17 @@ -import fs from "fs"; -import test from "tape"; -import path from "path"; -import { fileURLToPath } from "url"; -import { loadJsonFileSync } from "load-json-file"; -import { writeJsonFileSync } from "write-json-file"; -import { area } from "./index.js"; +import test from "node:test"; +import { area } from "./index.ts"; import { polygon } from "@turf/helpers"; -import { Polygon } from "geojson"; -const __dirname = path.dirname(fileURLToPath(import.meta.url)); +import type { Polygon } from "geojson"; +import { testFixtures } from "../../support/testFixtures.mts"; +import assert from "assert"; -const directories = { - in: path.join(__dirname, "test", "in") + path.sep, - out: path.join(__dirname, "test", "out") + path.sep, -}; - -const fixtures = fs.readdirSync(directories.in).map((filename) => { - return { - filename, - name: path.parse(filename).name, - geojson: loadJsonFileSync(directories.in + filename), - }; -}); - -test("turf-area", (t) => { - for (const fixture of fixtures) { - const name = fixture.name; - const geojson = fixture.geojson; - const results = Math.round(area(geojson)); - if (process.env.REGEN) - writeJsonFileSync(directories.out + name + ".json", results); - t.equal(results, loadJsonFileSync(directories.out + name + ".json"), name); - } - t.end(); +await test("area fixtures", async (t) => { + await testFixtures(t, (geojson) => { + return Math.round(area(geojson)); + }); }); -test("turf-area-length-check", (t) => { +test("turf-area -- length-check", () => { const invalidPoly: Polygon = { type: "Polygon", coordinates: [ @@ -46,12 +23,10 @@ test("turf-area-length-check", (t) => { ], }; const result = area(invalidPoly); - t.equal(result, 0); - - t.end(); + assert.strictEqual(result, 0); }); -test("turf-area-rotation-consistency", (t) => { +test("turf-area rotation-consistency", () => { const rotatingPoly = polygon([ [ [28.321755510202507, 16.35627490376781], @@ -84,7 +59,6 @@ test("turf-area-rotation-consistency", (t) => { rotatingPoly.geometry.coordinates[0][i]; const curResult = area(changingPoly); - t.equal(result, curResult); + assert.strictEqual(result, curResult); } - t.end(); }); diff --git a/packages/turf-bbox-clip/bench.ts b/packages/turf-bbox-clip/bench.ts index ae93604d67..7166ad09dc 100644 --- a/packages/turf-bbox-clip/bench.ts +++ b/packages/turf-bbox-clip/bench.ts @@ -1,38 +1,16 @@ -import fs from "fs"; -import path from "path"; -import { fileURLToPath } from "url"; -import { loadJsonFileSync } from "load-json-file"; -import Benchmark from "benchmark"; import { bbox } from "@turf/bbox"; -import { bboxClip } from "./index.js"; +import { bboxClip } from "./index.ts"; +import { benchFixtures } from "../../support/benchFixtures.mts"; -const __dirname = path.dirname(fileURLToPath(import.meta.url)); - -const directory = path.join(__dirname, "test", "in") + path.sep; -const fixtures = fs.readdirSync(directory).map((filename) => { - return { - filename, - name: path.parse(filename).name, - geojson: loadJsonFileSync(directory + filename), - }; -}); - -/** - * Benchmark Results - * - * linestring-single-line x 1,065,073 ops/sec ±1.11% (90 runs sampled) - * linestring x 56,599 ops/sec ±1.17% (90 runs sampled) - * multi-linestring x 859,048 ops/sec ±1.01% (91 runs sampled) - * multi-polygon x 26,991 ops/sec ±0.87% (94 runs sampled) - * polygon-crossing-hole x 25,277 ops/sec ±0.72% (92 runs sampled) - * polygon-holes x 27,233 ops/sec ±0.89% (91 runs sampled) - * polygon x 21,339 ops/sec ±1.19% (89 runs sampled) - */ -const suite = new Benchmark.Suite("turf-bbox-clip"); -for (const { name, geojson } of fixtures) { - suite.add(name, () => - bboxClip(geojson.features[0], bbox(geojson.features[1])) - ); -} - -suite.on("cycle", (e) => console.log(String(e.target))).run(); +// Benchmark Results +// linestring-single-line.geojson x 15,871,930 ops/sec ±0.24% (98 runs sampled) +// linestring.geojson x 264,962 ops/sec ±1.14% (96 runs sampled) +// multi-linestring.geojson x 7,892,547 ops/sec ±0.35% (95 runs sampled) +// multi-polygon.geojson x 138,989 ops/sec ±0.31% (98 runs sampled) +// polygon-crossing-hole.geojson x 151,793 ops/sec ±0.35% (95 runs sampled) +// polygon-holes.geojson x 142,335 ops/sec ±0.30% (96 runs sampled) +// polygon-point-intersection.geojson x 8,580,181 ops/sec ±0.73% (94 runs sampled) +// polygon.geojson x 117,120 ops/sec ±0.18% (99 runs sampled) +await benchFixtures("turf-bbox-clip", (input) => + bboxClip(input.features[0], bbox(input.features[1])) +); diff --git a/packages/turf-bbox-clip/index.ts b/packages/turf-bbox-clip/index.ts index 765dc39424..de306c6815 100644 --- a/packages/turf-bbox-clip/index.ts +++ b/packages/turf-bbox-clip/index.ts @@ -1,4 +1,4 @@ -import { +import type { BBox, Feature, LineString, @@ -15,7 +15,7 @@ import { polygon, } from "@turf/helpers"; import { getGeom } from "@turf/invariant"; -import { lineclip, polygonclip } from "./lib/lineclip.js"; +import { lineclip, polygonclip } from "./lib/lineclip.ts"; /** * Takes a {@link Feature} and a bbox and clips the feature to the bbox using diff --git a/packages/turf-bbox-clip/lib/lineclip.ts b/packages/turf-bbox-clip/lib/lineclip.ts index 92004521a6..5361412472 100644 --- a/packages/turf-bbox-clip/lib/lineclip.ts +++ b/packages/turf-bbox-clip/lib/lineclip.ts @@ -1,6 +1,6 @@ // Cohen-Sutherland line clipping algorithm, adapted to efficiently // handle polylines rather than just segments -import { BBox } from "geojson"; +import type { BBox } from "geojson"; export function lineclip( points: number[][], diff --git a/packages/turf-bbox-clip/package.json b/packages/turf-bbox-clip/package.json index 1d0a229037..78b7569715 100644 --- a/packages/turf-bbox-clip/package.json +++ b/packages/turf-bbox-clip/package.json @@ -50,22 +50,15 @@ "dist" ], "scripts": { - "bench": "tsx bench.ts", + "bench": "node bench.ts", "build": "tsup --config ../../tsup.config.ts", "test": "pnpm run /test:.*/", - "test:tape": "tsx test.ts" + "test:node": "node --test test.ts" }, "devDependencies": { "@turf/bbox": "workspace:*", - "@types/benchmark": "catalog:", - "@types/tape": "catalog:", - "benchmark": "catalog:", - "load-json-file": "^7.0.1", - "tape": "catalog:", "tsup": "catalog:", - "tsx": "catalog:", - "typescript": "catalog:", - "write-json-file": "^6.0.0" + "typescript": "catalog:" }, "dependencies": { "@turf/helpers": "workspace:*", diff --git a/packages/turf-bbox-clip/test.ts b/packages/turf-bbox-clip/test.ts index 9bd6116483..2f14f79e7f 100644 --- a/packages/turf-bbox-clip/test.ts +++ b/packages/turf-bbox-clip/test.ts @@ -1,60 +1,37 @@ -import fs from "fs"; -import test from "tape"; -import path from "path"; -import { fileURLToPath } from "url"; -import { loadJsonFileSync } from "load-json-file"; -import { writeJsonFileSync } from "write-json-file"; import { point, feature, featureCollection } from "@turf/helpers"; import { bbox as turfBBox } from "@turf/bbox"; -import { bboxClip } from "./index.js"; +import { bboxClip } from "./index.ts"; +import { testFixtures } from "../../support/testFixtures.mts"; +import assert from "assert"; +import test from "node:test"; -const __dirname = path.dirname(fileURLToPath(import.meta.url)); - -const directories = { - in: path.join(__dirname, "test", "in") + path.sep, - out: path.join(__dirname, "test", "out") + path.sep, -}; - -const fixtures = fs.readdirSync(directories.in).map((filename) => { - return { - filename, - name: path.parse(filename).name, - geojson: loadJsonFileSync(directories.in + filename), - }; -}); - -test("turf-bbox-clip", (t) => { - for (const fixture of fixtures) { - const filename = fixture.filename; - const name = fixture.name; - const geojson = fixture.geojson; +await test("bboxClip features", async (t) => { + await testFixtures(t, (geojson) => { const feature = geojson.features[0]; const bbox = turfBBox(geojson.features[1]); const clipped = bboxClip(feature, bbox); - const results = featureCollection([ + return featureCollection([ colorize(feature, "#080"), colorize(clipped, "#F00"), colorize(geojson.features[1], "#00F", 3), ]); + }); +}); - if (process.env.REGEN) - writeJsonFileSync(directories.out + filename, results); - t.deepEquals(results, loadJsonFileSync(directories.out + filename), name); - } - t.end(); +test("turf-bbox-clip -- throws", () => { + assert.throws(() => { + bboxClip(point([5, 10]) as any, [-180, -90, 180, 90]); + }, /geometry Point not supported/); }); -test("turf-bbox-clip -- throws", (t) => { - t.throws( - () => bboxClip(point([5, 10]), [-180, -90, 180, 90]), - /geometry Point not supported/ +test("turf-bbox-clip -- null geometries", () => { + assert.throws( + () => bboxClip(feature(null as any), [-180, -90, 180, 90]), + "coords must be GeoJSON Feature, Geometry Object or an Array" ); - t.end(); }); -function colorize(feature, color, width) { - color = color || "#F00"; - width = width || 6; +function colorize(feature: any, color = "#F00", width = 6) { feature.properties = { stroke: color, fill: color, @@ -63,11 +40,3 @@ function colorize(feature, color, width) { }; return feature; } - -test("turf-bbox-clip -- null geometries", (t) => { - t.throws( - () => bboxClip(feature(null), [-180, -90, 180, 90]), - "coords must be GeoJSON Feature, Geometry Object or an Array" - ); - t.end(); -}); diff --git a/packages/turf-bezier-spline/bench.ts b/packages/turf-bezier-spline/bench.ts index 4f886db616..d9023c0155 100644 --- a/packages/turf-bezier-spline/bench.ts +++ b/packages/turf-bezier-spline/bench.ts @@ -1,30 +1,13 @@ -import fs from "fs"; -import path from "path"; -import { fileURLToPath } from "url"; -import { loadJsonFileSync } from "load-json-file"; -import Benchmark from "benchmark"; -import { bezierSpline } from "./index.js"; - -const __dirname = path.dirname(fileURLToPath(import.meta.url)); - -const directory = path.join(__dirname, "test", "in") + path.sep; -const fixtures = fs.readdirSync(directory).map((filename) => { - return { - filename, - name: path.parse(filename).name, - geojson: loadJsonFileSync(directory + filename), - }; -}); - -/** - * Benchmark Results - * - * bezierIn x 771 ops/sec ±1.31% (88 runs sampled) - * simple x 768 ops/sec ±1.20% (89 runs sampled) - */ -const suite = new Benchmark.Suite("turf-bezier-spline"); -for (const { name, geojson } of fixtures) { - suite.add(name, () => bezierSpline(geojson)); -} - -suite.on("cycle", (e) => console.log(String(e.target))).run(); +import { bezierSpline } from "./index.ts"; +import { benchFixtures } from "../../support/benchFixtures.mts"; + +// Benchmark Results +// linestring-single-line.geojson x 15,443,284 ops/sec ±0.31% (101 runs sampled) +// linestring.geojson x 264,982 ops/sec ±0.37% (98 runs sampled) +// multi-linestring.geojson x 7,798,170 ops/sec ±0.46% (100 runs sampled) +// multi-polygon.geojson x 135,112 ops/sec ±0.20% (98 runs sampled) +// polygon-crossing-hole.geojson x 152,794 ops/sec ±0.25% (99 runs sampled) +// polygon-holes.geojson x 140,602 ops/sec ±0.21% (99 runs sampled) +// polygon-point-intersection.geojson x 8,323,552 ops/sec ±0.61% (100 runs sampled) +// polygon.geojson x 116,567 ops/sec ±0.20% (96 runs sampled) +await benchFixtures("turf-bezier-spline", (input) => bezierSpline(input)); diff --git a/packages/turf-bezier-spline/index.ts b/packages/turf-bezier-spline/index.ts index 99599877b0..1f5d285f4c 100644 --- a/packages/turf-bezier-spline/index.ts +++ b/packages/turf-bezier-spline/index.ts @@ -1,7 +1,7 @@ -import { Feature, LineString, GeoJsonProperties } from "geojson"; +import type { Feature, LineString, GeoJsonProperties } from "geojson"; import { lineString } from "@turf/helpers"; import { getGeom } from "@turf/invariant"; -import { Spline } from "./lib/spline.js"; +import { Spline } from "./lib/spline.ts"; /** * Takes a {@link LineString|line} and returns a curved version diff --git a/packages/turf-bezier-spline/lib/spline.ts b/packages/turf-bezier-spline/lib/spline.ts index 67f1595f29..fc0a555a1b 100644 --- a/packages/turf-bezier-spline/lib/spline.ts +++ b/packages/turf-bezier-spline/lib/spline.ts @@ -1,4 +1,4 @@ -interface Point { +export interface Point { x: number; y: number; z: number; @@ -30,7 +30,7 @@ interface Point { * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -class Spline { +export class Spline { public duration: number; public points: Point[]; public sharpness: number; @@ -194,6 +194,3 @@ function B(t: number) { (1 - t) * (1 - t) * (1 - t), ]; } - -export { Spline, Point }; -export default Spline; diff --git a/packages/turf-bezier-spline/package.json b/packages/turf-bezier-spline/package.json index c660fd33f5..d11084fbc7 100644 --- a/packages/turf-bezier-spline/package.json +++ b/packages/turf-bezier-spline/package.json @@ -45,21 +45,14 @@ "dist" ], "scripts": { - "bench": "tsx bench.ts", + "bench": "node bench.ts", "build": "tsup --config ../../tsup.config.ts", "test": "pnpm run /test:.*/", - "test:tape": "tsx test.ts" + "test:node": "node --test test.ts" }, "devDependencies": { - "@types/benchmark": "catalog:", - "@types/tape": "catalog:", - "benchmark": "catalog:", - "load-json-file": "^7.0.1", - "tape": "catalog:", "tsup": "catalog:", - "tsx": "catalog:", - "typescript": "catalog:", - "write-json-file": "^6.0.0" + "typescript": "catalog:" }, "dependencies": { "@turf/helpers": "workspace:*", diff --git a/packages/turf-bezier-spline/test.ts b/packages/turf-bezier-spline/test.ts index 69dcd7fff8..7149da29c7 100644 --- a/packages/turf-bezier-spline/test.ts +++ b/packages/turf-bezier-spline/test.ts @@ -1,45 +1,16 @@ -import fs from "fs"; -import test from "tape"; -import path from "path"; -import { fileURLToPath } from "url"; -import { loadJsonFileSync } from "load-json-file"; -import { writeJsonFileSync } from "write-json-file"; import { featureCollection } from "@turf/helpers"; -import { bezierSpline } from "./index.js"; +import { bezierSpline } from "./index.ts"; +import { testFixtures } from "../../support/testFixtures.mts"; +import test from "node:test"; -const __dirname = path.dirname(fileURLToPath(import.meta.url)); - -const directories = { - in: path.join(__dirname, "test", "in") + path.sep, - out: path.join(__dirname, "test", "out") + path.sep, -}; - -const fixtures = fs.readdirSync(directories.in).map((filename) => { - return { - filename, - name: path.parse(filename).name, - geojson: loadJsonFileSync(directories.in + filename), - }; -}); - -test("turf-bezier-spline", (t) => { - fixtures.forEach((fixture) => { - const filename = fixture.filename; - const name = fixture.name; - const geojson = fixture.geojson; +await test("turf-bezier-spline fixtures", async (t) => { + await testFixtures(t, (geojson) => { const spline = colorize(bezierSpline(geojson)); - const results = featureCollection([spline, geojson]); - - if (process.env.REGEN) - writeJsonFileSync(directories.out + filename, results); - t.deepEquals(results, loadJsonFileSync(directories.out + filename), name); + return featureCollection([spline, geojson]); }); - t.end(); }); -function colorize(feature, color, width) { - color = color || "#F00"; - width = width || 6; +function colorize(feature: any, color = "#F00", width = 6) { feature.properties = { stroke: color, fill: color, diff --git a/packages/turf-buffer/bench.ts b/packages/turf-buffer/bench.ts index b7fa44a1d5..29f14e0e5b 100644 --- a/packages/turf-buffer/bench.ts +++ b/packages/turf-buffer/bench.ts @@ -1,54 +1,22 @@ -import fs from "fs"; -import path from "path"; -import { fileURLToPath } from "url"; -import { loadJsonFileSync } from "load-json-file"; -import Benchmark from "benchmark"; -import { buffer } from "./index.js"; +import { buffer } from "./index.ts"; +import { benchFixtures } from "../../support/benchFixtures.mts"; -const __dirname = path.dirname(fileURLToPath(import.meta.url)); - -const directory = path.join(__dirname, "test", "in") + path.sep; -const fixtures = fs.readdirSync(directory).map((filename) => { - return { - filename, - name: path.parse(filename).name, - geojson: loadJsonFileSync(directory + filename), - }; -}); - -/** - * Benchmark Results - * - * feature-collection-points: 139.101ms - * geometry-collection-points: 20.334ms - * issue-#783: 33.209ms - * linestring: 6.371ms - * multi-linestring: 48.786ms - * multi-point: 7.627ms - * multi-polygon: 38.921ms - * negative-buffer: 5.621ms - * north-latitude-points: 71.144ms - * northern-polygon: 2.644ms - * point: 8.155ms - * polygon-with-holes: 6.965ms - * feature-collection-points x 722 ops/sec ±14.28% (65 runs sampled) - * geometry-collection-points x 1,314 ops/sec ±7.87% (66 runs sampled) - * issue-#783 x 1,404 ops/sec ±6.81% (64 runs sampled) - * linestring x 2,936 ops/sec ±6.94% (72 runs sampled) - * multi-linestring x 623 ops/sec ±4.35% (79 runs sampled) - * multi-point x 1,735 ops/sec ±8.60% (65 runs sampled) - * multi-polygon x 1,125 ops/sec ±3.93% (80 runs sampled) - * north-latitude-points x 1,649 ops/sec ±2.09% (86 runs sampled) - * northern-polygon x 4,658 ops/sec ±3.08% (78 runs sampled) - * point x 65,020 ops/sec ±1.29% (85 runs sampled) - * polygon-with-holes x 2,795 ops/sec ±2.98% (81 runs sampled) - */ -const suite = new Benchmark.Suite("turf-buffer"); -for (const { name, geojson } of fixtures) { - console.time(name); - buffer(geojson, 50, { units: "miles" }); - console.timeEnd(name); - suite.add(name, () => buffer(geojson, 50, { units: "miles" })); -} - -suite.on("cycle", (e) => console.log(String(e.target))).run(); +// Benchmark Results +// feature-collection-points.geojson x 10,741 ops/sec ±0.84% (96 runs sampled) +// geometry-collection-points.geojson x 16,229 ops/sec ±0.47% (99 runs sampled) +// issue-#783.geojson x 18,447 ops/sec ±0.27% (97 runs sampled) +// issue-#801-Ecuador.geojson x 27,774 ops/sec ±0.41% (97 runs sampled) +// issue-#801.geojson x 27,382 ops/sec ±0.18% (99 runs sampled) +// issue-#815.geojson x 42,241 ops/sec ±0.27% (98 runs sampled) +// issue-#900.geojson x 9,042 ops/sec ±0.32% (96 runs sampled) +// issue-#916.geojson x 23,689 ops/sec ±0.52% (97 runs sampled) +// linestring.geojson x 36,095 ops/sec ±0.41% (95 runs sampled) +// multi-linestring.geojson x 7,168 ops/sec ±0.15% (99 runs sampled) +// multi-point.geojson x 21,735 ops/sec ±0.60% (99 runs sampled) +// multi-polygon.geojson x 13,019 ops/sec ±0.18% (93 runs sampled) +// negative-buffer.geojson x 46,876 ops/sec ±0.19% (100 runs sampled) +// north-latitude-points.geojson x 16,680 ops/sec ±0.17% (98 runs sampled) +// northern-polygon.geojson x 46,875 ops/sec ±0.15% (99 runs sampled) +// point.geojson x 59,494 ops/sec ±0.17% (96 runs sampled) +// polygon-with-holes.geojson x 30,772 ops/sec ±0.59% (98 runs sampled) +benchFixtures("turf-buffer", (input) => buffer(input, 50, { units: "miles" })); diff --git a/packages/turf-buffer/index.ts b/packages/turf-buffer/index.ts index 075e79ba74..8134334f92 100644 --- a/packages/turf-buffer/index.ts +++ b/packages/turf-buffer/index.ts @@ -2,16 +2,16 @@ import { center } from "@turf/center"; // @ts-expect-error We're hopefully dropping @turf/jsts entirely soon, so lets just go without types for now import jsts from "@turf/jsts"; import { geomEach, featureEach } from "@turf/meta"; -import { geoAzimuthalEquidistant, GeoProjection } from "d3-geo"; +import { geoAzimuthalEquidistant, type GeoProjection } from "d3-geo"; import { feature, featureCollection, radiansToLength, lengthToRadians, earthRadius, - Units, + type Units, } from "@turf/helpers"; -import { +import type { Feature, FeatureCollection, GeometryCollection, diff --git a/packages/turf-buffer/package.json b/packages/turf-buffer/package.json index 0792fa28ad..e2a14e6036 100644 --- a/packages/turf-buffer/package.json +++ b/packages/turf-buffer/package.json @@ -52,25 +52,18 @@ "dist" ], "scripts": { - "bench": "tsx bench.ts", + "bench": "node bench.ts", "build": "tsup --config ../../tsup.config.ts", "test": "pnpm run /test:.*/", - "test:tape": "tsx test.ts", + "test:node": "node --test test.ts", "test:types": "tstyche" }, "devDependencies": { "@turf/truncate": "workspace:*", - "@types/benchmark": "catalog:", "@types/d3-geo": "^3.1.0", - "@types/tape": "catalog:", - "benchmark": "catalog:", - "load-json-file": "^7.0.1", - "tape": "catalog:", "tstyche": "catalog:", "tsup": "catalog:", - "tsx": "catalog:", - "typescript": "catalog:", - "write-json-file": "^6.0.0" + "typescript": "catalog:" }, "dependencies": { "@turf/bbox": "workspace:*", diff --git a/packages/turf-buffer/test.ts b/packages/turf-buffer/test.ts index d0ae678321..ed0c89a6e1 100644 --- a/packages/turf-buffer/test.ts +++ b/packages/turf-buffer/test.ts @@ -1,9 +1,3 @@ -import fs from "fs"; -import test from "tape"; -import path from "path"; -import { fileURLToPath } from "url"; -import { loadJsonFileSync } from "load-json-file"; -import { writeJsonFileSync } from "write-json-file"; import { truncate } from "@turf/truncate"; import { featureEach } from "@turf/meta"; import { @@ -12,36 +6,17 @@ import { polygon, geometryCollection, } from "@turf/helpers"; -import { buffer } from "./index.js"; +import { buffer } from "./index.ts"; +import { testFixtures } from "../../support/testFixtures.mts"; +import test from "node:test"; +import assert from "assert"; -const __dirname = path.dirname(fileURLToPath(import.meta.url)); - -const directories = { - in: path.join(__dirname, "test", "in") + path.sep, - out: path.join(__dirname, "test", "out") + path.sep, -}; - -var fixtures = fs.readdirSync(directories.in).map((filename) => { - return { - filename, - name: path.parse(filename).name, - geojson: loadJsonFileSync(directories.in + filename), - }; -}); -// fixtures = fixtures.filter(({name}) => name === 'feature-collection-points'); - -test("turf-buffer", (t) => { - fixtures.forEach((fixture) => { - const filename = fixture.filename; - const name = fixture.name; - const geojson = fixture.geojson; - const properties = geojson.properties || {}; - const radius = properties.radius || 50; - const units = properties.units || "miles"; - const steps = properties.steps; +await test("buffer fixtures", async (t) => { + await testFixtures(t, (geojson) => { + const { radius = 50, units = "miles", steps } = geojson.properties ?? {}; const buffered = truncate( - buffer(geojson, radius, { units: units, steps: steps }) + buffer(geojson, radius, { units: units, steps: steps })! ); // Add Results to FeatureCollection @@ -53,15 +28,12 @@ test("turf-buffer", (t) => { results.features.push(colorize(feature, "#00F")) ); - if (process.env.REGEN) - writeJsonFileSync(directories.out + filename, results); - t.deepEqual(results, loadJsonFileSync(directories.out + filename), name); + return results; }); - t.end(); }); // https://github.com/Turfjs/turf/pull/736 -test("turf-buffer - Support Negative Buffer", (t) => { +test("turf-buffer - Support Negative Buffer", () => { const poly = polygon([ [ [11, 0], @@ -74,8 +46,7 @@ test("turf-buffer - Support Negative Buffer", (t) => { ], ]); - t.assert(buffer(poly, -50), "allow negative buffer param"); - t.end(); + assert(buffer(poly, -50), "allow negative buffer param"); }); test("turf-buffer - Support Geometry Objects", (t) => { @@ -93,13 +64,12 @@ test("turf-buffer - Support Geometry Objects", (t) => { ]); const gc = geometryCollection([pt.geometry, poly.geometry]); - t.assert(buffer(gc, 10), "support Geometry Collection"); - t.assert(buffer(pt.geometry, 10), "support Point Geometry"); - t.assert(buffer(poly.geometry, 10), "support Polygon Geometry"); - t.end(); + assert(buffer(gc, 10), "support Geometry Collection"); + assert(buffer(pt.geometry, 10), "support Point Geometry"); + assert(buffer(poly.geometry, 10), "support Polygon Geometry"); }); -test("turf-buffer - Prevent Input Mutation", (t) => { +test("turf-buffer - Prevent Input Mutation", () => { const pt = point([61, 5]); const poly = polygon([ [ @@ -112,7 +82,7 @@ test("turf-buffer - Prevent Input Mutation", (t) => { [11, 0], ], ]); - const collection = featureCollection([pt, poly]); + const collection = featureCollection([pt as any, poly]); const beforePt = JSON.parse(JSON.stringify(pt)); const beforePoly = JSON.parse(JSON.stringify(poly)); @@ -122,15 +92,18 @@ test("turf-buffer - Prevent Input Mutation", (t) => { buffer(poly, 10); buffer(collection, 10); - t.deepEqual(pt, beforePt, "pt should not mutate"); - t.deepEqual(poly, beforePoly, "poly should not mutate"); - t.deepEqual(collection, beforeCollection, "collection should not mutate"); - t.end(); + assert.deepEqual(pt, beforePt, "pt should not mutate"); + assert.deepEqual(poly, beforePoly, "poly should not mutate"); + assert.deepEqual( + collection, + beforeCollection, + "collection should not mutate" + ); }); // https://github.com/Turfjs/turf/issues/745 // https://github.com/Turfjs/turf/pull/736#issuecomment-301937747 -test("turf-buffer - morphological closing", (t) => { +test("turf-buffer - morphological closing", () => { const poly = polygon([ [ [11, 0], @@ -143,20 +116,19 @@ test("turf-buffer - morphological closing", (t) => { ], ]); - t.equal( + assert.strictEqual( buffer(poly, -500, { units: "miles" }), undefined, "empty geometry should be undefined" ); - t.deepEqual( + assert.deepEqual( buffer(featureCollection([poly]), -500, { units: "miles" }), featureCollection([]), "empty geometries should be an empty FeatureCollection" ); - t.end(); }); -test("turf-buffer - undefined return", (t) => { +test("turf-buffer - undefined return", () => { const poly: GeoJSON.Feature = { type: "Feature", properties: {}, @@ -174,16 +146,14 @@ test("turf-buffer - undefined return", (t) => { }, }; - t.equal( + assert.strictEqual( buffer(poly, -100000000), undefined, "empty geometry should be undefined if the resulting geometry is invalid" ); - t.end(); }); -function colorize(feature, color) { - color = color || "#F00"; +function colorize(feature: any, color = "#F00") { if (feature.properties) { feature.properties.stroke = color; feature.properties.fill = color; diff --git a/packages/turf-center/package.json b/packages/turf-center/package.json index 3413441b58..285c6e3d35 100644 --- a/packages/turf-center/package.json +++ b/packages/turf-center/package.json @@ -49,7 +49,7 @@ "bench": "node bench.ts", "build": "tsup --config ../../tsup.config.ts", "test": "pnpm run /test:.*/", - "test:node": "node --test", + "test:node": "node --test test.ts", "test:types": "tsc --esModuleInterop --module node16 --moduleResolution node16 --noEmit --strict types.ts" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2cc56153f6..a7b87ab822 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,6 +12,9 @@ catalogs: '@types/geojson': specifier: ^7946.0.10 version: 7946.0.14 + '@types/node': + specifier: ^22.19.17 + version: 22.19.17 '@types/tape': specifier: ^5.8.1 version: 5.8.1 @@ -60,16 +63,16 @@ importers: specifier: 0.6.0-alpha.6 version: 0.6.0-alpha.6 '@types/benchmark': - specifier: ^2.1.5 + specifier: 'catalog:' version: 2.1.5 '@types/node': - specifier: 22.15.3 - version: 22.15.3 + specifier: 'catalog:' + version: 22.19.17 acorn: specifier: ^8.14.1 version: 8.15.0 benchmark: - specifier: ^2.1.4 + specifier: 'catalog:' version: 2.1.4 camelcase: specifier: ^8.0.0 @@ -112,7 +115,7 @@ importers: version: 9.1.7 lerna: specifier: ^9.0.3 - version: 9.0.3(@types/node@22.15.3) + version: 9.0.3(@types/node@22.19.17) lint-staged: specifier: ^15.5.1 version: 15.5.1 @@ -129,10 +132,10 @@ importers: specifier: ^2.0.3 version: 2.0.3 tsup: - specifier: ^8.4.0 + specifier: 'catalog:' version: 8.4.0(postcss@8.5.3)(tsx@4.19.4)(typescript@5.8.3)(yaml@2.8.2) typescript: - specifier: ^5.8.3 + specifier: 'catalog:' version: 5.8.3 typescript-eslint: specifier: ^8.38.0 @@ -666,33 +669,12 @@ importers: specifier: 'catalog:' version: 2.8.1 devDependencies: - '@types/benchmark': - specifier: 'catalog:' - version: 2.1.5 - '@types/tape': - specifier: 'catalog:' - version: 5.8.1 - benchmark: - specifier: 'catalog:' - version: 2.1.4 - load-json-file: - specifier: ^7.0.1 - version: 7.0.1 - tape: - specifier: 'catalog:' - version: 5.9.0 tsup: specifier: 'catalog:' version: 8.4.0(postcss@8.5.3)(tsx@4.19.4)(typescript@5.8.3)(yaml@2.8.2) - tsx: - specifier: 'catalog:' - version: 4.19.4 typescript: specifier: 'catalog:' version: 5.8.3 - write-json-file: - specifier: ^6.0.0 - version: 6.0.0 packages/turf-bbox: dependencies: @@ -749,33 +731,12 @@ importers: '@turf/bbox': specifier: workspace:* version: link:../turf-bbox - '@types/benchmark': - specifier: 'catalog:' - version: 2.1.5 - '@types/tape': - specifier: 'catalog:' - version: 5.8.1 - benchmark: - specifier: 'catalog:' - version: 2.1.4 - load-json-file: - specifier: ^7.0.1 - version: 7.0.1 - tape: - specifier: 'catalog:' - version: 5.9.0 tsup: specifier: 'catalog:' version: 8.4.0(postcss@8.5.3)(tsx@4.19.4)(typescript@5.8.3)(yaml@2.8.2) - tsx: - specifier: 'catalog:' - version: 4.19.4 typescript: specifier: 'catalog:' version: 5.8.3 - write-json-file: - specifier: ^6.0.0 - version: 6.0.0 packages/turf-bbox-polygon: dependencies: @@ -869,33 +830,12 @@ importers: specifier: 'catalog:' version: 2.8.1 devDependencies: - '@types/benchmark': - specifier: 'catalog:' - version: 2.1.5 - '@types/tape': - specifier: 'catalog:' - version: 5.8.1 - benchmark: - specifier: 'catalog:' - version: 2.1.4 - load-json-file: - specifier: ^7.0.1 - version: 7.0.1 - tape: - specifier: 'catalog:' - version: 5.9.0 tsup: specifier: 'catalog:' version: 8.4.0(postcss@8.5.3)(tsx@4.19.4)(typescript@5.8.3)(yaml@2.8.2) - tsx: - specifier: 'catalog:' - version: 4.19.4 typescript: specifier: 'catalog:' version: 5.8.3 - write-json-file: - specifier: ^6.0.0 - version: 6.0.0 packages/turf-boolean-clockwise: dependencies: @@ -1637,39 +1577,18 @@ importers: '@turf/truncate': specifier: workspace:* version: link:../turf-truncate - '@types/benchmark': - specifier: 'catalog:' - version: 2.1.5 '@types/d3-geo': specifier: ^3.1.0 version: 3.1.0 - '@types/tape': - specifier: 'catalog:' - version: 5.8.1 - benchmark: - specifier: 'catalog:' - version: 2.1.4 - load-json-file: - specifier: ^7.0.1 - version: 7.0.1 - tape: - specifier: 'catalog:' - version: 5.9.0 tstyche: specifier: 'catalog:' version: 6.2.0(typescript@5.8.3) tsup: specifier: 'catalog:' version: 8.4.0(postcss@8.5.3)(tsx@4.19.4)(typescript@5.8.3)(yaml@2.8.2) - tsx: - specifier: 'catalog:' - version: 4.19.4 typescript: specifier: 'catalog:' version: 5.8.3 - write-json-file: - specifier: ^6.0.0 - version: 6.0.0 packages/turf-center: dependencies: @@ -7768,6 +7687,9 @@ packages: '@types/node@22.15.3': resolution: {integrity: sha512-lX7HFZeHf4QG/J7tBZqrCAXwz9J5RD56Y6MpP0eJkka8p+K0RY/yBTW7CYFJ4VGCclxqOLKmiGP5juQc6MKgcw==} + '@types/node@22.19.17': + resolution: {integrity: sha512-wGdMcf+vPYM6jikpS/qhg6WiqSV/OhG+jeeHT/KlVqxYfD40iYJf9/AE1uQxVWFvU7MipKRkRv8NSHiCGgPr8Q==} + '@types/normalize-package-data@2.4.4': resolution: {integrity: sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA==} @@ -12678,128 +12600,128 @@ snapshots: '@inquirer/ansi@1.0.2': {} - '@inquirer/checkbox@4.3.2(@types/node@22.15.3)': + '@inquirer/checkbox@4.3.2(@types/node@22.19.17)': dependencies: '@inquirer/ansi': 1.0.2 - '@inquirer/core': 10.3.2(@types/node@22.15.3) + '@inquirer/core': 10.3.2(@types/node@22.19.17) '@inquirer/figures': 1.0.15 - '@inquirer/type': 3.0.10(@types/node@22.15.3) + '@inquirer/type': 3.0.10(@types/node@22.19.17) yoctocolors-cjs: 2.1.3 optionalDependencies: - '@types/node': 22.15.3 + '@types/node': 22.19.17 - '@inquirer/confirm@5.1.21(@types/node@22.15.3)': + '@inquirer/confirm@5.1.21(@types/node@22.19.17)': dependencies: - '@inquirer/core': 10.3.2(@types/node@22.15.3) - '@inquirer/type': 3.0.10(@types/node@22.15.3) + '@inquirer/core': 10.3.2(@types/node@22.19.17) + '@inquirer/type': 3.0.10(@types/node@22.19.17) optionalDependencies: - '@types/node': 22.15.3 + '@types/node': 22.19.17 - '@inquirer/core@10.3.2(@types/node@22.15.3)': + '@inquirer/core@10.3.2(@types/node@22.19.17)': dependencies: '@inquirer/ansi': 1.0.2 '@inquirer/figures': 1.0.15 - '@inquirer/type': 3.0.10(@types/node@22.15.3) + '@inquirer/type': 3.0.10(@types/node@22.19.17) cli-width: 4.1.0 mute-stream: 2.0.0 signal-exit: 4.1.0 wrap-ansi: 6.2.0 yoctocolors-cjs: 2.1.3 optionalDependencies: - '@types/node': 22.15.3 + '@types/node': 22.19.17 - '@inquirer/editor@4.2.23(@types/node@22.15.3)': + '@inquirer/editor@4.2.23(@types/node@22.19.17)': dependencies: - '@inquirer/core': 10.3.2(@types/node@22.15.3) - '@inquirer/external-editor': 1.0.3(@types/node@22.15.3) - '@inquirer/type': 3.0.10(@types/node@22.15.3) + '@inquirer/core': 10.3.2(@types/node@22.19.17) + '@inquirer/external-editor': 1.0.3(@types/node@22.19.17) + '@inquirer/type': 3.0.10(@types/node@22.19.17) optionalDependencies: - '@types/node': 22.15.3 + '@types/node': 22.19.17 - '@inquirer/expand@4.0.23(@types/node@22.15.3)': + '@inquirer/expand@4.0.23(@types/node@22.19.17)': dependencies: - '@inquirer/core': 10.3.2(@types/node@22.15.3) - '@inquirer/type': 3.0.10(@types/node@22.15.3) + '@inquirer/core': 10.3.2(@types/node@22.19.17) + '@inquirer/type': 3.0.10(@types/node@22.19.17) yoctocolors-cjs: 2.1.3 optionalDependencies: - '@types/node': 22.15.3 + '@types/node': 22.19.17 - '@inquirer/external-editor@1.0.3(@types/node@22.15.3)': + '@inquirer/external-editor@1.0.3(@types/node@22.19.17)': dependencies: chardet: 2.1.1 iconv-lite: 0.7.0 optionalDependencies: - '@types/node': 22.15.3 + '@types/node': 22.19.17 '@inquirer/figures@1.0.15': {} - '@inquirer/input@4.3.1(@types/node@22.15.3)': + '@inquirer/input@4.3.1(@types/node@22.19.17)': dependencies: - '@inquirer/core': 10.3.2(@types/node@22.15.3) - '@inquirer/type': 3.0.10(@types/node@22.15.3) + '@inquirer/core': 10.3.2(@types/node@22.19.17) + '@inquirer/type': 3.0.10(@types/node@22.19.17) optionalDependencies: - '@types/node': 22.15.3 + '@types/node': 22.19.17 - '@inquirer/number@3.0.23(@types/node@22.15.3)': + '@inquirer/number@3.0.23(@types/node@22.19.17)': dependencies: - '@inquirer/core': 10.3.2(@types/node@22.15.3) - '@inquirer/type': 3.0.10(@types/node@22.15.3) + '@inquirer/core': 10.3.2(@types/node@22.19.17) + '@inquirer/type': 3.0.10(@types/node@22.19.17) optionalDependencies: - '@types/node': 22.15.3 + '@types/node': 22.19.17 - '@inquirer/password@4.0.23(@types/node@22.15.3)': + '@inquirer/password@4.0.23(@types/node@22.19.17)': dependencies: '@inquirer/ansi': 1.0.2 - '@inquirer/core': 10.3.2(@types/node@22.15.3) - '@inquirer/type': 3.0.10(@types/node@22.15.3) + '@inquirer/core': 10.3.2(@types/node@22.19.17) + '@inquirer/type': 3.0.10(@types/node@22.19.17) optionalDependencies: - '@types/node': 22.15.3 - - '@inquirer/prompts@7.10.1(@types/node@22.15.3)': - dependencies: - '@inquirer/checkbox': 4.3.2(@types/node@22.15.3) - '@inquirer/confirm': 5.1.21(@types/node@22.15.3) - '@inquirer/editor': 4.2.23(@types/node@22.15.3) - '@inquirer/expand': 4.0.23(@types/node@22.15.3) - '@inquirer/input': 4.3.1(@types/node@22.15.3) - '@inquirer/number': 3.0.23(@types/node@22.15.3) - '@inquirer/password': 4.0.23(@types/node@22.15.3) - '@inquirer/rawlist': 4.1.11(@types/node@22.15.3) - '@inquirer/search': 3.2.2(@types/node@22.15.3) - '@inquirer/select': 4.4.2(@types/node@22.15.3) + '@types/node': 22.19.17 + + '@inquirer/prompts@7.10.1(@types/node@22.19.17)': + dependencies: + '@inquirer/checkbox': 4.3.2(@types/node@22.19.17) + '@inquirer/confirm': 5.1.21(@types/node@22.19.17) + '@inquirer/editor': 4.2.23(@types/node@22.19.17) + '@inquirer/expand': 4.0.23(@types/node@22.19.17) + '@inquirer/input': 4.3.1(@types/node@22.19.17) + '@inquirer/number': 3.0.23(@types/node@22.19.17) + '@inquirer/password': 4.0.23(@types/node@22.19.17) + '@inquirer/rawlist': 4.1.11(@types/node@22.19.17) + '@inquirer/search': 3.2.2(@types/node@22.19.17) + '@inquirer/select': 4.4.2(@types/node@22.19.17) optionalDependencies: - '@types/node': 22.15.3 + '@types/node': 22.19.17 - '@inquirer/rawlist@4.1.11(@types/node@22.15.3)': + '@inquirer/rawlist@4.1.11(@types/node@22.19.17)': dependencies: - '@inquirer/core': 10.3.2(@types/node@22.15.3) - '@inquirer/type': 3.0.10(@types/node@22.15.3) + '@inquirer/core': 10.3.2(@types/node@22.19.17) + '@inquirer/type': 3.0.10(@types/node@22.19.17) yoctocolors-cjs: 2.1.3 optionalDependencies: - '@types/node': 22.15.3 + '@types/node': 22.19.17 - '@inquirer/search@3.2.2(@types/node@22.15.3)': + '@inquirer/search@3.2.2(@types/node@22.19.17)': dependencies: - '@inquirer/core': 10.3.2(@types/node@22.15.3) + '@inquirer/core': 10.3.2(@types/node@22.19.17) '@inquirer/figures': 1.0.15 - '@inquirer/type': 3.0.10(@types/node@22.15.3) + '@inquirer/type': 3.0.10(@types/node@22.19.17) yoctocolors-cjs: 2.1.3 optionalDependencies: - '@types/node': 22.15.3 + '@types/node': 22.19.17 - '@inquirer/select@4.4.2(@types/node@22.15.3)': + '@inquirer/select@4.4.2(@types/node@22.19.17)': dependencies: '@inquirer/ansi': 1.0.2 - '@inquirer/core': 10.3.2(@types/node@22.15.3) + '@inquirer/core': 10.3.2(@types/node@22.19.17) '@inquirer/figures': 1.0.15 - '@inquirer/type': 3.0.10(@types/node@22.15.3) + '@inquirer/type': 3.0.10(@types/node@22.19.17) yoctocolors-cjs: 2.1.3 optionalDependencies: - '@types/node': 22.15.3 + '@types/node': 22.19.17 - '@inquirer/type@3.0.10(@types/node@22.15.3)': + '@inquirer/type@3.0.10(@types/node@22.19.17)': optionalDependencies: - '@types/node': 22.15.3 + '@types/node': 22.19.17 '@isaacs/balanced-match@4.0.1': {} @@ -12858,7 +12780,7 @@ snapshots: '@jridgewell/resolve-uri': 3.1.2 '@jridgewell/sourcemap-codec': 1.5.0 - '@lerna/create@9.0.3(@types/node@22.15.3)(typescript@5.8.3)': + '@lerna/create@9.0.3(@types/node@22.19.17)(typescript@5.8.3)': dependencies: '@npmcli/arborist': 9.1.6 '@npmcli/package-json': 7.0.2 @@ -12885,7 +12807,7 @@ snapshots: has-unicode: 2.0.1 ini: 1.3.8 init-package-json: 8.2.2 - inquirer: 12.9.6(@types/node@22.15.3) + inquirer: 12.9.6(@types/node@22.19.17) is-ci: 3.0.1 is-stream: 2.0.0 js-yaml: 4.1.1 @@ -13542,6 +13464,10 @@ snapshots: dependencies: undici-types: 6.21.0 + '@types/node@22.19.17': + dependencies: + undici-types: 6.21.0 + '@types/normalize-package-data@2.4.4': {} '@types/object-assign@4.0.33': {} @@ -13647,7 +13573,7 @@ snapshots: dependencies: '@typescript-eslint/types': 8.31.1 '@typescript-eslint/visitor-keys': 8.31.1 - debug: 4.4.0 + debug: 4.4.3 fast-glob: 3.3.3 is-glob: 4.0.3 minimatch: 9.0.5 @@ -13760,7 +13686,7 @@ snapshots: agent-base@7.1.1: dependencies: - debug: 4.4.0 + debug: 4.4.3 transitivePeerDependencies: - supports-color @@ -15345,14 +15271,14 @@ snapshots: http-proxy-agent@7.0.2: dependencies: agent-base: 7.1.1 - debug: 4.4.0 + debug: 4.4.3 transitivePeerDependencies: - supports-color https-proxy-agent@7.0.4: dependencies: agent-base: 7.1.1 - debug: 4.4.0 + debug: 4.4.3 transitivePeerDependencies: - supports-color @@ -15420,17 +15346,17 @@ snapshots: validate-npm-package-license: 3.0.4 validate-npm-package-name: 6.0.2 - inquirer@12.9.6(@types/node@22.15.3): + inquirer@12.9.6(@types/node@22.19.17): dependencies: '@inquirer/ansi': 1.0.2 - '@inquirer/core': 10.3.2(@types/node@22.15.3) - '@inquirer/prompts': 7.10.1(@types/node@22.15.3) - '@inquirer/type': 3.0.10(@types/node@22.15.3) + '@inquirer/core': 10.3.2(@types/node@22.19.17) + '@inquirer/prompts': 7.10.1(@types/node@22.19.17) + '@inquirer/type': 3.0.10(@types/node@22.19.17) mute-stream: 2.0.0 run-async: 4.0.6 rxjs: 7.8.2 optionalDependencies: - '@types/node': 22.15.3 + '@types/node': 22.19.17 internal-slot@1.0.7: dependencies: @@ -15734,9 +15660,9 @@ snapshots: kuler@2.0.0: {} - lerna@9.0.3(@types/node@22.15.3): + lerna@9.0.3(@types/node@22.19.17): dependencies: - '@lerna/create': 9.0.3(@types/node@22.15.3)(typescript@5.8.3) + '@lerna/create': 9.0.3(@types/node@22.19.17)(typescript@5.8.3) '@npmcli/arborist': 9.1.6 '@npmcli/package-json': 7.0.2 '@npmcli/run-script': 10.0.2 @@ -15766,7 +15692,7 @@ snapshots: import-local: 3.1.0 ini: 1.3.8 init-package-json: 8.2.2 - inquirer: 12.9.6(@types/node@22.15.3) + inquirer: 12.9.6(@types/node@22.19.17) is-ci: 3.0.1 is-stream: 2.0.0 jest-diff: 30.2.0 @@ -17492,7 +17418,7 @@ snapshots: socks-proxy-agent@8.0.3: dependencies: agent-base: 7.1.1 - debug: 4.4.0 + debug: 4.4.3 socks: 2.7.1 transitivePeerDependencies: - supports-color @@ -17659,7 +17585,7 @@ snapshots: sucrase@3.35.0: dependencies: - '@jridgewell/gen-mapping': 0.3.5 + '@jridgewell/gen-mapping': 0.3.8 commander: 4.1.1 glob: 10.5.0 lines-and-columns: 1.2.4 @@ -17835,7 +17761,7 @@ snapshots: cac: 6.7.14 chokidar: 4.0.3 consola: 3.4.2 - debug: 4.4.0 + debug: 4.4.3 esbuild: 0.25.3 joycon: 3.1.1 picocolors: 1.1.1 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 8226f7e5a7..1f5be2424c 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -4,6 +4,7 @@ packages: catalog: "@types/benchmark": ^2.1.5 "@types/geojson": ^7946.0.10 + "@types/node": ^22.19.17 "@types/tape": ^5.8.1 benchmark: ^2.1.4 tape: ^5.9.0 diff --git a/support/testFixtures.mts b/support/testFixtures.mts index f568cfd849..3aae276d78 100644 --- a/support/testFixtures.mts +++ b/support/testFixtures.mts @@ -3,6 +3,18 @@ import { readdir, readFile, writeFile } from "node:fs/promises"; import path from "node:path"; import type { TestContext } from "node:test"; +const VALID_TYPES: ReadonlySet = new Set([ + "Feature", + "FeatureCollection", + "GeometryCollection", + "Point", + "LineString", + "Polygon", + "MultiPoint", + "MultiLineString", + "MultiPolygon", +]); + export async function testFixtures(t: TestContext, fn: (input: any) => any) { const dirs = { in: path.join(process.cwd(), "test", "in"), @@ -12,9 +24,19 @@ export async function testFixtures(t: TestContext, fn: (input: any) => any) { for (const file of await readdir(dirs.in)) { await t.test(file, async () => { const inputPath = path.join(dirs.in, file); - const outputPath = path.join(dirs.out, file); const inputData = JSON.parse(await readFile(inputPath, "utf-8")); const result = fn(inputData); + + let outputPath = path.join(dirs.out, file); + // if we don't have geojson output, we should use .json instead + if ( + result == null || + typeof result != "object" || + !VALID_TYPES.has(result.type) + ) { + outputPath = outputPath.replace(/\.geojson$/, ".json"); + } + if (process.env.REGEN) { await writeFile(outputPath, JSON.stringify(result, null, 2)); } else {