Skip to content

Commit cd17d63

Browse files
committed
feat: re-add Blob support
`pack` will return a `Promise` when it packs a `Blob` Switching to `bun test`. `jsdom` is annoying. Closes #61
1 parent 9a2efa9 commit cd17d63

24 files changed

+1698
-16104
lines changed

.github/workflows/bun.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3+
4+
name: Bun CI
5+
6+
on:
7+
push:
8+
pull_request:
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: oven-sh/setup-bun@v1
16+
- run: bun install --frozen-lockfile
17+
- run: bun run build
18+
- run: bun test
19+
- run: bun run check

.github/workflows/node.js.yml

-34
This file was deleted.
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3+
4+
name: Node.js CI
5+
6+
on:
7+
push:
8+
branches: ["master"]
9+
pull_request:
10+
branches: ["master"]
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
matrix:
18+
node-version: [16.x, 18.x, 20.x]
19+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
20+
21+
steps:
22+
- uses: actions/checkout@v3
23+
- name: Use Node.js ${{ matrix.node-version }}
24+
uses: actions/setup-node@v3
25+
with:
26+
node-version: ${{ matrix.node-version }}
27+
cache: "npm"
28+
- run: npm ci
29+
- run: npm run build
30+
- run: npm run coverage
31+
- name: Publish code coverage to CodeClimate
32+
uses: paambaati/[email protected]
33+
env:
34+
CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}

.github/workflows/prettier.yml

+7-14
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
1-
# From https://til.simonwillison.net/github-actions/prettier-github-actions
21
name: Check JavaScript for conformance with Prettier
32

43
on:
54
push:
65
pull_request:
76

87
jobs:
9-
prettier:
8+
biome:
109
runs-on: ubuntu-latest
1110
steps:
12-
- name: Check out repo
13-
uses: actions/checkout@v3
14-
- uses: actions/cache@v3
15-
name: Configure npm caching
16-
with:
17-
path: ~/.npm
18-
key: ${{ runner.os }}-npm-${{ hashFiles('**/workflows/prettier.yml') }}
19-
restore-keys: |
20-
${{ runner.os }}-npm-
21-
- name: Run prettier
22-
run: |-
23-
npx prettier --check .
11+
- name: Checkout
12+
uses: actions/checkout@v4
13+
- name: Setup Biome
14+
uses: biomejs/setup-biome@v1
15+
- name: Run Biome
16+
run: biome ci .

.github/workflows/release.yml

+4-7
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,13 @@ jobs:
1313
uses: actions/checkout@v3
1414
with:
1515
fetch-depth: 0
16-
- name: Setup Node.js
17-
uses: actions/setup-node@v3
18-
with:
19-
node-version: "lts/*"
16+
- uses: oven-sh/setup-bun@v1
2017
- name: Install dependencies
21-
run: npm ci
18+
run: bun install --frozen-lockfile
2219
- name: Build
23-
run: npm run build
20+
run: bun run build
2421
- name: Release
2522
env:
2623
GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_GH_TOKEN }}
2724
NPM_TOKEN: ${{ secrets.SEMANTIC_RELEASE_NPM_TOKEN }}
28-
run: npx semantic-release
25+
run: bun run semantic-release

.npmignore

Whitespace-only changes.

.prettierignore

-6
This file was deleted.

.prettierrc.toml

-3
This file was deleted.

.vscode/settings.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
{
2-
"standard.semistandard": true,
3-
"standard.usePackageJson": true,
4-
"standard.autoFixOnSave": true,
5-
"javascript.validate.enable": false,
6-
"eslint.autoFixOnSave": true
2+
"editor.defaultFormatter": "biomejs.biome"
73
}

__test__/blobs.spec.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { expect, describe, it } from "@jest/globals";
2+
3+
import { packAndUnpack } from "./util";
4+
5+
import data, { blob, objWithBlob } from "./data";
6+
import { pack, unpack } from "../lib/binarypack";
7+
8+
describe("Blobs", () => {
9+
it("replaces Blobs with ArrayBuffer ", async () => {
10+
expect(await packAndUnpack(blob)).toStrictEqual(await blob.arrayBuffer());
11+
});
12+
it("replaces Blobs with ArrayBuffer in objects ", async () => {
13+
const objWithAB = {
14+
...objWithBlob,
15+
blob: await objWithBlob.blob.arrayBuffer(),
16+
};
17+
expect(await packAndUnpack(objWithBlob)).toStrictEqual(objWithAB);
18+
});
19+
it("keep Text decodable", async () => {
20+
for (const commit of data) {
21+
const json = JSON.stringify(commit);
22+
const blob = new Blob([json], { type: "application/json" });
23+
const decoded = new TextDecoder().decode(
24+
await packAndUnpack<ArrayBuffer>(blob),
25+
);
26+
expect(decoded).toStrictEqual(json);
27+
}
28+
});
29+
});

__test__/bugs.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ import { packAndUnpack } from "./util";
55
describe("Bugs", () => {
66
describe("Objects", () => {
77
it("replaces undefined with null ", async () => {
8-
expect(await packAndUnpack(undefined)).toBe(null);
8+
expect(packAndUnpack(undefined)).toBe(null);
99
});
1010
});
1111
describe("Numbers", () => {
1212
it("gives back wrong value on INT64_MAX ", async () => {
13-
expect(await packAndUnpack(0x7fffffffffffffff)).toBe(
14-
-9223372036854776000,
15-
);
13+
expect(packAndUnpack(0x7fffffffffffffff)).not.toEqual(0x7fffffffffffffff);
1614
});
1715
});
1816
});

0 commit comments

Comments
 (0)