Skip to content

Commit d31e636

Browse files
authored
Revert "Modernize test/bench runners (#3038)" (#3060)
This reverts commit eb94133.
1 parent eb94133 commit d31e636

10 files changed

Lines changed: 138 additions & 154 deletions

File tree

.monorepolint.config.mjs

Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const PACKAGES = []; // packages that aren't @turf/turf
1616
const MAIN_PACKAGE = "@turf/turf";
1717

1818
const TAPE_PACKAGES = []; // packages that have tape tests
19-
const NODE_TEST_PACKAGES = []; // projects that use node's native test runner
2019
const TYPES_PACKAGES = []; // packages that have types tests
2120
const TSTYCHE_PACKAGES = []; // packages that use tstyche for type tests.
2221

@@ -33,16 +32,8 @@ for (const pk of await fs.readdir(packagesPath)) {
3332

3433
PACKAGES.push(name);
3534

36-
if (existsSync(path.join(packagesPath, pk, "test.ts"))) {
37-
const testFileContents = await fs.readFile(
38-
path.join(packagesPath, pk, "test.ts"),
39-
"utf-8"
40-
);
41-
if (testFileContents.includes(`from "tape"`)) {
42-
TAPE_PACKAGES.push(name);
43-
} else {
44-
NODE_TEST_PACKAGES.push(name);
45-
}
35+
if (existsSync(path.join(pk, "test.js"))) {
36+
TAPE_PACKAGES.push(name);
4637
}
4738

4839
if (existsSync(path.join(packagesPath, pk, "types.ts"))) {
@@ -207,23 +198,11 @@ export default {
207198
scripts: {
208199
bench: "tsx bench.ts",
209200
"test:tape": "tsx test.ts",
210-
"test:node": REMOVE,
211201
},
212202
},
213203
includePackages: TAPE_PACKAGES,
214204
}),
215205

216-
packageScript({
217-
options: {
218-
scripts: {
219-
bench: "node bench.ts",
220-
"test:node": "node --test",
221-
"test:tape": REMOVE,
222-
},
223-
},
224-
includePackages: NODE_TEST_PACKAGES,
225-
}),
226-
227206
packageScript({
228207
options: {
229208
scripts: {
@@ -254,43 +233,20 @@ export default {
254233
},
255234
},
256235
includePackages: PACKAGES,
257-
excludePackages: NODE_TEST_PACKAGES,
258-
}),
259-
260-
requireDependency({
261-
options: {
262-
devDependencies: {
263-
tape: "catalog:",
264-
"@types/tape": "catalog:",
265-
},
266-
},
267-
includePackages: TAPE_PACKAGES,
268236
}),
269237

270238
requireDependency({
271239
options: {
272-
devDependencies: {
273-
"@types/benchmark": REMOVE,
274-
"@types/tape": REMOVE,
275-
benchmark: REMOVE,
276-
"load-json-file": REMOVE,
277-
tape: REMOVE,
278-
tsx: REMOVE,
279-
"write-json-file": REMOVE,
240+
dependencies: {
241+
tslib: "catalog:",
280242
},
281-
},
282-
includePackages: NODE_TEST_PACKAGES,
283-
}),
284-
285-
requireDependency({
286-
options: {
287243
devDependencies: {
288244
"@types/benchmark": "catalog:",
289-
benchmark: "catalog:",
245+
"@types/tape": "catalog:",
246+
typescript: "catalog:",
290247
},
291248
},
292249
includePackages: PACKAGES,
293-
excludePackages: NODE_TEST_PACKAGES,
294250
}),
295251

296252
requireDependency({

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@
3636
"@monorepolint/config": "0.6.0-alpha.6",
3737
"@monorepolint/core": "0.6.0-alpha.6",
3838
"@monorepolint/rules": "0.6.0-alpha.6",
39-
"@types/benchmark": "^2.1.5",
4039
"@types/node": "22.15.3",
4140
"acorn": "^8.14.1",
42-
"benchmark": "^2.1.4",
4341
"camelcase": "^8.0.0",
4442
"d3-queue": "*",
4543
"decamelize": "^6.0.0",

packages/turf-center/bench.ts

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,48 @@
1-
import { center } from "./index.ts";
2-
import { benchFixtures } from "../../support/benchFixtures.mts";
3-
4-
// Benchmark Results
5-
// feature-collection.geojson x 27,241,658 ops/sec ±0.34% (99 runs sampled)
6-
// imbalanced-polygon.geojson x 14,679,583 ops/sec ±0.27% (98 runs sampled)
7-
// linestring.geojson x 34,199,495 ops/sec ±0.52% (95 runs sampled)
8-
// point.geojson x 52,230,993 ops/sec ±0.70% (96 runs sampled)
9-
// points-with-weights.geojson x 24,802,237 ops/sec ±0.33% (100 runs sampled)
10-
// polygon-without-weights.geojson x 18,423,881 ops/sec ±0.28% (100 runs sampled)
11-
// polygon.geojson x 24,990,920 ops/sec ±0.45% (99 runs sampled)
12-
await benchFixtures("turf-center", (input) => center(input));
1+
import path from "path";
2+
import { fileURLToPath } from "url";
3+
import { glob } from "glob";
4+
import { loadJsonFileSync } from "load-json-file";
5+
import Benchmark from "benchmark";
6+
import { center } from "./index.js";
7+
8+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
9+
10+
const fixtures = glob
11+
.sync(path.join(__dirname, "test", "in", "*.geojson"))
12+
.map((input) => {
13+
return {
14+
name: path.parse(input).name,
15+
geojson: loadJsonFileSync(input),
16+
};
17+
});
18+
19+
/**
20+
* Single Process Benchmark
21+
*
22+
* feature-collection: 0.445ms
23+
* imbalanced-polygon: 0.051ms
24+
* linestring: 0.027ms
25+
* point: 0.011ms
26+
* polygon: 0.013ms
27+
*/
28+
for (const { name, geojson } of fixtures) {
29+
console.time(name);
30+
center(geojson);
31+
console.timeEnd(name);
32+
}
33+
34+
/**
35+
* Benchmark Results
36+
*
37+
* feature-collection x 2,786,700 ops/sec ±1.50% (83 runs sampled)
38+
* imbalanced-polygon x 1,364,145 ops/sec ±3.33% (76 runs sampled)
39+
* linestring x 4,104,106 ops/sec ±4.16% (81 runs sampled)
40+
* point x 4,901,692 ops/sec ±5.23% (81 runs sampled)
41+
* polygon x 2,862,759 ops/sec ±1.14% (86 runs sampled)
42+
*/
43+
const suite = new Benchmark.Suite("turf-center");
44+
for (const { name, geojson } of fixtures) {
45+
suite.add(name, () => center(geojson));
46+
}
47+
48+
suite.on("cycle", (e) => console.log(String(e.target))).run();

packages/turf-center/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { BBox, Feature, GeoJsonProperties, Point } from "geojson";
1+
import { BBox, Feature, GeoJsonProperties, Point } from "geojson";
22
import { bbox } from "@turf/bbox";
3-
import { point, type Id, type AllGeoJSON } from "@turf/helpers";
3+
import { point, Id, AllGeoJSON } from "@turf/helpers";
44

55
/**
66
* Takes a {@link Feature} or {@link FeatureCollection} and returns the absolute center point of all features.

packages/turf-center/package.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,24 @@
4646
"dist"
4747
],
4848
"scripts": {
49-
"bench": "node bench.ts",
49+
"bench": "tsx bench.ts",
5050
"build": "tsup --config ../../tsup.config.ts",
5151
"test": "pnpm run /test:.*/",
52-
"test:node": "node --test",
52+
"test:tape": "tsx test.ts",
5353
"test:types": "tsc --esModuleInterop --module node16 --moduleResolution node16 --noEmit --strict types.ts"
5454
},
5555
"devDependencies": {
5656
"@turf/bbox-polygon": "workspace:*",
5757
"@turf/meta": "workspace:*",
58+
"@types/benchmark": "catalog:",
59+
"@types/tape": "catalog:",
60+
"benchmark": "catalog:",
61+
"load-json-file": "^7.0.1",
62+
"tape": "catalog:",
5863
"tsup": "catalog:",
59-
"typescript": "catalog:"
64+
"tsx": "catalog:",
65+
"typescript": "catalog:",
66+
"write-json-file": "^6.0.0"
6067
},
6168
"dependencies": {
6269
"@turf/bbox": "workspace:*",

packages/turf-center/test.ts

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,61 @@
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";
1012

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));
1614

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);
3523

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();
3851
});
3952

40-
test("turf-center -- properties", () => {
53+
test("turf-center -- properties", (t) => {
4154
const line = lineString([
4255
[0, 0],
4356
[1, 1],
4457
]);
4558
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();
4761
});

pnpm-lock.yaml

Lines changed: 21 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

support/benchFixtures.mts

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)