Skip to content

Commit

Permalink
log wrong file path
Browse files Browse the repository at this point in the history
  • Loading branch information
Greegko committed May 7, 2023
1 parent ace3604 commit 7d4e7ea
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/core-test/tests/utils/test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as ava from "ava";

import { argv } from "process";
import * as util from "util";

import { Command, GameConfig, GameState } from "@rpg-village/core";
Expand All @@ -22,7 +23,15 @@ type Test = {
expectedState: ExpectedState | ExpectedState[];
};

const project_dir = argv[1].replace(/node_modules.*/, "");

export function test(testName: string, { config, initState, commands, expectedState, turn = 0 }: Test) {
const testFilePath = new Error().stack
.split("\n")[2]
.replace("at Object.<anonymous> ", "")
.slice(5, -1)
.replace(project_dir, "");

ava.default(testName, t => {
const game = gameFactory({ state: initState, config } as any);

Expand All @@ -36,15 +45,15 @@ export function test(testName: string, { config, initState, commands, expectedSt
});
}

for (let i = 0; i < turn; i++) {
for (let i = 0; i < +turn; i++) {
game.gameTurn();
}

const gameState = game.getState();

const testExpectedState = (expectedState: ExpectedState) => {
if (typeof expectedState === "object") {
t.like(gameState, expectedState);
t.like(gameState, expectedState, testFilePath);
} else {
expectedState(gameState, {
...t,
Expand Down

0 comments on commit 7d4e7ea

Please sign in to comment.