This repository has been archived by the owner on Jun 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from hanshs/automated-testing
setup Jest and React Testing Library closes #37
- Loading branch information
Showing
9 changed files
with
18,931 additions
and
2,600 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Automated Tests | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
run_automated_tests: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [14.x, 15.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v2 | ||
- name: Install dependencies | ||
run: npm install | ||
- name: Run unit tests | ||
run: npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// __mocks__/fileMock.js | ||
|
||
(module.exports = "test-file-stub") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// __mocks__/styleMock.js | ||
|
||
module.exports = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
test('testing jest configuration', () => { | ||
expect(true).toBe(true); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Theorem from "../components/Theorem"; | ||
import { render } from '@testing-library/react' | ||
|
||
const testTheorem = { | ||
claim: { | ||
statement: 'I am thorem statement', | ||
successor: { | ||
statement: 'I am detailed statement' | ||
} | ||
}, | ||
proof: [ | ||
{ claim: { statement: 'Step 1' } }, | ||
{ | ||
claim: { statement: 'Step 2' }, | ||
subProof: [ | ||
{ claim: { statement: 'Step 2 Subproof Step 1', successor: { statement: 'Step 2 Subproof Step 1 more detailed' } } }, | ||
{ claim: { statement: 'Step 2 Subproof Step 2' } } | ||
] | ||
}, | ||
{ claim: { statement: 'Step 3' } }, | ||
{ claim: { statement: 'Step 4' } } | ||
] | ||
} | ||
|
||
it('renders a theorem', () => { | ||
render(<Theorem theorem={testTheorem} />) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// jest .config.js | ||
|
||
module.exports = { | ||
collectCoverageFrom: [ | ||
'**/*.{js,jsx,ts,tsx}', | ||
'!**/*.d.ts', | ||
'!**/node_modules/**', | ||
], | ||
moduleNameMapper: { | ||
/* Handle CSS imports (with CSS modules) | ||
https://jestjs.io/docs/webpack#mocking-css-modules */ | ||
'^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy', | ||
|
||
// Handle CSS imports (without CSS modules) | ||
'^.+\\.(css|sass|scss)$': '<rootDir>/__mocks__/styleMock.js', | ||
|
||
/* Handle image imports | ||
https://jestjs.io/docs/webpack#handling-static-assets */ | ||
'^.+\\.(jpg|jpeg|png|gif|webp|avif|svg)$': | ||
'<rootDir>/__mocks__/fileMock.js', | ||
}, | ||
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/.next/'], | ||
testEnvironment: 'jsdom', | ||
transform: { | ||
/* Use babel-jest to transpile tests with the next/babel preset | ||
https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object */ | ||
'^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', { presets: ['next/babel'] }], | ||
}, | ||
transformIgnorePatterns: [ | ||
'/node_modules/', | ||
'^.+\\.module\\.(css|sass|scss)$', | ||
], | ||
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// jest.setup.js | ||
|
||
import '@testing-library/jest-dom/extend-expect' |
Oops, something went wrong.
3f19751
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: