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 = { // @ts-check
...require('./.mocharc.base.cjs'),
require: 'ts-node/register', // If we are running in Bun or Deno, they have native TypeScript support with .js imports, node requires .ts imports
loader: 'ts-node/esm', const supportsTypescript = 'Bun' in globalThis || 'Deno' in globalThis
'enable-source-maps': true,
/** @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": { "scripts": {
"build": "turbo build", "build": "turbo build",
"build:type": "turbo build:type", "build:type": "turbo build:type",
"release-build": "turbo build build:type",
"build:doc": "typedoc --options ./typedoc.jsonc", "build:doc": "typedoc --options ./typedoc.jsonc",
"build:watch": "turbo watch build build:type", "build:watch": "turbo watch build build:type",
"release-build": "turbo build build:type",
"test:unit": "turbo test:unit", "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:deno-unit": "turbo test:deno-unit",
"test:bun-unit": "turbo test:bun-unit",
"test:integration": "turbo test:integration", "test:integration": "turbo test:integration",
"test:e2e": "turbo test:e2e", "test:e2e": "turbo test:e2e",
"test:type": "turbo build:type",
"test:test-type": "turbo test:test-type", "test:test-type": "turbo test:test-type",
"test:type": "turbo build:type",
"check": "turbo check", "check": "turbo check",
"check:all": "biome check --write", "check:all": "biome check --write",
"postinstall": "husky" "postinstall": "husky"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -2,39 +2,53 @@
"$schema": "https://turbo.build/schema.json", "$schema": "https://turbo.build/schema.json",
"tasks": { "tasks": {
"build": { "build": {
"outputs": ["dist/**/*.js"], "inputs": ["src/**/*.ts"],
"inputs": ["src/**/*.ts"] "outputs": ["dist/**/*.js"]
}, },
"build:type": { "build:type": {
"dependsOn": ["^build:type"], "dependsOn": ["^build:type"],
"inputs": ["src/**/*.ts"],
"outputs": ["dist/**/*.d.ts", "dist/**/*.d.ts.map", "dist/tsconfig.tsbuildinfo"] "outputs": ["dist/**/*.d.ts", "dist/**/*.d.ts.map", "dist/tsconfig.tsbuildinfo"]
}, },
"test:unit-coverage": { "check": {
"dependsOn": ["^build"], "dependsOn": ["build:type"],
"outputs": ["coverage/**"] "cache": false
}, },
"test:unit": { "test:unit": {
"dependsOn": ["^build", "build"], "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/**"] "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": { "test:integration": {
"dependsOn": ["^build"], "dependsOn": ["^build"],
"inputs": ["src/**/*.ts", "tests/integration**/*.spec.ts"],
"outputs": ["coverage/**"] "outputs": ["coverage/**"]
}, },
"test:test-type": {
"dependsOn": ["^build:type"]
},
"test:deno-unit": {
"dependsOn": ["^build", "build"]
},
"test:bun-unit": {
"dependsOn": ["^build", "build"]
},
"test:e2e": { "test:e2e": {
"dependsOn": ["^build"], "dependsOn": ["^build"],
"inputs": ["src/**/*.ts", "tests/e2e**/*.spec.ts"],
"outputs": ["coverage/**"], "outputs": ["coverage/**"],
"env": ["DISCORD_TOKEN", "E2E_TEST_GUILD_ID"] "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": { "check": {
"dependsOn": ["build:type"], "dependsOn": ["build:type"],
"cache": false "cache": false