Skip to content

Commit

Permalink
Add webcrypto node.js + browser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
acusti committed Jan 22, 2024
1 parent 376f1c4 commit e9c6481
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 22 deletions.
45 changes: 23 additions & 22 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/webcrypto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
"ts",
"flow"
],
"scripts": {
"test": "vitest"
},
"repository": {
"type": "git",
"url": "https://github.com/acusti/uikit.git",
Expand All @@ -45,6 +48,7 @@
},
"devDependencies": {
"@types/node": "^20.10.5",
"happy-dom": "^12.10.3",
"typescript": "^5.3.3",
"vitest": "^1.1.0"
}
Expand Down
12 changes: 12 additions & 0 deletions packages/webcrypto/src/browser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @vitest-environment happy-dom
import { describe, expect, it } from 'vitest';

import webcrypto from './browser.js';

describe('@acusti/webcrypto', () => {
describe('browser.ts', () => {
it('exports node:crypto’s webcrypto object', () => {
expect(webcrypto).toBe(window.crypto);
});
});
});
19 changes: 19 additions & 0 deletions packages/webcrypto/src/node.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import crypto from 'node:crypto';

import { describe, expect, it } from 'vitest';

import webcrypto from './node.js';

describe('@acusti/webcrypto', () => {
describe('node.ts', () => {
it('exports node:crypto’s webcrypto object', () => {
expect(webcrypto).toBe(crypto.webcrypto);
});

it('works in a node environment (as opposed to browser.js, which throws an error)', async () => {
await expect(() => import('./browser.js')).rejects.toThrowError(
'not defined',
);
});
});
});
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ __metadata:
resolution: "@acusti/webcrypto@workspace:packages/webcrypto"
dependencies:
"@types/node": "npm:^20.10.5"
happy-dom: "npm:^12.10.3"
typescript: "npm:^5.3.3"
vitest: "npm:^1.1.0"
languageName: unknown
Expand Down

0 comments on commit e9c6481

Please sign in to comment.