mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-12-15 06:15:20 +01:00
[Test] Fix incorrect path join logic in test-end-log.ts (#6756)
* [Test] Fix incorrect path join logic in `test-end-log`.ts * Update test-end-log.ts * remove unused import * Apply Biome --------- Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
This commit is contained in:
parent
4b86cfc0ee
commit
0a1cad4814
@ -1,13 +1,13 @@
|
||||
/**
|
||||
* Code to add markers to the beginning and end of tests.
|
||||
* Intended for use with {@linkcode CustomDefaultReporter}, and placed inside test hooks
|
||||
* (rather than as part of the reporter) to ensure Vitest waits for the log messages to be printed.
|
||||
* (rather than as part of the reporter) to ensure Vitest waits for the log messages to be printed before beginning subsequent cases.
|
||||
* @module
|
||||
*/
|
||||
|
||||
// biome-ignore lint/correctness/noUnusedImports: TSDoc
|
||||
import type CustomDefaultReporter from "#test/test-utils/reporters/custom-default-reporter";
|
||||
import { basename, join, relative } from "path";
|
||||
import { join, relative } from "path";
|
||||
import chalk from "chalk";
|
||||
import type { RunnerTask, RunnerTaskResult, RunnerTestCase } from "vitest";
|
||||
|
||||
@ -18,7 +18,12 @@ const TEST_END_BARRIER = chalk.bold.hex("#ff7c7cff")("==================");
|
||||
const TEST_NAME_COLOR = "#008886ff" as const;
|
||||
const VITEST_PINK_COLOR = "#c162de" as const;
|
||||
|
||||
const testRoot = join(import.meta.dirname, "..", "..", "..");
|
||||
/**
|
||||
* The root directory of the project, used when constructing relative paths.
|
||||
* @privateRemarks
|
||||
* Will have to be altered if this file is moved!
|
||||
*/
|
||||
const rootDir = join(import.meta.dirname, "..", "..", "..");
|
||||
|
||||
/**
|
||||
* Log the testfile name and path upon a case starting. \
|
||||
@ -46,17 +51,18 @@ export function logTestEnd(task: RunnerTestCase): void {
|
||||
Name: ${chalk.hex(TEST_NAME_COLOR)(getTestName(task))}
|
||||
Result: ${resultStr}${durationStr}
|
||||
File: ${chalk.hex("#d29b0eff")(
|
||||
getPathFromTest(task.file.filepath) + (task.location ? `:${task.location.line}:${task.location.column}` : ""),
|
||||
// Formatting used to allow for IDE Ctrl+click shortcuts
|
||||
getRelativePath(task.file.filepath) + (task.location ? `:${task.location.line}:${task.location.column}` : ""),
|
||||
)}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path of the current test file relative to the `test` directory.
|
||||
* Get the path of the current test file relative to the project root.
|
||||
* @param abs - The absolute path to the file
|
||||
* @returns The relative path with `test/` appended to it.
|
||||
* @returns The path relative to the project root folder.
|
||||
*/
|
||||
function getPathFromTest(abs: string): string {
|
||||
return join(basename(testRoot), relative(testRoot, abs));
|
||||
function getRelativePath(abs: string): string {
|
||||
return relative(rootDir, abs);
|
||||
}
|
||||
|
||||
function getResultStr(result: RunnerTaskResult | undefined): string {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user