Skip to content

Commit d0d0a9b

Browse files
authored
Add test coverage to project (#39)
* initial setup of jest in the project * add initial tests for get-authorization-url * add cookie tests * add tests for workos * add authLoader tests * istanbul ignore env-variables file * move test utility methods to test-helpers file * rename tsconfig-base.json to tsconfig.json * remove unused import * add session -> terminateSession tests * add encryptSession tests * session -> authkitLoader tests * add auth tests * test cleanup * add ci workflow * lint fixes * clean up copied code from authkit-nextjs * change coverage to 80%, remove unnecessary clearAllMocks calls
1 parent a68475b commit d0d0a9b

17 files changed

+5561
-174
lines changed

.github/workflows/ci.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
pull_request: {}
8+
9+
defaults:
10+
run:
11+
shell: bash
12+
13+
jobs:
14+
test:
15+
name: Test Node ${{ matrix.node }}
16+
runs-on: ubuntu-latest
17+
strategy:
18+
matrix:
19+
node: [18, 20, 22]
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: actions/setup-node@v4
23+
with:
24+
node-version: ${{ matrix.node }}
25+
26+
- name: Install Dependencies
27+
run: |
28+
npm install
29+
30+
- name: Prettier
31+
run: |
32+
npm run prettier
33+
34+
- name: Lint
35+
run: |
36+
npm run lint
37+
38+
- name: Build
39+
run: |
40+
npm run build
41+
42+
- name: Test
43+
run: |
44+
npm run test -- --coverage

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.DS_Store
22
node_modules
33
dist
4+
coverage/

jest.config.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import type { Config } from 'jest';
2+
3+
const config: Config = {
4+
// Automatically clear mock calls, instances, contexts and results before every test
5+
clearMocks: true,
6+
7+
// Automatically reset mock state between every test
8+
resetMocks: true,
9+
10+
// Indicates whether the coverage information should be collected while executing the test
11+
collectCoverage: true,
12+
13+
// The directory where Jest should output its coverage files
14+
coverageDirectory: 'coverage',
15+
16+
// Indicates which provider should be used to instrument code for coverage
17+
coverageProvider: 'babel',
18+
19+
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
20+
moduleNameMapper: {
21+
'^(\\.{1,2}/.*)\\.js$': '$1', // Handle ESM imports
22+
},
23+
24+
// A preset that is used as a base for Jest's configuration
25+
preset: 'ts-jest',
26+
27+
// Run tests from one or more projects
28+
projects: [
29+
{
30+
displayName: 'jsdom',
31+
testEnvironment: 'jsdom',
32+
testMatch: ['**/*.spec.tsx', '**/__tests__/**/*.spec.tsx'],
33+
transform: {
34+
'^.+\\.tsx?$': 'ts-jest', // Use ts-jest for TypeScript files
35+
},
36+
moduleNameMapper: {
37+
'^(\\.{1,2}/.*)\\.js$': '$1',
38+
},
39+
},
40+
{
41+
displayName: 'node',
42+
testEnvironment: 'node',
43+
testMatch: ['**/*.spec.ts', '**/__tests__/**/*.spec.ts'],
44+
transform: {
45+
'^.+\\.tsx?$': 'ts-jest',
46+
},
47+
moduleNameMapper: {
48+
'^(\\.{1,2}/.*)\\.js$': '$1',
49+
},
50+
setupFiles: ['<rootDir>/jest.setup.ts'],
51+
},
52+
],
53+
54+
// Indicates whether each individual test should be reported during the run
55+
verbose: true,
56+
57+
// Optionally, add these for better TypeScript support
58+
extensionsToTreatAsEsm: ['.ts'],
59+
60+
coverageThreshold: {
61+
global: {
62+
branches: 80,
63+
functions: 80,
64+
lines: 80,
65+
statements: 80,
66+
},
67+
},
68+
};
69+
70+
export default config;

jest.setup.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
process.env.WORKOS_API_KEY = 'sk_test_1234567890';
2+
process.env.WORKOS_CLIENT_ID = 'client_1234567890';
3+
process.env.WORKOS_COOKIE_PASSWORD = 'kR620keEzOIzPThfnMEAba8XYgKdQ5vg';
4+
process.env.WORKOS_REDIRECT_URI = 'http://localhost:5173/callback';
5+
process.env.WORKOS_COOKIE_DOMAIN = 'example.com';
6+
process.env.WORKOS_API_HOSTNAME = 'api.workos.com';
7+
8+
export {};

0 commit comments

Comments
 (0)