Skip to content

Commit df3fffe

Browse files
committed
chore(tests): mocha-chai migration
- https://mochajs.org - https://www.chaijs.com
1 parent cb19287 commit df3fffe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1592
-3032
lines changed

.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# - https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/dotenv
66

7-
DEBUG='*,-babel*,-yarn,-eslint:*,-eslintrc:*,-lint-staged:*,-typescript-eslint*'
7+
DEBUG='*,-babel*,-compression,-eslint:*,-eslintrc:*,-lint-staged:*,-mocha:*,-typescript-eslint*,-yarn'
88
DEBUG_COLORS=true
99
GITHUB_WORKSPACE=$PWD
1010
NODE_ENV=development
@@ -13,7 +13,7 @@ NODE_ENV=development
1313
NODE_MODULES=node_modules
1414
NPM_TOKEN=$NPM_TOKEN_FLDV
1515
PAT_GPR=$PAT_GPR_FLDV
16-
PROJECT_CWD=$GITHUB_WORKSPACE
16+
[[ $GITHUB_ACTIONS ]] && PROJECT_CWD=$GITHUB_WORKSPACE
1717
TS_NODE_PROJECT="$PROJECT_CWD/tsconfig.json"
1818

1919
# NODE_OPTIONS - Use ESM

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# ESLint Ignore
22
# https://eslint.org/docs/user-guide/configuring#ignoring-files-and-directories
33

