mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-18 22:32:32 +02:00
Sanitize overrides before tests
Co-authored-by: PigeonBar <56974298+PigeonBar@users.noreply.github.com>
This commit is contained in:
parent
bb052e0194
commit
1d96f00d96
21
.github/workflows/tests.yml
vendored
21
.github/workflows/tests.yml
vendored
@ -15,29 +15,8 @@ on:
|
|||||||
types: [checks_requested]
|
types: [checks_requested]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
pre-test:
|
|
||||||
name: Run Pre-test
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Check out Git repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
submodules: 'recursive'
|
|
||||||
path: tests-action
|
|
||||||
- name: Set up Node.js
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 20
|
|
||||||
- name: Install Node.js dependencies
|
|
||||||
working-directory: tests-action
|
|
||||||
run: npm ci
|
|
||||||
- name: Run Pre-test
|
|
||||||
working-directory: tests-action
|
|
||||||
run: npx vitest run --project pre ${{ !runner.debug && '--silent' || '' }}
|
|
||||||
|
|
||||||
run-tests:
|
run-tests:
|
||||||
name: Run Tests
|
name: Run Tests
|
||||||
needs: [pre-test]
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
shard: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
shard: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||||
|
@ -254,6 +254,11 @@ class DefaultOverrides {
|
|||||||
* Note that, for all items in the array, `count` is not used.
|
* Note that, for all items in the array, `count` is not used.
|
||||||
*/
|
*/
|
||||||
readonly ITEM_REWARD_OVERRIDE: ModifierOverride[] = [];
|
readonly ITEM_REWARD_OVERRIDE: ModifierOverride[] = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If `true`, disable all non-scripted opponent trainer encounters.
|
||||||
|
*/
|
||||||
|
readonly DISABLE_STANDARD_TRAINERS_OVERRIDE: boolean = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defaultOverrides = new DefaultOverrides();
|
export const defaultOverrides = new DefaultOverrides();
|
||||||
|
@ -57,6 +57,7 @@ import fs from "node:fs";
|
|||||||
import { expect, vi } from "vitest";
|
import { expect, vi } from "vitest";
|
||||||
import { globalScene } from "#app/global-scene";
|
import { globalScene } from "#app/global-scene";
|
||||||
import type StarterSelectUiHandler from "#app/ui/starter-select-ui-handler";
|
import type StarterSelectUiHandler from "#app/ui/starter-select-ui-handler";
|
||||||
|
import { MockFetch } from "./mocks/mockFetch";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to manage the game state and transitions between phases.
|
* Class to manage the game state and transitions between phases.
|
||||||
@ -122,9 +123,12 @@ export default class GameManager {
|
|||||||
this.settings = new SettingsHelper(this);
|
this.settings = new SettingsHelper(this);
|
||||||
this.reload = new ReloadHelper(this);
|
this.reload = new ReloadHelper(this);
|
||||||
this.modifiers = new ModifierHelper(this);
|
this.modifiers = new ModifierHelper(this);
|
||||||
|
this.override.sanitizeOverrides();
|
||||||
|
|
||||||
// Disables Mystery Encounters on all tests (can be overridden at test level)
|
// Disables Mystery Encounters on all tests (can be overridden at test level)
|
||||||
this.override.mysteryEncounterChance(0);
|
this.override.mysteryEncounterChance(0);
|
||||||
|
|
||||||
|
global.fetch = vi.fn(MockFetch) as any;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6,7 +6,7 @@ import type { GameModes } from "#app/game-mode";
|
|||||||
import { getGameMode } from "#app/game-mode";
|
import { getGameMode } from "#app/game-mode";
|
||||||
import type { ModifierOverride } from "#app/modifier/modifier-type";
|
import type { ModifierOverride } from "#app/modifier/modifier-type";
|
||||||
import type { BattleStyle } from "#app/overrides";
|
import type { BattleStyle } from "#app/overrides";
|
||||||
import Overrides from "#app/overrides";
|
import Overrides, { defaultOverrides } from "#app/overrides";
|
||||||
import type { Unlockables } from "#app/system/unlockables";
|
import type { Unlockables } from "#app/system/unlockables";
|
||||||
import { Biome } from "#enums/biome";
|
import { Biome } from "#enums/biome";
|
||||||
import { Moves } from "#enums/moves";
|
import { Moves } from "#enums/moves";
|
||||||
@ -15,8 +15,9 @@ import type { MysteryEncounterType } from "#enums/mystery-encounter-type";
|
|||||||
import { Species } from "#enums/species";
|
import { Species } from "#enums/species";
|
||||||
import { StatusEffect } from "#enums/status-effect";
|
import { StatusEffect } from "#enums/status-effect";
|
||||||
import type { WeatherType } from "#enums/weather-type";
|
import type { WeatherType } from "#enums/weather-type";
|
||||||
import { vi } from "vitest";
|
import { expect, vi } from "vitest";
|
||||||
import { GameManagerHelper } from "./gameManagerHelper";
|
import { GameManagerHelper } from "./gameManagerHelper";
|
||||||
|
import { shiftCharCodes } from "#app/utils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper to handle overrides in tests
|
* Helper to handle overrides in tests
|
||||||
@ -226,12 +227,7 @@ export class OverridesHelper extends GameManagerHelper {
|
|||||||
* @returns `this`
|
* @returns `this`
|
||||||
*/
|
*/
|
||||||
public disableTrainerWaves(): this {
|
public disableTrainerWaves(): this {
|
||||||
const realFn = getGameMode;
|
vi.spyOn(Overrides, "DISABLE_STANDARD_TRAINERS_OVERRIDE");
|
||||||
vi.spyOn(GameMode, "getGameMode").mockImplementation((gameMode: GameModes) => {
|
|
||||||
const mode = realFn(gameMode);
|
|
||||||
mode.hasTrainers = false;
|
|
||||||
return mode;
|
|
||||||
});
|
|
||||||
this.log("Standard trainer waves are disabled!");
|
this.log("Standard trainer waves are disabled!");
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -263,11 +259,8 @@ export class OverridesHelper extends GameManagerHelper {
|
|||||||
* @returns `this`
|
* @returns `this`
|
||||||
*/
|
*/
|
||||||
public seed(seed: string): this {
|
public seed(seed: string): this {
|
||||||
vi.spyOn(this.game.scene, "resetSeed").mockImplementation(() => {
|
// Shift the seed here with a negative wave number, to compensate for `resetSeed()` shifting the seed itself.
|
||||||
this.game.scene.waveSeed = seed;
|
this.game.scene.setSeed(shiftCharCodes(seed, (this.game.scene.currentBattle?.waveIndex ?? 0) * -1));
|
||||||
Phaser.Math.RND.sow([seed]);
|
|
||||||
this.game.scene.rngCounter = 0;
|
|
||||||
});
|
|
||||||
this.game.scene.resetSeed();
|
this.game.scene.resetSeed();
|
||||||
this.log(`Seed set to "${seed}"!`);
|
this.log(`Seed set to "${seed}"!`);
|
||||||
return this;
|
return this;
|
||||||
@ -539,4 +532,14 @@ export class OverridesHelper extends GameManagerHelper {
|
|||||||
private log(...params: any[]) {
|
private log(...params: any[]) {
|
||||||
console.log("Overrides:", ...params);
|
console.log("Overrides:", ...params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public sanitizeOverrides(): void {
|
||||||
|
for (const key of Object.keys(defaultOverrides)) {
|
||||||
|
if (Overrides[key] !== defaultOverrides[key]) {
|
||||||
|
vi.spyOn(Overrides, key as any, "get").mockReturnValue(defaultOverrides[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(Overrides).toEqual(defaultOverrides);
|
||||||
|
this.log("Sanitizing all overrides!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user