port tests to node 18 test module; remove zora dep

This commit is contained in:
Brandon Liu
2022-11-22 20:38:14 +08:00
parent f457724da1
commit 47d35484fc
9 changed files with 778 additions and 221 deletions

View File

@@ -11,8 +11,7 @@
"@cloudflare/workers-types": "^3.17.0",
"esbuild-runner": "^2.2.2",
"typescript": "^4.8.4",
"wrangler": "2.1.12",
"zora": "^5.1.0"
"wrangler": "2.1.12"
}
},
"node_modules/@cloudflare/kv-asset-handler": {
@@ -1571,12 +1570,6 @@
"mustache": "^4.2.0",
"stack-trace": "0.0.10"
}
},
"node_modules/zora": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/zora/-/zora-5.1.0.tgz",
"integrity": "sha512-ikV3raEYF44q4BWfWzalqceCelgQPFxCjK61Nt6NNLfogRIezZmY3A/oGzOuSqLV8iySsw4xcrrFTEaCf6LY+g==",
"dev": true
}
},
"dependencies": {
@@ -2637,12 +2630,6 @@
"mustache": "^4.2.0",
"stack-trace": "0.0.10"
}
},
"zora": {
"version": "5.1.0",
"resolved": "https://registry.npmjs.org/zora/-/zora-5.1.0.tgz",
"integrity": "sha512-ikV3raEYF44q4BWfWzalqceCelgQPFxCjK61Nt6NNLfogRIezZmY3A/oGzOuSqLV8iySsw4xcrrFTEaCf6LY+g==",
"dev": true
}
}
}

View File

@@ -5,8 +5,7 @@
"@cloudflare/workers-types": "^3.17.0",
"esbuild-runner": "^2.2.2",
"typescript": "^4.8.4",
"wrangler": "2.1.12",
"zora": "^5.1.0"
"wrangler": "2.1.12"
},
"private": true,
"scripts": {

View File

@@ -1,58 +1,72 @@
import { test } from "zora";
import { test } from "node:test";
import assert from "node:assert";
import { pmtiles_path, tile_path } from "./index";
test("pmtiles path", (assertion) => {
test("pmtiles path", () => {
let result = pmtiles_path("foo", undefined);
assertion.equal(result, "foo.pmtiles");
assert.strictEqual(result, "foo.pmtiles");
});
test("pmtiles path", (assertion) => {
let result = pmtiles_path("foo","folder/{name}/file.pmtiles");
assertion.equal(result, "folder/foo/file.pmtiles");
test("pmtiles path", () => {
let result = pmtiles_path("foo", "folder/{name}/file.pmtiles");
assert.strictEqual(result, "folder/foo/file.pmtiles");
});
test("pmtiles path with slash", (assertion) => {
let result = pmtiles_path("foo/bar","folder/{name}/file.pmtiles");
assertion.equal(result, "folder/foo/bar/file.pmtiles");
test("pmtiles path with slash", () => {
let result = pmtiles_path("foo/bar", "folder/{name}/file.pmtiles");
assert.strictEqual(result, "folder/foo/bar/file.pmtiles");
});
test("pmtiles path with multiple names", (assertion) => {
let result = pmtiles_path("slug","folder/{name}/{name}.pmtiles");
assertion.equal(result, "folder/slug/slug.pmtiles");
result = pmtiles_path("foo/bar","folder/{name}/{name}.pmtiles");
assertion.equal(result, "folder/foo/bar/foo/bar.pmtiles");
test("pmtiles path with multiple names", () => {
let result = pmtiles_path("slug", "folder/{name}/{name}.pmtiles");
assert.strictEqual(result, "folder/slug/slug.pmtiles");
result = pmtiles_path("foo/bar", "folder/{name}/{name}.pmtiles");
assert.strictEqual(result, "folder/foo/bar/foo/bar.pmtiles");
});
test("parse tile default", (assertion) => {
let {ok, name, tile, ext} = tile_path("abcd");
assertion.equal(ok, false);
test("parse tile default", () => {
let { ok, name, tile, ext } = tile_path("abcd");
assert.strictEqual(ok, false);
({name, tile} = tile_path("/foo/11/22/33.pbf"));
assertion.equal(name,"foo");
assertion.equal(tile[0],11);
assertion.equal(tile[1],22);
assertion.equal(tile[2],33);
({ name, tile } = tile_path("/foo/11/22/33.pbf"));
assert.strictEqual(name, "foo");
assert.strictEqual(tile[0], 11);
assert.strictEqual(tile[1], 22);
assert.strictEqual(tile[2], 33);
});
test("parse tile path setting", (assertion) => {
let {ok, name, tile, ext} = tile_path("/foo/11/22/33.pbf","/{name}/{z}/{y}/{x}.{ext}");
assertion.equal(tile[1],33);
assertion.equal(tile[2],22);
assertion.equal(ext,"pbf");
({ok, name, tile, ext} = tile_path("/tiles/foo/4/2/3.mvt","/tiles/{name}/{z}/{x}/{y}.{ext}"));
assertion.equal(name,"foo");
assertion.equal(tile[0],4);
assertion.equal(tile[1],2);
assertion.equal(tile[2],3);
assertion.equal(ext,"mvt");
test("parse tile path setting", () => {
let { ok, name, tile, ext } = tile_path(
"/foo/11/22/33.pbf",
"/{name}/{z}/{y}/{x}.{ext}"
);
assert.strictEqual(tile[1], 33);
assert.strictEqual(tile[2], 22);
assert.strictEqual(ext, "pbf");
({ ok, name, tile, ext } = tile_path(
"/tiles/foo/4/2/3.mvt",
"/tiles/{name}/{z}/{x}/{y}.{ext}"
));
assert.strictEqual(name, "foo");
assert.strictEqual(tile[0], 4);
assert.strictEqual(tile[1], 2);
assert.strictEqual(tile[2], 3);
assert.strictEqual(ext, "mvt");
});
test("parse tile path setting special chars", (assertion) => {
let {ok, name, tile, ext} = tile_path("/folder(new/foo/11/22/33.pbf","/folder(new/{name}/{z}/{y}/{x}.{ext}");
assertion.equal(name,"foo");
test("parse tile path setting special chars", () => {
let { ok, name, tile, ext } = tile_path(
"/folder(new/foo/11/22/33.pbf",
"/folder(new/{name}/{z}/{y}/{x}.{ext}"
);
assert.strictEqual(name, "foo");
});
test("parse tile path setting slash", (assertion) => {
let {ok, name, tile, ext} = tile_path("/foo/bar/11/22/33.pbf","/{name}/{z}/{y}/{x}.{ext}");
assertion.equal(name,"foo/bar");
test("parse tile path setting slash", () => {
let { ok, name, tile, ext } = tile_path(
"/foo/bar/11/22/33.pbf",
"/{name}/{z}/{y}/{x}.{ext}"
);
assert.strictEqual(name, "foo/bar");
});

View File

@@ -8,7 +8,8 @@
"module": "es2022",
"moduleResolution": "node",
"types": [
"@cloudflare/workers-types"
"@cloudflare/workers-types",
"node"
],
"resolveJsonModule": true,
"allowJs": true,