Skip to content

Commit

Permalink
chore(tests): add coverage workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
unicornware committed Nov 5, 2021
1 parent fe2f5ac commit bee90a0
Show file tree
Hide file tree
Showing 20 changed files with 553 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# - https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/dotenv

DEBUG='*,-babel*,-compression,-eslint:*,-eslintrc:*,-lint-staged:*,-mocha:*,-typescript-eslint*,-yarn'
DEBUG='*,-babel*,-compression,-eslint:*,-eslintrc:*,-istanbuljs,-lint-staged:*,-mocha:*,-typescript-eslint*,-yarn'
DEBUG_COLORS=true
GITHUB_WORKSPACE=$(git rev-parse --show-toplevel)
NODE_ENV=development
Expand Down
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# ESLint Ignore
# https://eslint.org/docs/user-guide/configuring#ignoring-files-and-directories

**/.nyc/*
**/coverage/*
**/node_modules/*

.yarn/*
Expand Down
1 change: 1 addition & 0 deletions .eslintrc.base.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ module.exports = {
'mts',
'namespace',
'ncc',
'nycrc',
'perf',
'pnv',
'ponyfill',
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ jobs:
- id: check-style
name: Check code style
run: yarn check:style
# - id: check-tests
# name: Check test suites
# run: yarn test
- id: env
name: Set build environment variables
name: Set environment variables
run: node ./tools/cli/loadenv.cjs -gc=test
- id: check-build
name: Check builds
run: yarn prepack --tarball --env=test
name: Check build
run: yarn prepack -te=test
- id: test
name: Run test suites
run: yarn test:ci
- id: env-post
name: Post Set build environment variables
name: Post Set environment variables
run: echo "NODE_OPTIONS=''" >> $GITHUB_ENV
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ jspm_packages/
.env*.local

### Testing ###
**/.nyc/
**/coverage/
**/__tests__/results.json

### TypeScript ###
Expand Down
3 changes: 3 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./.nycrc.base"
}
9 changes: 9 additions & 0 deletions .nycrc.base
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"all": false,
"cache": false,
"exclude": ["**/__tests__/*", "**/index.ts", "*.fixture.ts", "*.spec.ts"],
"extension": [".ts"],
"reporter": ["lcov", "text"],
"skip-full": false,
"temp-dir": "./.nyc"
}
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Prettier Ignore
# See: https://prettier.io/docs/en/ignore.html

