forked from storacha/w3up
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: replace ava with vitest (storacha#239)
Based on the discussion in storacha#150, I decided to try replacing ava with vitest and found that it was super easy 😄 Much nicer out-of-the-box experience than getting ava to play nice with typescript. Any objections to tossing ava overboard? edit: once the build failure is sorted out, that is 😐
- Loading branch information
1 parent
0b5d6e5
commit afe756f
Showing
10 changed files
with
347 additions
and
604 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { test, expect } from 'vitest' | ||
import 'fake-indexeddb/auto' | ||
|
||
import { createAgent } from '../src/index' | ||
|
||
test('createAgent', async () => { | ||
const agent = await createAgent() | ||
expect(agent).toBeTruthy() | ||
expect(agent.did().startsWith('did:key')).toBe(true) | ||
expect(agent.spaces.size).to.eql(0) | ||
}) | ||
|
||
test('createSpace', async () => { | ||
const agent = await createAgent() | ||
const space = await agent.createSpace('test') | ||
expect(space).toBeTruthy() | ||
expect(space.did.startsWith('did:key:')).toBe(true) | ||
}) | ||
|
||
test('registerSpace fails if no current space is set', async () => { | ||
const agent = await createAgent() | ||
await expect(agent.registerSpace('[email protected]')).rejects.toThrowError() | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# vitest-environment-w3ui | ||
|
||
A utility package that exports a custom [Vitest test environment](https://vitest.dev/guide/environment.html). | ||
|
||
This is a very thin wrapper around the default JSDOM vitest environment that also defines the `crypto` global, using Node's builtin `crypto.webcrypto` implementation. | ||
|
||
This is needed because the vitest JSDOM environment defines a `crypto` global with only the `getRandomValues` function defined, but one of our dependencies (`@noble/ed25519`) assumes that if the `crypto` global exists, it can safely access the WebCrypto APIs at `crypto.subtle`. | ||
|
||
Note that this package is not published to NPM, as it's only used when testing other packages in this repo. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "vitest-environment-w3ui", | ||
"version": "1.0.0", | ||
"description": "A vitest environment that exposes Node's webcrypto API to the builtin JSDOM test environment", | ||
"main": "src/index.ts", | ||
"files": [ | ||
"src" | ||
], | ||
"keywords": [], | ||
"author": "Yusef Napora", | ||
"license": "Apache 2.0 OR MIT", | ||
"dependencies": { | ||
"vitest": "^0.27.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import crypto from 'crypto' | ||
import { builtinEnvironments } from 'vitest/environments' | ||
import type { Environment } from 'vitest' | ||
|
||
const env: Environment = { | ||
name: 'w3ui', | ||
async setup (global, options) { | ||
// use the standard jsdom environment as a base | ||
const jsdom = await builtinEnvironments.jsdom.setup(global, options) | ||
|
||
// `crypto` is defined as a getter on the global scope in Node 19+, | ||
// so attempting to set it with `Object.assign()` would fail. Instead, | ||
// override the getter with a new value. | ||
Object.defineProperty(global, 'crypto', { get: () => crypto.webcrypto }) | ||
|
||
return { | ||
async teardown (global) { | ||
await jsdom.teardown(global) | ||
} | ||
} | ||
} | ||
} | ||
|
||
export default env |
Oops, something went wrong.