Skip to content

Commit

Permalink
feat: re-add Blob support (#62)
Browse files Browse the repository at this point in the history
`pack` will return a `Promise` when it packs a `Blob`.

Closes #61
  • Loading branch information
jonasgloning authored Dec 3, 2023
2 parents b79775b + 2eb5afb commit e79d1ee
Show file tree
Hide file tree
Showing 24 changed files with 1,698 additions and 16,104 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/bun.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Bun CI

on:
push:
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- run: bun install --frozen-lockfile
- run: bun run build
- run: bun test
- run: bun run check
34 changes: 0 additions & 34 deletions .github/workflows/node.js.yml

This file was deleted.

34 changes: 34 additions & 0 deletions .github/workflows/node.js.yml.deactivated
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js CI

on:
push:
branches: ["master"]
pull_request:
branches: ["master"]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
- run: npm ci
- run: npm run build
- run: npm run coverage
- name: Publish code coverage to CodeClimate
uses: paambaati/[email protected]
env:
CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
21 changes: 7 additions & 14 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
# From https://til.simonwillison.net/github-actions/prettier-github-actions
name: Check JavaScript for conformance with Prettier

on:
push:
pull_request:

jobs:
prettier:
biome:
runs-on: ubuntu-latest
steps:
- name: Check out repo
uses: actions/checkout@v3
- uses: actions/cache@v3
name: Configure npm caching
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('**/workflows/prettier.yml') }}
restore-keys: |
${{ runner.os }}-npm-
- name: Run prettier
run: |-
npx prettier --check .
- name: Checkout
uses: actions/checkout@v4
- name: Setup Biome
uses: biomejs/setup-biome@v1
- name: Run Biome
run: biome ci .
11 changes: 4 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "lts/*"
- uses: oven-sh/setup-bun@v1
- name: Install dependencies
run: npm ci
run: bun install --frozen-lockfile
- name: Build
run: npm run build
run: bun run build
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_GH_TOKEN }}
NPM_TOKEN: ${{ secrets.SEMANTIC_RELEASE_NPM_TOKEN }}
run: npx semantic-release
run: bun run semantic-release
Empty file removed .npmignore
Empty file.
6 changes: 0 additions & 6 deletions .prettierignore

This file was deleted.

3 changes: 0 additions & 3 deletions .prettierrc.toml

This file was deleted.

6 changes: 1 addition & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
{
"standard.semistandard": true,
"standard.usePackageJson": true,
"standard.autoFixOnSave": true,
"javascript.validate.enable": false,
"eslint.autoFixOnSave": true
"editor.defaultFormatter": "biomejs.biome"
}
29 changes: 29 additions & 0 deletions __test__/blobs.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { expect, describe, it } from "@jest/globals";

import { packAndUnpack } from "./util";

import data, { blob, objWithBlob } from "./data";
import { pack, unpack } from "../lib/binarypack";

describe("Blobs", () => {
it("replaces Blobs with ArrayBuffer ", async () => {
expect(await packAndUnpack(blob)).toStrictEqual(await blob.arrayBuffer());
});
it("replaces Blobs with ArrayBuffer in objects ", async () => {
const objWithAB = {
...objWithBlob,
blob: await objWithBlob.blob.arrayBuffer(),
};
expect(await packAndUnpack(objWithBlob)).toStrictEqual(objWithAB);
});
it("keep Text decodable", async () => {
for (const commit of data) {
const json = JSON.stringify(commit);
const blob = new Blob([json], { type: "application/json" });
const decoded = new TextDecoder().decode(
await packAndUnpack<ArrayBuffer>(blob),
);
expect(decoded).toStrictEqual(json);
}
});
});
6 changes: 2 additions & 4 deletions __test__/bugs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import { packAndUnpack } from "./util";
describe("Bugs", () => {
describe("Objects", () => {
it("replaces undefined with null ", async () => {
expect(await packAndUnpack(undefined)).toBe(null);
expect(packAndUnpack(undefined)).toBe(null);
});
});
describe("Numbers", () => {
it("gives back wrong value on INT64_MAX ", async () => {
expect(await packAndUnpack(0x7fffffffffffffff)).toBe(
-9223372036854776000,
);
expect(packAndUnpack(0x7fffffffffffffff)).not.toEqual(0x7fffffffffffffff);
});
});
});
Loading

0 comments on commit e79d1ee

Please sign in to comment.