**/.nyc/*
**/coverage/*
**/node_modules/*
.husky/_/*
.yarn/*
Expand Down
10 changes: 8 additions & 2 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@ module.exports = {
trailingComma: 'none',
overrides: [
{
files: ['*.cts', '*.mts'],
files: ['**/*.cts', '**/*.mts'],
options: {
parser: 'typescript'
}
},
{
files: ['**/.nycrc*'],
options: {
parser: 'json'
}
},
{
files: [
'*.sh',
'**/*.sh',
'.husky/commit-msg',
'.husky/pre-commit',
'.husky/pre-push'
Expand Down
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"*.d.cts": "typescript",
"*.d.mts": "typescript",
".env*": "shellscript",
".nycrc*": "json",
"commit-msg": "shellscript",
"pre-commit": "shellscript",
"pre-push": "shellscript"
Expand Down Expand Up @@ -46,6 +47,11 @@
"format": "svg",
"icon": "mocha"
},
{
"extensions": [".nycrc.base", ".nycrc.react"],
"format": "svg",
"icon": "nyc"
},
{
"extensions": [
"build.json",
Expand Down
2 changes: 1 addition & 1 deletion __tests__/config/reporters.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"mochajsJsonFileReporterReporterOptions": {
"output": "__tests__/results.json"
},
"reporterEnabled": "spec, @mochajs/json-file-reporter"
"reporterEnabled": "spec,@mochajs/json-file-reporter"
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"bootstrap": ". ./.env && yarn prepack",
"postinstall": "is-ci || chmod +x .husky/* && husky install",
"prepack": "yarn workspaces foreach -iv --topological-dev run prepack",
"check:ci": "yarn check:types && yarn fix:format && yarn fix:style && yarn test && yarn build --tarball && rimraf packages/*/*.tgz",
"check:ci": "yarn check:types && yarn fix:format && yarn fix:style && yarn test && yarn build --tarball && rimraf ./*/*/*.tgz",
"check:dedupe": "yarn dedupe --check",
"check:format": "prettier --check .",
"check:install": "yarn dlx @yarnpkg/doctor .",
Expand All @@ -33,6 +33,7 @@
"fix:format": "prettier --write .",
"fix:style": "yarn check:style --fix --cache",
"test": "bash tools/scripts/mocha.sh",
"test:ci": "yarn test --no-growl --no-parallel --sort",
"test:aggregate-error-ponyfill": "yarn workspace @flex-development/aggregate-error-ponyfill test",
"test:coverage": "yarn workspace @flex-development/$0 test:coverage",
"test:exceptions": "yarn workspace @flex-development/exceptions test",
Expand All @@ -50,6 +51,7 @@
"@flex-development/log": "4.0.1-dev.0",
"@flex-development/trext": "2.0.4",
"@flex-development/tutils": "4.2.3",
"@istanbuljs/esm-loader-hook": "0.1.2",
"@mochajs/json-file-reporter": "1.3.0",
"@packages": "link:packages",
"@types/chai": "4.2.22",
Expand All @@ -64,6 +66,7 @@
"@typescript-eslint/eslint-plugin": "5.3.0",
"@typescript-eslint/parser": "5.3.0",
"@vercel/ncc": "0.31.1",
"babel-plugin-istanbul": "6.1.1",
"chai": "4.3.4",
"chalk": "4.1.2",
"concurrently": "6.3.0",
Expand Down Expand Up @@ -91,6 +94,7 @@
"lodash.merge": "4.6.2",
"mocha": "9.1.3",
"mocha-multi-reporters": "1.5.1",
"nyc": "15.1.0",
"prettier": "2.4.1",
"prettier-plugin-sh": "0.7.1",
"pretty-format": "27.3.1",
Expand Down
5 changes: 5 additions & 0 deletions packages/aggregate-error-ponyfill/.nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../../.nycrc.base",
"include": ["src"],
"report-dir": "./coverage"
}
1 change: 1 addition & 0 deletions packages/aggregate-error-ponyfill/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"chai": "4.3.4",
"mocha": "9.1.3",
"mocha-multi-reporters": "1.5.1",
"nyc": "15.1.0",
"serve": "12.0.1",
"ts-node": "10.4.0",
"typescript": "4.5.0-beta"
Expand Down
5 changes: 5 additions & 0 deletions packages/exceptions/.nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../../.nycrc.base",
"include": ["src"],
"report-dir": "./coverage"
}
1 change: 1 addition & 0 deletions packages/exceptions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
"firebase-admin": "10.0.0",
"mocha": "9.1.3",
"mocha-multi-reporters": "1.5.1",
"nyc": "15.1.0",
"serve": "12.0.1",
"ts-node": "10.4.0",
"typescript": "4.5.0-beta"
Expand Down
12 changes: 11 additions & 1 deletion tools/loaders/esm.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as istanbul from '@istanbuljs/esm-loader-hook'
import path from 'node:path'
import { createMatchPath, loadConfig } from 'tsconfig-paths'
import pkg from '../../package.json'
Expand All @@ -10,6 +11,8 @@ import pkg from '../../package.json'
* @see https://nodejs.org/docs/latest-v12.x/api/all.html#esm_hooks
*/

const TEST = process.env.NODE_ENV === 'test'

/**
* Determines if `url` should be interpreted as a CommonJS or ES module.
*
Expand Down Expand Up @@ -83,4 +86,11 @@ export const resolve = async (specifier, ctx, fn) => {
* @param {EsmLoader.Hooks.TransformSource} fn - Default transform fn
* @return {Promise<EsmLoader.HookResult.TransformSource>} Source code
*/
export const transformSource = hooks.transformSource
export const transformSource = async (source, ctx, fn) => {
source = (await hooks.transformSource(source, ctx, fn)).source

/** @see https://github.com/istanbuljs/esm-loader-hook */
if (TEST) source = (await istanbul.transformSource(source, ctx, fn)).source

return { source }
}
11 changes: 8 additions & 3 deletions tools/scripts/mocha.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@
#
# References:
#
# - https://github.com/istanbuljs/nyc
# - https://github.com/piotrwitek/ts-mocha
# - https://mochajs.org/#command-line-usage

# 1. Load default environment variables
. $GITHUB_WORKSPACE/.env
# . $GITHUB_WORKSPACE/.env

# 2. Set test environment variables
export NODE_ENV=test
export TS_NODE_PROJECT="$GITHUB_WORKSPACE/tsconfig.test.json"

# 3. Run test suites
ts-mocha $@
# 3. Remove coverage output
rimraf $GITHUB_WORKSPACE/.nyc/ $GITHUB_WORKSPACE/coverage/
rimraf $GITHUB_WORKSPACE/*/*/.nyc/ $GITHUB_WORKSPACE/*/*/coverage/

# 4. Run test suites
nyc ts-mocha $@
4 changes: 3 additions & 1 deletion tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"compilerOptions": {},
"compilerOptions": {
"inlineSourceMap": true
},
"extends": "./tsconfig.json"
}
Loading

0 comments on commit bee90a0

Please sign in to comment.