mirror of
https://github.com/discordeno/discordeno.git
synced 2026-05-21 02:40:08 +00:00
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:
@@ -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,
|
||||
}
|
||||
27
.mocharc.cjs
27
.mocharc.cjs
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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:^",
|
||||
|
||||
@@ -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:^",
|
||||
|
||||
@@ -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:^",
|
||||
|
||||
@@ -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:^",
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -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:^"
|
||||
|
||||
42
turbo.json
42
turbo.json
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user