Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ID-2116 Unit test Passport in a browser-like environment #1961

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion packages/passport/sdk/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const config: Config = {
'@imtbl/x-client': '<rootDir>../../x-client/src',
'@imtbl/toolkit': '<rootDir>../../internal/toolkit/src',
},
testEnvironment: 'jsdom',
resolver: "./resolver.ts",
testEnvironment: "./jest.custom.env.ts",
transform: {
'^.+\\.(t|j)sx?$': '@swc/jest',
},
Expand Down
10 changes: 10 additions & 0 deletions packages/passport/sdk/jest.custom.env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import JSDOMEnvironment from 'jest-environment-jsdom';

export default class CustomEnvironment extends JSDOMEnvironment {
async setup() {
await super.setup();

// In browser environments, the global Buffer is not available.
(this.global.Buffer as any) = undefined;
}
}
1 change: 1 addition & 0 deletions packages/passport/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "^5.57.1",
"@typescript-eslint/parser": "^5.57.1",
"browser-resolve": "^2.0.0",
"cross-fetch": "^3.1.6",
"eslint": "^8.40.0",
"jest": "^29.4.3",
Expand Down
8 changes: 8 additions & 0 deletions packages/passport/sdk/resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* browser-resolve ensures that browser versions of packages are resolved where appropriate.
* It respects the "browser" field in package.json.
*/

const browserResolve = require('browser-resolve');

module.exports = browserResolve.sync;
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3825,6 +3825,7 @@ __metadata:
"@typescript-eslint/eslint-plugin": ^5.57.1
"@typescript-eslint/parser": ^5.57.1
axios: ^1.6.5
browser-resolve: ^2.0.0
cross-fetch: ^3.1.6
eslint: ^8.40.0
ethers: ^5.7.2
Expand Down
Loading