Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .github/workflows/deno.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ name: Deno

on:
push:
branches: ["main"]
branches: ['main']
tags:
- v*
pull_request:
branches: ["main"]
branches: ['main']

permissions:
contents: read
Expand All @@ -28,16 +28,19 @@ jobs:
uses: actions/checkout@v3

- name: Setup Deno
uses: denoland/setup-deno@v1
uses: denoland/setup-deno@v2
with:
deno-version: v1.x
deno-version: v2.x

- name: Verify formatting
run: deno fmt --check

- name: Run linter
run: deno lint

- name: Install Bext
run: deno task install

- name: Run tests
run: deno task test
release:
Expand Down
34 changes: 22 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ browser.
> bext --source=src # --source or -s: specify source directory (default: "source")
> bext --source=src --static=assets # --static or -t: specify static assets directory (default: "static")
> bext --source=src --static=assets --output=build # --output or -o: specify output directory (default: "dist")

> bext --config=../deno.json # --config or -c: specify deno.json config file. If using a workspace, point at the root workspace deno.json
```

## Types and Utilities
Expand Down Expand Up @@ -63,35 +65,43 @@ browserAPI.tabs.onUpdated.addListener(
bext `browserAPI` will also return a mock browser when running in a Deno environment (where native extension apis don't exist). This makes writing unit tests a breeze!

```ts
import browserAPI, { isDeno } from 'jsr:@bpev/bext';
import { assertStrictEquals } from 'jsr:@std/assert';
import { assertSpyCall, assertSpyCalls, stub } from 'jsr:@std/testing/mock';
import browserAPI, { isDeno } from 'jsr:@bpev/bext'
import { assertStrictEquals } from 'jsr:@std/assert'
import { assertSpyCall, assertSpyCalls, stub } from 'jsr:@std/testing/mock'

import { getStorage } from './storage_helpers.ts';
import { getStorage } from './storage_helpers.ts'

Deno.test('is running in test env', () => {
assert()
})

Deno.test('uses browser storage', async () => {
const getStorageStub = stub(browserAPI.storage.sync, 'get', () => {
return Promise.resolve({ storage_key: 'mock_storage_value' });
});
return Promise.resolve({ storage_key: 'mock_storage_value' })
})

assertStrictEquals(await getStorage(), 'mock_storage_value');
assertSpyCalls(getStorageStub, 1);
assertStrictEquals(await getStorage(), 'mock_storage_value')
assertSpyCalls(getStorageStub, 1)

// Expect `chrome.sync.storage.get` to be called with the storage_key
assertSpyCall(getStorageStub, 0, { args: ['storage_key'] });
getStorageStub.restore();
});
assertSpyCall(getStorageStub, 0, { args: ['storage_key'] })
getStorageStub.restore()
})
```

# Running this repo (for Bext development)

Tasks are defined in [deno.json](./deno.json), but basically:

- `deno task dev`: Run the example app in watch-mode
- `deno task dev:{project}`: Run the example app in watch-mode
- `deno task test`: Makes sure it all works. Use this before committing!
- runs fmt, lint, type-checks, unit tests for source and example apps
- builds example apps using local bext copy

## `/examples`

Note that the `deno tasks` in the example projects are meant to show the client usage, and therefore have tasks that don't work within the context of this repo's workspace.

If you want to run these projects from the Bext repo, please use the tasks in the root `deno.json` (instead of the `deno.json` in the `/examples/{project}`)

Also, for this same reason, do not put any imports in the root `deno.json`.
51 changes: 18 additions & 33 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,28 @@
{
"name": "@bpev/bext",
"version": "1.3.1",
"exports": {
".": "./source/mod.ts",
"./bin": "./source/main.ts",
"./mock": "./source/mock_browser/main.ts",
"./types/chrome": "./source/types/chrome.ts"
},
"workspace": [
"examples/preact",
"examples/barebones",
"source"
],
"fmt": {
"semiColons": false,
"singleQuote": true,
"proseWrap": "preserve",
"include": ["source", "examples"],
"exclude": ["dist"]
},
"imports": {
"@std/assert": "jsr:@std/assert@^1.0.0",
"@std/testing": "jsr:@std/testing@^0.225.3"
"semiColons": false,
"singleQuote": true
},
"lint": {
"test": {
"include": ["source"],
"exclude": ["dist", "examples"]
},
"publish": {
"exclude": ["dist", "examples"]
"exclude": ["examples"]
},
"tasks": {
"build": "deno task build:preact && deno task build:barebones",
"build:barebones": "(cd examples/barebones && deno run -A ../../source/main.ts internal-dev-only-build)",
"build:preact": "(cd examples/preact && deno run -A ../../source/main.ts internal-dev-only-build)",
"install": "deno install --name=bext -Agf ./source/main.ts",
"build": "deno task build:barebones && deno task build:preact",
"build:barebones": "(cd examples/barebones && bext build -c ../../deno.json)",
"build:preact": "(cd examples/preact && bext build -c ../../deno.json)",
"check": "deno check source/main.ts && deno check source/mod.ts",
"dev:barebones": "(cd examples/barebones && deno run -A ../../source/main.ts internal-dev-only-build -w)",
"dev:preact": "(cd examples/preact && deno run -A ../../source/main.ts internal-dev-only-build -w)",
"test": "deno task test:source && deno task build && deno task test:preact && deno publish --dry-run --allow-dirty",
"test:preact": "(cd examples/preact && deno task test)",
"test:source": "deno fmt && deno lint && deno task check && deno test source"
},
"test": {
"include": ["source"],
"exclude": ["dist", "examples"]
"dev:barebones": "(cd examples/barebones && bext dev -c ../../deno.json)",
"dev:preact": "(cd examples/preact && bext dev -c ../../deno.json)",
"test": "deno fmt && deno lint && deno task test:source && deno task test:preact && deno task build",
"test:source": "(cd source && deno test)",
"test:preact": "(cd examples/preact && deno task test)"
}
}
Loading