diff --git a/package-lock.json b/package-lock.json index 2f0a9cff..9970691b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19595,7 +19595,7 @@ "@babel/preset-typescript": "^7.24.7", "@testing-library/jest-dom": "^6.4.8", "@testing-library/react": "^16.0.0", - "@types/react": "16.8", + "@types/react": ">16.8", "babel": "^6.23.0", "babel-jest": "^29.7.0", "fake-indexeddb": "^6.0.0", @@ -19603,15 +19603,6 @@ "vitest": "^2.0.5" } }, - "packages/use-auth-client/node_modules/@types/react": { - "version": "16.8.25", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/prop-types": "*", - "csstype": "^2.2.0" - } - }, "packages/use-auth-client/node_modules/@vitest/expect": { "version": "2.0.5", "dev": true, @@ -19707,11 +19698,6 @@ "node": ">= 16" } }, - "packages/use-auth-client/node_modules/csstype": { - "version": "2.6.21", - "dev": true, - "license": "MIT" - }, "packages/use-auth-client/node_modules/deep-eql": { "version": "5.0.2", "dev": true, diff --git a/packages/use-auth-client/.gitignore b/packages/use-auth-client/.gitignore new file mode 100644 index 00000000..40ba0014 --- /dev/null +++ b/packages/use-auth-client/.gitignore @@ -0,0 +1,17 @@ +build_info.json +node_modules/ +dist/ +**/*.js +**/*.js.map +**/*.d.ts + +# generated docs +/docs/reference + +# Cannot ignore .d.ts files in types/ +!types/**/*.d.ts + +# Cannot ignore setup files for webpack and jest, which are still JavaScript. +!webpack.config.js +!jest.config.js +!test-setup.js diff --git a/packages/use-auth-client/FixJSDOMEnvironment.ts b/packages/use-auth-client/FixJSDOMEnvironment.ts new file mode 100644 index 00000000..f538d57c --- /dev/null +++ b/packages/use-auth-client/FixJSDOMEnvironment.ts @@ -0,0 +1,11 @@ +import JSDOMEnvironment from 'jest-environment-jsdom'; + +// https://github.com/facebook/jest/blob/v29.4.3/website/versioned_docs/version-29.4/Configuration.md#testenvironment-string +export default class FixJSDOMEnvironment extends JSDOMEnvironment { + constructor(...args: ConstructorParameters) { + super(...args); + + // FIXME https://github.com/jsdom/jsdom/issues/3363 + this.global.structuredClone = structuredClone; + } +} diff --git a/packages/use-auth-client/jest.config.ts b/packages/use-auth-client/jest.config.ts index ad88e167..982b636e 100644 --- a/packages/use-auth-client/jest.config.ts +++ b/packages/use-auth-client/jest.config.ts @@ -1,6 +1,6 @@ module.exports = { preset: 'ts-jest', - testEnvironment: 'jsdom', + testEnvironment: './FixJSDOMEnvironment.ts', roots: ['/test'], setupFilesAfterEnv: ['/setupTests.ts'], }; diff --git a/packages/use-auth-client/package.json b/packages/use-auth-client/package.json index a6bbf9f2..9c17712b 100644 --- a/packages/use-auth-client/package.json +++ b/packages/use-auth-client/package.json @@ -27,7 +27,7 @@ "@babel/preset-typescript": "^7.24.7", "@testing-library/jest-dom": "^6.4.8", "@testing-library/react": "^16.0.0", - "@types/react": "16.8", + "@types/react": ">16.8", "babel": "^6.23.0", "babel-jest": "^29.7.0", "fake-indexeddb": "^6.0.0", diff --git a/packages/use-auth-client/setupTests.ts b/packages/use-auth-client/setupTests.ts index 9c78d31b..efccb6d9 100644 --- a/packages/use-auth-client/setupTests.ts +++ b/packages/use-auth-client/setupTests.ts @@ -2,4 +2,17 @@ import 'fake-indexeddb/auto'; import { TextEncoder } from 'util'; import '@testing-library/jest-dom'; +import { Crypto } from '@peculiar/webcrypto'; +const crypto = new Crypto(); + +Object.defineProperty(globalThis, 'crypto', { + value: crypto, +}); + +Object.defineProperty(global, 'console', { + writable: true, + value: { ...global.console, log: jest.fn(), warn: jest.fn(), error: jest.fn() }, +}); + + global.TextEncoder = TextEncoder; diff --git a/packages/use-auth-client/test/use-auth-client.test.tsx b/packages/use-auth-client/test/use-auth-client.test.tsx index d0272a48..e938cbd3 100644 --- a/packages/use-auth-client/test/use-auth-client.test.tsx +++ b/packages/use-auth-client/test/use-auth-client.test.tsx @@ -6,7 +6,7 @@ import { describe, it } from '@jest/globals'; describe('useAuthClient', () => { it('should return an authClient object with the expected properties', async () => { interface Props { - children: React.ReactNode; + children?: React.ReactNode; } const Component: React.FC = () => { const { isAuthenticated, login, logout } = useAuthClient(); @@ -21,7 +21,10 @@ describe('useAuthClient', () => { // disable typescript render(); - const isAuthenticated = screen.getByTestId('isAuthenticated'); - expect(isAuthenticated).toHaveTextContent('false'); + ( + expect(screen.getByTestId('isAuthenticated')) as unknown as { + toHaveTextContent: (str: string) => boolean; + } + ).toHaveTextContent('false'); }); });