Skip to content

Commit

Permalink
feat: setup jest and react-testing-library (#196)
Browse files Browse the repository at this point in the history
* feat: setup jest and react-testing-library

* chore: import
  • Loading branch information
paanSinghCoder authored Dec 10, 2024
1 parent 87e0506 commit 846b60f
Show file tree
Hide file tree
Showing 6 changed files with 2,454 additions and 76 deletions.
25 changes: 25 additions & 0 deletions packages/raystack/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export default {
preset: 'ts-jest',
testEnvironment: 'jsdom',
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
moduleNameMapper: {
// Handle CSS imports
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
// Handle path aliases
'^~/(.*)$': '<rootDir>/v1/$1'
},
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
collectCoverageFrom: [
'v1/**/*.{ts,tsx}',
'!v1/**/*.d.ts',
'!v1/**/index.{ts,tsx}'
],
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80
}
}
};
1 change: 1 addition & 0 deletions packages/raystack/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@testing-library/jest-dom';
13 changes: 12 additions & 1 deletion packages/raystack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
"release": "release-it",
"release:ci": "release-it --ci --no-increment --npm.ignoreVersion",
"bump-version": "node scripts/bump-version.js",
"clean": "rm -rf .turbo && rm -rf dist"
"clean": "rm -rf .turbo && rm -rf dist",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage"
},
"typesVersions": {
"*": {
Expand All @@ -52,9 +55,16 @@
"@rollup/plugin-image": "^3.0.2",
"@rollup/plugin-node-resolve": "^15.1.0",
"@rollup/plugin-typescript": "^11.1.1",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.1.0",
"@testing-library/user-event": "^14.5.2",
"@types/jest": "^29.5.14",
"@types/react": "^18.2.12",
"@types/react-select": "^5.0.1",
"eslint-config-custom": "workspace:*",
"identity-obj-proxy": "^3.0.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"np": "^8.0.4",
"npm": "^9.7.1",
"parcel": "^2.9.2",
Expand All @@ -66,6 +76,7 @@
"rollup": "^3.25.1",
"rollup-plugin-postcss": "^4.0.2",
"semver": "^7.6.0",
"ts-jest": "^29.2.5",
"tsconfig": "workspace:*",
"typescript": "~5.4.3"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/raystack/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"paths": {
"~/*": ["./*"],
"~/v1/*": ["./v1/*"]
}
},
"types": ["jest", "@testing-library/jest-dom"]
},
"include": [".", "v1"],
"exclude": ["dist", "build", "node_modules"]
Expand Down
12 changes: 12 additions & 0 deletions packages/raystack/v1/test-utils.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ReactElement } from 'react';
import { render as rtlRender, RenderOptions, RenderResult } from '@testing-library/react';

function render(ui: ReactElement, options: RenderOptions = {}): RenderResult {
return rtlRender(ui, {
wrapper: ({ children }) => children,
...options,
});
}

export * from '@testing-library/react';
export { render };
Loading

0 comments on commit 846b60f

Please sign in to comment.