4-
**/coverage/*
54
**/node_modules/*
65

76
.yarn/*

.eslintrc.base.cjs

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ module.exports = {
7373
'EsmLoader',
7474
'Exception',
7575
'ExceptionJSON',
76+
'Mocha',
7677
'NodeJS',
7778
'PackageResolverOptions',
7879
'PackageResolverPath',
@@ -122,7 +123,8 @@ module.exports = {
122123
skipWordIfMatch: [],
123124
skipWords: [
124125
'argv',
125-
'basedir',
126+
'bdd',
127+
'chai',
126128
'cjs',
127129
'commitlint',
128130
'commonjs',
@@ -136,15 +138,17 @@ module.exports = {
136138
'formatter',
137139
'loadenv',
138140
'mjs',
141+
'mocharc',
139142
'msg',
140143
'mts',
144+
'namespace',
141145
'ncc',
142146
'perf',
143-
'pkgfile',
144147
'pnv',
145148
'postinstall',
146149
'prepack',
147150
'prog',
151+
'redeclare',
148152
'stringified',
149153
'tgz',
150154
'tsc',
@@ -266,16 +270,52 @@ module.exports = {
266270
{
267271
files: ['**/*.spec.ts'],
268272
env: {
269-
jest: true
273+
mocha: true
270274
},
271-
extends: ['plugin:jest/recommended'],
272275
globals: {
273-
'jest/globals': true
276+
after: true,
277+
afterEach: true,
278+
before: true,
279+
beforeEach: true,
280+
describe: true,
281+
expect: true,
282+
it: true,
283+
pf: true
274284
},
285+
plugins: ['chai-expect', 'mocha'],
275286
rules: {
276-
'jest/no-disabled-tests': 0,
277-
'jest/valid-title': 0,
278-
'tree-shaking/no-side-effects-in-initialization': 0
287+
'@typescript-eslint/ban-ts-comment': 0,
288+
'chai-expect/missing-assertion': 2,
289+
'chai-expect/no-inner-compare': 2,
290+
'chai-expect/no-inner-literal': 2,
291+
'chai-expect/terminating-properties': [2, { properties: [] }],
292+
'mocha/handle-done-callback': [2, { ignoreSkipped: false }],
293+
'mocha/max-top-level-suites': [2, { limit: 1 }],
294+
'mocha/no-async-describe': 2,
295+
'mocha/no-exclusive-tests': 2,
296+
'mocha/no-exports': 2,
297+
'mocha/no-global-tests': 2,
298+
'mocha/no-hooks': 0,
299+
'mocha/no-hooks-for-single-case': 0,
300+
'mocha/no-identical-title': 2,
301+
'mocha/no-mocha-arrows': 0,
302+
'mocha/no-nested-tests': 2,
303+
'mocha/no-pending-tests': 2,
304+
'mocha/no-return-and-callback': 2,
305+
'mocha/no-return-from-async': 2,
306+
'mocha/no-setup-in-describe': 0,
307+
'mocha/no-sibling-hooks': 2,
308+
'mocha/no-skipped-tests': 0,
309+
'mocha/no-synchronous-tests': [0, { allowed: ['async'] }],
310+
'mocha/no-top-level-hooks': 2,
311+
'mocha/prefer-arrow-callback': 2,
312+
'mocha/valid-suite-description': [2, { pattern: '^[.#@a-z0-9].+' }],
313+
'prefer-arrow-callback': 0,
314+
'mocha/valid-test-description': [2, { pattern: '^should.[a-z0-9]+.*' }],
315+
'tree-shaking/no-side-effects-in-initialization': 0,
316+
'unicorn/consistent-function-scoping': 0,
317+
'unicorn/no-array-for-each': 0,
318+
'unicorn/no-useless-undefined': 0
279319
}
280320
},
281321
{

.github/workflows/continuous-integration.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ jobs:
5656
- id: env
5757
name: Set environment variables
5858
run: node ./tools/cli/loadenv.cjs -gc=test
59+
- id: check-tests
60+
name: Check test suites
61+
run: yarn test
5962
- id: check-build
6063
name: Check builds
6164
run: yarn prepack --tarball --env=test

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ jspm_packages/
7171
# Environment variables
7272
.env*.local
7373

74-
### Jest ###
75-
coverage/
74+
### Testing ###
7675
**/__tests__/results.json
7776

7877
### TypeScript ###

.mocharc.base.cjs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* @file Mocha Configuration - Base
3+
* @see https://mochajs.org/#command-line-usage
4+
* @see https://mochajs.org/#configuration-format
5+
*/
6+
7+
const PWD = process.env.PROJECT_CWD
8+
const TYPES = ['', 'e2e', 'functional', 'integration']
9+
10+
/** @type {Mocha.MochaInstanceOptions} */
11+
const config = {
12+
allowUncaught: false,
13+
asyncOnly: false,
14+
bail: false,
15+
checkLeaks: true,
16+
color: true,
17+
diff: true,
18+
exit: true,
19+
extension: TYPES.map(type => `${type}.spec.ts`),
20+
failZero: false,
21+
forbidOnly: true,
22+
forbidPending: false,
23+
fullTrace: true,
24+
globals: ['chai', 'expect'],
25+
growl: !(require('is-ci') || process.env.GITHUB_ACTIONS === true),
26+
ignore: ['**/coverage/*', '**/node_modules/*'],
27+
inlineDiffs: true,
28+
isWorker: true,
29+
/** @see https://typestrong.org/ts-node/docs/recipes/mocha */
30+
loader: `${PWD}/tools/loaders/esm.mjs`,
31+
noHighlighting: false,
32+
nodeOption: [
33+
'experimental-json-modules',
34+
'es-module-specifier-resolution node'
35+
],
36+
parallel: true,
37+
recursive: true,
38+
/** @see https://github.com/stanleyhlng/mocha-multi-reporters */
39+
reporter: 'mocha-multi-reporters',
40+
reporterOptions: [`configFile=${PWD}/__tests__/config/reporters.json`],
41+
require: [
42+
`${PWD}/__tests__/config/mocha-global-fixtures.ts`,
43+
`${PWD}/__tests__/config/mocha-root-hooks.ts`
44+
],
45+
retries: 0,
46+
sort: false,
47+
spec: '{,!(coverage|node_modules)/**}/__tests__/*.spec.*',
48+
timeout: 2000,
49+
ui: 'bdd',
50+
watch: false
51+
}
52+
53+
module.exports = config

.mocharc.cjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @file Mocha Configuration - Root
3+
* @see https://mochajs.org/#configuration-format
4+
* @see https://github.com/mochajs/mocha/blob/master/example/config/.mocharc.js
5+
*/
6+
7+
/** @type {Mocha.MochaInstanceOptions} */
8+
module.exports = require('./.mocharc.base.cjs')

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Prettier Ignore
22
# See: https://prettier.io/docs/en/ignore.html
33

4-
**/coverage/*
54
**/node_modules/*
65
.husky/_/*
76
.yarn/*

.vscode/settings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141
"format": "svg",
4242
"icon": "lintstagedrc"
4343
},
44+
{
45+
"extensions": [".mocharc.base.cjs", ".mocharc.cjs"],
46+
"format": "svg",
47+
"icon": "mocha"
48+
},
4449
{
4550
"extensions": [
4651
"build.json",
@@ -58,6 +63,11 @@
5863
}
5964
],
6065
"vsicons.associations.folders": [
66+
{
67+
"extensions": ["__doubles__"],
68+
"format": "svg",
69+
"icon": "mock"
70+
},
6171
{
6272
"extensions": ["__fixtures__", "dtos"],
6373
"format": "svg",

CONTRIBUTING.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,14 @@ be part of your code review.
229229

230230
### Testing
231231

232-
This project uses [Jest][15] as its test runner. To run _all_ the tests in this
233-
project, run `yarn test` from the project root.
232+
This project uses [Mocha][15] x [Chai][16] testing workflow.
234233

235-
Husky is configured to run tests before every push. Use [`describe.skip`][16] or
236-
[`it.skip`][17] if you need to create a new issue regarding the test, or need to
237-
make a `wip` commit.
234+
- run project-level test suites: `yarn test`
235+
- run workspace-level test suites: `yarn test:<package.json#name-no-scope>`
236+
237+
Husky is configured to run tests before every push. If you need to create a new
238+
issue regarding a test, or need to make a `wip` commit, use Mocha's [inclusive
239+
tests feature][17] to mark your tests or suites as pending.
238240

239241
### Getting Help
240242

@@ -362,7 +364,7 @@ Before releasing, the following steps must be completed:
362364
- once the PR is merged, the deployment workflow will be triggered
363365
- the maintainer who approved the PR should check to make sure the workflow
364366
completes all jobs as expected. if successful, the workflow will:
365-
- publish package to the [GitHub Package Registry][19] and
367+
- publish package to the [GitHub Package Registry][18] and
366368
- update the production branch (merge branch `next` into `main`)
367369
- publish the drafted release
368370
- the maintainer who approved the PR should go through the PR's linked issues
@@ -385,8 +387,8 @@ Before releasing, the following steps must be completed:
385387
[12]: https://eslint.org
386388
[13]: https://jsdoc.app
387389
[14]: https://github.com/gajus/eslint-plugin-jsdoc
388-
[15]: https://jestjs.io
389-
[16]: https://jestjs.io/docs/api#describeskipname-fn
390-
[17]: https://jestjs.io/docs/api#testskipname-fn
390+
[15]: https://mochajs.org
391+
[16]: https://www.chaijs.com
392+
[17]: https://mochajs.org/#inclusive-tests
391393
[18]: https://www.conventionalcommits.org/en/v1.0.0
392394
[19]: https://github.com/features/packages

0 commit comments

Comments
 (0)