run prettier on js/test; add prettier check to CI

This commit is contained in:
Brandon Liu
2023-03-12 13:30:57 +08:00
parent 606c80a1fc
commit 802f6aea4e
5 changed files with 414 additions and 400 deletions

View File

@@ -44,6 +44,7 @@ jobs:
node-version: 18.x
- run: python .github/check_examples.py
- run: cd js && npm install && npm test
- run: cd js && npm prettier-check
- run: cd python && python -m unittest test/test_*
- run: cd cpp && make
- run: cd serverless/cloudflare && npm install && npm test

View File

@@ -18,7 +18,8 @@
"build": "npm run build-iife && npm run build-esm && npm run build-cjs && npm run build-tsc",
"test": "node -r esbuild-runner/register test/index.test.ts",
"tsc": "tsc --noEmit --watch",
"prettier": "prettier --write *.ts"
"prettier": "prettier --write *.ts test/*.ts",
"prettier-check": "prettier --check *.ts test/*.ts"
},
"homepage": "https://github.com/protomaps/pmtiles",
"author": "Brandon Liu",

View File

@@ -1,2 +1,2 @@
import './v2.test';
import './v3.test';
import "./v2.test";
import "./v3.test";

View File

@@ -14,7 +14,8 @@ import {
} from "../v2";
test("stub data", () => {
let dataview = new DataView(createDirectory([
let dataview = new DataView(
createDirectory([
{ z: 5, x: 1000, y: 2000, offset: 1000, length: 2000, is_dir: false },
{
z: 14,
@@ -24,19 +25,21 @@ test("stub data", () => {
length: 999,
is_dir: false,
},
]));
])
);
var z_raw = dataview.getUint8(17 + 0);
var x = getUint24(dataview, 17 + 1);
var y = getUint24(dataview, 17 + 4);
var offset = getUint48(dataview, 17 + 7);
var length = dataview.getUint32(17 + 13, true);
assert.strictEqual(z_raw,14);
assert.strictEqual(x,16383);
assert.strictEqual(y,16383);
assert.strictEqual(z_raw, 14);
assert.strictEqual(x, 16383);
assert.strictEqual(y, 16383);
});
test("get entry", () => {
let view = new DataView(createDirectory([
let view = new DataView(
createDirectory([
{ z: 5, x: 1000, y: 2000, offset: 1000, length: 2000, is_dir: false },
{
z: 14,
@@ -46,19 +49,21 @@ test("get entry", () => {
length: 999,
is_dir: false,
},
]));
])
);
let entry = queryTile(view, 14, 16383, 16383);
assert.strictEqual(entry!.z,14);
assert.strictEqual(entry!.x,16383);
assert.strictEqual(entry!.y,16383);
assert.strictEqual(entry!.offset,999999);
assert.strictEqual(entry!.length,999);
assert.strictEqual(entry!.is_dir,false);
assert.strictEqual(queryLeafdir(view, 14, 16383, 16383),null);
assert.strictEqual(entry!.z, 14);
assert.strictEqual(entry!.x, 16383);
assert.strictEqual(entry!.y, 16383);
assert.strictEqual(entry!.offset, 999999);
assert.strictEqual(entry!.length, 999);
assert.strictEqual(entry!.is_dir, false);
assert.strictEqual(queryLeafdir(view, 14, 16383, 16383), null);
});
test("get leafdir", () => {
let view = new DataView(createDirectory([
let view = new DataView(
createDirectory([
{
z: 14,
x: 16383,
@@ -67,19 +72,21 @@ test("get leafdir", () => {
length: 999,
is_dir: true,
},
]));
])
);
let entry = queryLeafdir(view, 14, 16383, 16383);
assert.strictEqual(entry!.z,14);
assert.strictEqual(entry!.x,16383);
assert.strictEqual(entry!.y,16383);
assert.strictEqual(entry!.offset,999999);
assert.strictEqual(entry!.length,999);
assert.strictEqual(entry!.is_dir,true);
assert.strictEqual(queryTile(view, 14, 16383, 16383),null);
assert.strictEqual(entry!.z, 14);
assert.strictEqual(entry!.x, 16383);
assert.strictEqual(entry!.y, 16383);
assert.strictEqual(entry!.offset, 999999);
assert.strictEqual(entry!.length, 999);
assert.strictEqual(entry!.is_dir, true);
assert.strictEqual(queryTile(view, 14, 16383, 16383), null);
});
test("derive the leaf level", () => {
let view = new DataView(createDirectory([
let view = new DataView(
createDirectory([
{
z: 6,
x: 3,
@@ -88,12 +95,14 @@ test("derive the leaf level", () => {
length: 0,
is_dir: true,
},
]));
let leaf = deriveLeaf(view,{z:7,x:6,y:6});
assert.strictEqual(leaf!.z,6);
assert.strictEqual(leaf!.x,3);
assert.strictEqual(leaf!.y,3);
view = new DataView(createDirectory([
])
);
let leaf = deriveLeaf(view, { z: 7, x: 6, y: 6 });
assert.strictEqual(leaf!.z, 6);
assert.strictEqual(leaf!.x, 3);
assert.strictEqual(leaf!.y, 3);
view = new DataView(
createDirectory([
{
z: 6,
x: 3,
@@ -102,13 +111,15 @@ test("derive the leaf level", () => {
length: 0,
is_dir: false,
},
]));
leaf = deriveLeaf(view,{z:7,x:6,y:6});
assert.strictEqual(leaf,null);
])
);
leaf = deriveLeaf(view, { z: 7, x: 6, y: 6 });
assert.strictEqual(leaf, null);
});
test("convert spec v1 directory to spec v2 directory", () => {
let view = new DataView(createDirectory([
let view = new DataView(
createDirectory([
{
z: 7,
x: 3,
@@ -133,18 +144,19 @@ test("convert spec v1 directory to spec v2 directory", () => {
length: 1,
is_dir: false,
},
]));
])
);
let entry = queryLeafdir(view, 7, 3, 3);
assert.strictEqual(entry!.offset,3);
assert.strictEqual(entry!.offset, 3);
entry = queryTile(view, 6, 2, 2);
assert.strictEqual(entry!.offset,2);
assert.strictEqual(entry!.offset, 2);
entry = queryTile(view, 6, 2, 1);
assert.strictEqual(entry!.offset,1);
assert.strictEqual(entry!.offset, 1);
entry = parseEntry(view, 0);
assert.strictEqual(entry!.offset,1);
assert.strictEqual(entry!.offset, 1);
entry = parseEntry(view, 1);
assert.strictEqual(entry!.offset,2);
assert.strictEqual(entry!.offset, 2);
entry = parseEntry(view, 2);
assert.strictEqual(entry!.offset,3);
assert.strictEqual(entry!.offset, 3);
});

View File

@@ -84,11 +84,11 @@ test("invalid tiles", () => {
});
assert.throws(() => {
zxyToTileId(27,0,0);
zxyToTileId(27, 0, 0);
});
assert.throws(() => {
zxyToTileId(0,1,1);
zxyToTileId(0, 1, 1);
});
});
@@ -311,7 +311,7 @@ test("etags are part of key", async () => {
header.rootDirectoryLength,
header
);
})
});
cache.invalidate(source, "etag_2");
header = await cache.getHeader(source);
@@ -344,7 +344,7 @@ test("soft failure on etag weirdness", async () => {
header.rootDirectoryLength,
header
);
})
});
source.etag = "etag_1";
cache.invalidate(source, "etag_2");