Skip to content

Commit

Permalink
Merge pull request #11 from code-like-a-carpenter/tests
Browse files Browse the repository at this point in the history
tests
  • Loading branch information
ianwremmel authored Feb 12, 2023
2 parents f9693aa + 26923a8 commit 332a35d
Show file tree
Hide file tree
Showing 12 changed files with 13,172 additions and 7,469 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ jobs:
- build
- diff
- lint
- test
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
Expand Down Expand Up @@ -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'
77 changes: 77 additions & 0 deletions jest.config.ts
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,
};
Loading

0 comments on commit 332a35d

Please sign in to comment.