Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

63 lines
1.9 KiB
TypeScript
Raw Permalink Normal View History

2026-01-15 11:15:37 +00:00
/*
Copyright 2026 Element Creations Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
import { defineConfig, type ViteUserConfig } from "vitest/config";
import { type Reporter } from "vitest/reporters";
import { env } from "process";
const reporters: ViteUserConfig["test"]["reporters"] = [["default"]];
const slowTestReporter: Reporter = {
onTestRunEnd(testModules, unhandledErrors, reason) {
const tests = testModules
.flatMap((m) => Array.from(m.children.allTests()))
2026-02-04 11:46:48 +00:00
.filter((test) => test.diagnostic()?.slow);
2026-01-15 11:15:37 +00:00
tests.sort((x, y) => x.diagnostic()?.duration! - y.diagnostic()?.duration!);
tests.reverse();
if (tests.length > 0) {
console.warn("Slowest 10 tests:");
}
for (const t of tests.slice(0, 10)) {
console.warn(`${t.module.moduleId} > ${t.fullName}: ${t.diagnostic()?.duration.toFixed(0)}ms`);
}
},
};
// if we're running under GHA, enable the GHA & Sonar reporters
if (env["GITHUB_ACTIONS"] !== undefined) {
reporters.push(["github-actions", { silent: false }]);
reporters.push([
"vitest-sonar-reporter",
{
outputFile: process.env.SHARD
? `coverage/sonar-report-${process.env.SHARD}.xml`
: "coverage/sonar-report.xml",
},
]);
// if we're running against the develop branch, also enable the slow test reporter
if (env["GITHUB_REF"] == "refs/heads/develop") {
reporters.push(slowTestReporter);
}
}
export default defineConfig({
test: {
coverage: {
provider: "v8",
include: ["src/**/*"],
reporter: "lcov",
},
environment: "node",
reporters,
setupFiles: "spec/setupTests.ts",
globals: true,
pool: "threads",
},
});