-
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 #11 from code-like-a-carpenter/tests
tests
- Loading branch information
Showing
12 changed files
with
13,172 additions
and
7,469 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 |
---|---|---|
|
@@ -82,6 +82,7 @@ jobs: | |
- build | ||
- diff | ||
- lint | ||
- test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/[email protected] | ||
|
@@ -110,3 +111,28 @@ jobs: | |
GIT_COMMITTER_NAME: ${{ github.actor }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
test: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/[email protected] | ||
with: | ||
fetch-depth: 0 | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
cache: 'npm' | ||
- uses: nrwl/nx-set-shas@v3 | ||
- run: npm ci | ||
# by making this job depend on the build job, the following line should be | ||
# 100% cache hits; The nx cache seems to be much easier to use than the | ||
# GitHub artifact action. | ||
- run: npx nx run-many --target=build --parallel=4 | ||
- run: npm test | ||
- uses: check-run-reporter/[email protected] | ||
if: ${{ always() }} | ||
with: | ||
token: ${{ secrets.CHECK_RUN_REPORTER_TOKEN }} | ||
label: Unit Tests | ||
report: 'reports/junit/**/*.xml' |
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,77 @@ | ||
import assert from 'node:assert'; | ||
|
||
import type {Config} from '@jest/types'; | ||
import glob from 'glob'; | ||
// For a detailed explanation regarding each configuration property, visit: | ||
// https://jestjs.io/docs/en/configuration.html | ||
|
||
import pkg from './package.json'; | ||
|
||
// This is a hack to get around the fact that no one seems to be maintaining the | ||
// Jest types https://github.com/facebook/jest/issues/11640 | ||
declare global { | ||
// eslint-disable-next-line @typescript-eslint/no-namespace | ||
namespace NodeJS { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
interface Global {} | ||
} | ||
} | ||
|
||
const commonProjectConfig: Config.ProjectConfig = { | ||
clearMocks: true, | ||
testEnvironment: 'node', | ||
testPathIgnorePatterns: ['/dist/', '/node_modules/'], | ||
transform: { | ||
// jest uses babel-jest by default, but only if it can find a babel config | ||
// file. I'd like to avoid relying on babel for as long as possible, so I'm | ||
// using esbuild-jest here instead, which requires zero config. | ||
// @ts-expect-error | ||
'^.+\\.tsx?$': 'esbuild-jest', | ||
}, | ||
}; | ||
|
||
const CI = !!process.env.CI; | ||
const {workspaces} = pkg; | ||
|
||
assert( | ||
workspaces, | ||
'This Jest config is intended only for Monorepos and cannot work without a `workspaces` field in package.json' | ||
); | ||
|
||
/** @type {import('@jest/types').Config.GlobalConfig} */ | ||
module.exports = { | ||
bail: 0, | ||
collectCoverage: CI, | ||
coverageDirectory: 'reports/coverage', | ||
|
||
projects: [ | ||
{ | ||
...commonProjectConfig, | ||
displayName: 'Unit Tests', | ||
testMatch: workspaces | ||
.flatMap((ws) => glob.sync(ws)) | ||
.flatMap((packagePath) => [ | ||
`<rootDir>/${packagePath}/**/?(*.)+(test).[tj]s?(x)`, | ||
]), | ||
}, | ||
], | ||
reporters: [ | ||
!CI && 'default', | ||
CI && ['github-actions', {silent: false}], | ||
CI && [ | ||
'jest-junit', | ||
{ | ||
addFileAttribute: 'true', // Yep, it really needs to be a string | ||
ancestorSeparator: ' › ', | ||
classNameTemplate: '{classname}', | ||
includeConsoleOutput: true, | ||
outputDirectory: 'reports/junit', | ||
outputName: `jest.xml`, | ||
reportTestSuiteErrors: true, | ||
titleTemplate: '{title}', | ||
}, | ||
], | ||
CI && 'summary', | ||
].filter(Boolean), | ||
testLocationInResults: true, | ||
}; |
Oops, something went wrong.