test: Refactor mocha config & test scripts (#4664)

* Merge mocha config file

* Simplify scripts, remove coverage path fixing

Codecov is able to fix the coverage paths on its own

* Readd coveragePathFixing script

* Fix coverage path fix script
This commit is contained in:
Fleny
2026-01-07 20:51:26 +01:00
committed by GitHub
parent 011f0fe0dc
commit 8d90f28307
10 changed files with 85 additions and 75 deletions

View File

@@ -1,9 +0,0 @@
// This needs to be a different file as this is used for Deno and Bun
module.exports = {
recursive: true,
timeout: 2000,
'watch-extensions': 'ts',
'watch-files': ['src', 'tests'],
parallel: false,
}

View File

@@ -1,6 +1,23 @@
module.exports = {
...require('./.mocharc.base.cjs'),
require: 'ts-node/register',
loader: 'ts-node/esm',
'enable-source-maps': true,
// @ts-check
// If we are running in Bun or Deno, they have native TypeScript support with .js imports, node requires .ts imports
const supportsTypescript = 'Bun' in globalThis || 'Deno' in globalThis
/** @type {import("mocha").MochaInstanceOptions & Record<string, unknown>} */
const mochaConfig = {
timeout: 2000,
'watch-extensions': 'ts',
'watch-files': ['src', 'tests'],
}
if (!supportsTypescript) {
mochaConfig.require = ['ts-node/register']
// Node options
mochaConfig.loader = ['ts-node/esm']
// Node will output a ExperimentalWarning about --loader (--experimental-loader) and a DeprecationWarning because ts-node uses fs.Stat
mochaConfig['no-warnings'] = true
mochaConfig['enable-source-maps'] = true
}
module.exports = mochaConfig

View File

@@ -10,17 +10,16 @@
"scripts": {
"build": "turbo build",
"build:type": "turbo build:type",
"release-build": "turbo build build:type",
"build:doc": "typedoc --options ./typedoc.jsonc",
"build:watch": "turbo watch build build:type",
"release-build": "turbo build build:type",
"test:unit": "turbo test:unit",
"test:unit-coverage": "turbo test:unit-coverage",
"test:bun-unit": "turbo test:bun-unit",
"test:deno-unit": "turbo test:deno-unit",
"test:bun-unit": "turbo test:bun-unit",
"test:integration": "turbo test:integration",
"test:e2e": "turbo test:e2e",
"test:type": "turbo build:type",
"test:test-type": "turbo test:test-type",
"test:type": "turbo build:type",
"check": "turbo check",
"check:all": "biome check --write",
"postinstall": "husky"

View File

@@ -17,14 +17,12 @@
"build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist",
"release-build": "yarn build && yarn build:type",
"check": "biome check --write",
"test:unit-coverage": "c8 mocha --no-warnings 'tests/unit/**/*.spec.ts'",
"test:unit": "c8 --r lcov mocha --no-warnings 'tests/unit/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js discordeno",
"test:unit:watch": "mocha --no-warnings --watch --parallel 'tests/unit/**/*.spec.ts'",
"test:deno-unit": "deno -A ../../node_modules/mocha/bin/mocha.js --config ../../.mocharc.base.cjs 'tests/unit/**/*.spec.ts'",
"test:bun-unit": "bun ../../node_modules/mocha/bin/mocha.js --config ../../.mocharc.base.cjs 'tests/unit/**/*.spec.ts'",
"test:e2e": "c8 --r lcov mocha --no-warnings --jobs 1 --t 30000 'tests/e2e/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js rest",
"test:type": "tsc --noEmit",
"test:test-type": "tsc --project tests/tsconfig.json"
"test:unit": "c8 -r lcov mocha 'tests/unit/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js bot",
"test:deno-unit": "deno -A npm:mocha 'tests/unit/**/*.spec.ts'",
"test:bun-unit": "bun --bun mocha 'tests/unit/**/*.spec.ts'",
"test:e2e": "c8 -r lcov mocha -t 30000 'tests/e2e/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js bot",
"test:test-type": "tsc --project tests/tsconfig.json",
"test:type": "tsc --noEmit"
},
"dependencies": {
"@discordeno/gateway": "workspace:^",

View File

@@ -17,13 +17,11 @@
"build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist",
"release-build": "yarn build && yarn build:type",
"check": "biome check --write",
"test:unit-coverage": "c8 mocha --no-warnings 'tests/**/*.spec.ts'",
"test:unit": "c8 --r lcov mocha --no-warnings 'tests/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js discordeno",
"test:unit:watch": "mocha --no-warnings --watch --parallel 'tests/**/*.spec.ts'",
"test:deno-unit": "deno -A ../../node_modules/mocha/bin/mocha.js --config ../../.mocharc.base.cjs 'tests/**/*.spec.ts'",
"test:bun-unit": "bun ../../node_modules/mocha/bin/mocha.js --config ../../.mocharc.base.cjs 'tests/**/*.spec.ts'",
"test:type": "tsc --noEmit",
"test:test-type": "tsc --project tests/tsconfig.json"
"test:unit": "c8 -r lcov mocha 'tests/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js discordeno",
"test:deno-unit": "deno -A npm:mocha 'tests/**/*.spec.ts'",
"test:bun-unit": "bun --bun mocha 'tests/**/*.spec.ts'",
"test:test-type": "tsc --project tests/tsconfig.json",
"test:type": "tsc --noEmit"
},
"dependencies": {
"@discordeno/bot": "workspace:^",

View File

@@ -17,14 +17,12 @@
"build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist",
"release-build": "yarn build && yarn build:type",
"check": "biome check --write",
"test:unit-coverage": "c8 mocha --no-warnings 'tests/unit/**/*.spec.ts'",
"test:unit": "c8 --r lcov mocha --no-warnings 'tests/unit/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js gateway",
"test:unit:watch": "mocha --no-warnings --watch --parallel 'tests/unit/**/*.spec.ts'",
"test:deno-unit": "deno -A ../../node_modules/mocha/bin/mocha.js --config ../../.mocharc.base.cjs 'tests/unit/**/*.spec.ts'",
"test:bun-unit": "bun ../../node_modules/mocha/bin/mocha.js --config ../../.mocharc.base.cjs 'tests/unit/**/*.spec.ts'",
"test:integration": "c8 --r lcov mocha --no-warnings --t 15000 'tests/integration/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js gateway",
"test:type": "tsc --noEmit",
"test:test-type": "tsc --project tests/tsconfig.json"
"test:unit": "c8 -r lcov mocha 'tests/unit/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js gateway",
"test:deno-unit": "deno -A npm:mocha 'tests/unit/**/*.spec.ts'",
"test:bun-unit": "bun --bun mocha 'tests/unit/**/*.spec.ts'",
"test:integration": "c8 -r lcov mocha -t 15000 'tests/integration/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js gateway",
"test:test-type": "tsc --project tests/tsconfig.json",
"test:type": "tsc --noEmit"
},
"dependencies": {
"@discordeno/types": "workspace:^",

View File

@@ -17,14 +17,12 @@
"build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist",
"release-build": "yarn build && yarn build:type",
"check": "biome check --write",
"test:unit-coverage": "c8 mocha --no-warnings 'tests/unit/**/*.spec.ts'",
"test:unit": "c8 --r lcov mocha --no-warnings 'tests/unit/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js rest",
"test:unit:watch": "mocha --no-warnings --watch --parallel 'tests/unit/**/*.spec.ts'",
"test:deno-unit": "deno -A ../../node_modules/mocha/bin/mocha.js --config ../../.mocharc.base.cjs 'tests/unit/**/*.spec.ts'",
"test:bun-unit": "bun ../../node_modules/mocha/bin/mocha.js --config ../../.mocharc.base.cjs 'tests/unit/**/*.spec.ts'",
"test:e2e": "c8 --r lcov mocha --exit --no-warnings --jobs 1 --t 60000 'tests/e2e/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js rest",
"test:type": "tsc --noEmit",
"test:test-type": "tsc --project tests/tsconfig.json"
"test:unit": "c8 -r lcov mocha 'tests/unit/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js rest",
"test:deno-unit": "deno -A npm:mocha 'tests/unit/**/*.spec.ts'",
"test:bun-unit": "bun --bun mocha 'tests/unit/**/*.spec.ts'",
"test:e2e": "c8 -r lcov mocha -t 60000 'tests/e2e/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js rest",
"test:test-type": "tsc --project tests/tsconfig.json",
"test:type": "tsc --noEmit"
},
"dependencies": {
"@discordeno/types": "workspace:^",

View File

@@ -17,11 +17,10 @@
"build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist",
"release-build": "yarn build && yarn build:type",
"check": "biome check --write",
"test:unit-coverage": "c8 mocha --no-warnings 'tests/**/*.spec.ts'",
"test:unit": "c8 --r lcov mocha --no-warnings 'tests/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js utils",
"test:unit:watch": "mocha --no-warnings --watch --parallel 'tests/**/*.spec.ts'",
"test:deno-unit": "deno -A ../../node_modules/mocha/bin/mocha.js --config ../../.mocharc.base.cjs 'tests/**/*.spec.ts'",
"test:bun-unit": "bun ../../node_modules/mocha/bin/mocha.js --config ../../.mocharc.base.cjs 'tests/**/*.spec.ts'",
"test:unit": "c8 -r lcov mocha 'tests/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js types",
"test:deno-unit": "deno -A npm:mocha 'tests/**/*.spec.ts'",
"test:bun-unit": "bun --bun mocha 'tests/**/*.spec.ts'",
"test:test-type": "tsc --project tests/tsconfig.json",
"test:type": "tsc --noEmit"
},
"devDependencies": {

View File

@@ -17,13 +17,11 @@
"build:type": "tsc --declaration --emitDeclarationOnly --declarationDir dist",
"release-build": "yarn build && yarn build:type",
"check": "biome check --write",
"test:unit-coverage": "c8 mocha --no-warnings 'tests/**/*.spec.ts'",
"test:unit": "c8 --r lcov mocha --no-warnings 'tests/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js utils",
"test:unit:watch": "mocha --no-warnings --watch --parallel 'tests/**/*.spec.ts'",
"test:deno-unit": "deno -A ../../node_modules/mocha/bin/mocha.js --config ../../.mocharc.base.cjs 'tests/**/*.spec.ts'",
"test:bun-unit": "bun ../../node_modules/mocha/bin/mocha.js --config ../../.mocharc.base.cjs 'tests/**/*.spec.ts'",
"test:type": "tsc --noEmit",
"test:test-type": "tsc --project tests/tsconfig.json"
"test:unit": "c8 -r lcov mocha 'tests/**/*.spec.ts' && node ../../scripts/coveragePathFixing.js utils",
"test:deno-unit": "deno -A npm:mocha 'tests/**/*.spec.ts'",
"test:bun-unit": "bun --bun mocha 'tests/**/*.spec.ts'",
"test:test-type": "tsc --project tests/tsconfig.json",
"test:type": "tsc --noEmit"
},
"dependencies": {
"@discordeno/types": "workspace:^"

View File

@@ -2,39 +2,53 @@
"$schema": "https://turbo.build/schema.json",
"tasks": {
"build": {
"outputs": ["dist/**/*.js"],
"inputs": ["src/**/*.ts"]
"inputs": ["src/**/*.ts"],
"outputs": ["dist/**/*.js"]
},
"build:type": {
"dependsOn": ["^build:type"],
"inputs": ["src/**/*.ts"],
"outputs": ["dist/**/*.d.ts", "dist/**/*.d.ts.map", "dist/tsconfig.tsbuildinfo"]
},
"test:unit-coverage": {
"dependsOn": ["^build"],
"outputs": ["coverage/**"]
"check": {
"dependsOn": ["build:type"],
"cache": false
},
"test:unit": {
"dependsOn": ["^build", "build"],
// We need to exclude e2e and integration test manually since when there aren't e2e or integration we don't have a unit folder
"inputs": ["src/**/*.ts", "tests/**/*.spec.ts", "!tests/e2e/**/*.spec.ts", "!tests/integration**/*.spec.ts"],
"outputs": ["coverage/**"]
},
"test:deno-unit": {
"dependsOn": ["^build", "build"],
// We need to exclude e2e and integration test manually since when there aren't e2e or integration we don't have a unit folder
"inputs": ["src/**/*.ts", "tests/**/*.spec.ts", "!tests/e2e/**/*.spec.ts", "!tests/integration**/*.spec.ts"]
},
"test:bun-unit": {
"dependsOn": ["^build", "build"],
// We need to exclude e2e and integration test manually since when there aren't e2e or integration we don't have a unit folder
"inputs": ["src/**/*.ts", "tests/**/*.spec.ts", "!tests/e2e/**/*.spec.ts", "!tests/integration**/*.spec.ts"]
},
"test:integration": {
"dependsOn": ["^build"],
"inputs": ["src/**/*.ts", "tests/integration**/*.spec.ts"],
"outputs": ["coverage/**"]
},
"test:test-type": {
"dependsOn": ["^build:type"]
},
"test:deno-unit": {
"dependsOn": ["^build", "build"]
},
"test:bun-unit": {
"dependsOn": ["^build", "build"]
},
"test:e2e": {
"dependsOn": ["^build"],
"inputs": ["src/**/*.ts", "tests/e2e**/*.spec.ts"],
"outputs": ["coverage/**"],
"env": ["DISCORD_TOKEN", "E2E_TEST_GUILD_ID"]
},
"test:test-type": {
"dependsOn": ["^build:type"],
"inputs": ["src/**/*.ts", "tests/**/*.ts"]
},
"test:type": {
"dependsOn": ["^build:type"],
"inputs": ["src/**/*.ts"]
},
"check": {
"dependsOn": ["build:type"],
"cache": false