mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2024-11-25 08:16:04 +00:00
[Test] Prevent tests from running if overrides are different from the default values (#2110)
* mock default overrides in test setup * change beforeEach to beforeALl * move some more enums into the enums directory * replace modules that import i18n into overrides with modules that don't * add pre tests and update vitest configs, scripts * replace tabs with spaces * fix vitest server port overlap warning * add missing overrides and clean up workspace config * change test name * include spec files in main test suite
This commit is contained in:
parent
4b3984cf35
commit
2f81bd504c
@ -9,10 +9,10 @@
|
||||
"build": "vite build",
|
||||
"build:beta": "vite build --mode beta",
|
||||
"preview": "vite preview",
|
||||
"test": "vitest run",
|
||||
"test:cov": "vitest run --coverage",
|
||||
"test:watch": "vitest watch --coverage",
|
||||
"test:silent": "vitest run --silent",
|
||||
"test": "vitest run --project pre && vitest run --project main",
|
||||
"test:cov": "vitest run --project pre && vitest run --project main --coverage",
|
||||
"test:watch": "vitest run --project pre && vitest watch --project main --coverage",
|
||||
"test:silent": "vitest run --project pre && vitest run --project main --silent",
|
||||
"eslint": "eslint --fix .",
|
||||
"eslint-ci": "eslint .",
|
||||
"docs": "typedoc",
|
||||
|
@ -1,36 +1,11 @@
|
||||
import { Stat, getStatName } from "./pokemon-stat";
|
||||
import * as Utils from "../utils";
|
||||
import { TextStyle, getBBCodeFrag } from "../ui/text";
|
||||
import { Nature } from "#enums/nature";
|
||||
import { UiTheme } from "#enums/ui-theme";
|
||||
import i18next from "i18next";
|
||||
|
||||
export enum Nature {
|
||||
HARDY,
|
||||
LONELY,
|
||||
BRAVE,
|
||||
ADAMANT,
|
||||
NAUGHTY,
|
||||
BOLD,
|
||||
DOCILE,
|
||||
RELAXED,
|
||||
IMPISH,
|
||||
LAX,
|
||||
TIMID,
|
||||
HASTY,
|
||||
SERIOUS,
|
||||
JOLLY,
|
||||
NAIVE,
|
||||
MODEST,
|
||||
MILD,
|
||||
QUIET,
|
||||
BASHFUL,
|
||||
RASH,
|
||||
CALM,
|
||||
GENTLE,
|
||||
SASSY,
|
||||
CAREFUL,
|
||||
QUIRKY
|
||||
}
|
||||
export { Nature };
|
||||
|
||||
export function getNatureName(nature: Nature, includeStatEffects: boolean = false, forStarterSelect: boolean = false, ignoreBBCode: boolean = false, uiTheme: UiTheme = UiTheme.DEFAULT): string {
|
||||
let ret = Utils.toReadableString(Nature[nature]);
|
||||
|
@ -1,14 +1,8 @@
|
||||
import { PokeballType } from "#enums/pokeball";
|
||||
import BattleScene from "../battle-scene";
|
||||
import i18next from "i18next";
|
||||
|
||||
export enum PokeballType {
|
||||
POKEBALL,
|
||||
GREAT_BALL,
|
||||
ULTRA_BALL,
|
||||
ROGUE_BALL,
|
||||
MASTER_BALL,
|
||||
LUXURY_BALL
|
||||
}
|
||||
export { PokeballType };
|
||||
|
||||
export const MAX_PER_TYPE_POKEBALLS: integer = 99;
|
||||
|
||||
|
@ -1,13 +1,7 @@
|
||||
import { Stat } from "#enums/stat";
|
||||
import i18next from "i18next";
|
||||
|
||||
export enum Stat {
|
||||
HP = 0,
|
||||
ATK,
|
||||
DEF,
|
||||
SPATK,
|
||||
SPDEF,
|
||||
SPD
|
||||
}
|
||||
export { Stat };
|
||||
|
||||
export function getStatName(stat: Stat, shorten: boolean = false) {
|
||||
let ret: string = "";
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { Biome } from "#enums/biome";
|
||||
import { WeatherType } from "#enums/weather-type";
|
||||
import { getPokemonNameWithAffix } from "../messages";
|
||||
import Pokemon from "../field/pokemon";
|
||||
import { Type } from "./type";
|
||||
@ -9,19 +10,7 @@ import { SuppressWeatherEffectAbAttr } from "./ability";
|
||||
import { TerrainType, getTerrainName } from "./terrain";
|
||||
import i18next from "i18next";
|
||||
|
||||
export enum WeatherType {
|
||||
NONE,
|
||||
SUNNY,
|
||||
RAIN,
|
||||
SANDSTORM,
|
||||
HAIL,
|
||||
SNOW,
|
||||
FOG,
|
||||
HEAVY_RAIN,
|
||||
HARSH_SUN,
|
||||
STRONG_WINDS
|
||||
}
|
||||
|
||||
export { WeatherType };
|
||||
export class Weather {
|
||||
public weatherType: WeatherType;
|
||||
public turnsLeft: integer;
|
||||
|
27
src/enums/nature.ts
Normal file
27
src/enums/nature.ts
Normal file
@ -0,0 +1,27 @@
|
||||
export enum Nature {
|
||||
HARDY,
|
||||
LONELY,
|
||||
BRAVE,
|
||||
ADAMANT,
|
||||
NAUGHTY,
|
||||
BOLD,
|
||||
DOCILE,
|
||||
RELAXED,
|
||||
IMPISH,
|
||||
LAX,
|
||||
TIMID,
|
||||
HASTY,
|
||||
SERIOUS,
|
||||
JOLLY,
|
||||
NAIVE,
|
||||
MODEST,
|
||||
MILD,
|
||||
QUIET,
|
||||
BASHFUL,
|
||||
RASH,
|
||||
CALM,
|
||||
GENTLE,
|
||||
SASSY,
|
||||
CAREFUL,
|
||||
QUIRKY,
|
||||
}
|
8
src/enums/pokeball.ts
Normal file
8
src/enums/pokeball.ts
Normal file
@ -0,0 +1,8 @@
|
||||
export enum PokeballType {
|
||||
POKEBALL,
|
||||
GREAT_BALL,
|
||||
ULTRA_BALL,
|
||||
ROGUE_BALL,
|
||||
MASTER_BALL,
|
||||
LUXURY_BALL,
|
||||
}
|
8
src/enums/stat.ts
Normal file
8
src/enums/stat.ts
Normal file
@ -0,0 +1,8 @@
|
||||
export enum Stat {
|
||||
HP = 0,
|
||||
ATK,
|
||||
DEF,
|
||||
SPATK,
|
||||
SPDEF,
|
||||
SPD,
|
||||
}
|
12
src/enums/weather-type.ts
Normal file
12
src/enums/weather-type.ts
Normal file
@ -0,0 +1,12 @@
|
||||
export enum WeatherType {
|
||||
NONE,
|
||||
SUNNY,
|
||||
RAIN,
|
||||
SANDSTORM,
|
||||
HAIL,
|
||||
SNOW,
|
||||
FOG,
|
||||
HEAVY_RAIN,
|
||||
HARSH_SUN,
|
||||
STRONG_WINDS,
|
||||
}
|
@ -1154,6 +1154,8 @@ class WeightedModifierType {
|
||||
}
|
||||
}
|
||||
|
||||
export type ModifierTypes = keyof typeof modifierTypes;
|
||||
|
||||
export const modifierTypes = {
|
||||
POKEBALL: () => new AddPokeballModifierType("pb", PokeballType.POKEBALL, 5),
|
||||
GREAT_BALL: () => new AddPokeballModifierType("gb", PokeballType.GREAT_BALL, 5),
|
||||
|
@ -1,23 +1,23 @@
|
||||
import { WeatherType } from "./data/weather";
|
||||
import { Variant } from "./data/variant";
|
||||
import { TempBattleStat } from "./data/temp-battle-stat";
|
||||
import { Nature } from "./data/nature";
|
||||
import { Type } from "./data/type";
|
||||
import { Stat } from "./data/pokemon-stat";
|
||||
import { PokeballCounts } from "./battle-scene";
|
||||
import { PokeballType } from "./data/pokeball";
|
||||
import { Gender } from "./data/gender";
|
||||
import { StatusEffect } from "./data/status-effect";
|
||||
import { SpeciesStatBoosterItem, modifierTypes } from "./modifier/modifier-type";
|
||||
import { VariantTier } from "./enums/variant-tiers";
|
||||
import { EggTier } from "#enums/egg-type";
|
||||
import { allSpecies } from "./data/pokemon-species"; // eslint-disable-line @typescript-eslint/no-unused-vars
|
||||
import { Abilities } from "#enums/abilities";
|
||||
import { BerryType } from "#enums/berry-type";
|
||||
import { Biome } from "#enums/biome";
|
||||
import { Moves } from "#enums/moves";
|
||||
import { Nature } from "#enums/nature";
|
||||
import { PokeballType } from "#enums/pokeball";
|
||||
import { Species } from "#enums/species";
|
||||
import { Stat } from "#enums/stat";
|
||||
import { TimeOfDay } from "#enums/time-of-day";
|
||||
import { WeatherType } from "#enums/weather-type";
|
||||
import { VariantTier } from "#enums/variant-tiers";
|
||||
import { EggTier } from "#enums/egg-type";
|
||||
import { type PokeballCounts } from "./battle-scene";
|
||||
import { Gender } from "./data/gender";
|
||||
import { allSpecies } from "./data/pokemon-species"; // eslint-disable-line @typescript-eslint/no-unused-vars
|
||||
import { StatusEffect } from "./data/status-effect";
|
||||
import { TempBattleStat } from "./data/temp-battle-stat";
|
||||
import { Type } from "./data/type";
|
||||
import { Variant } from "./data/variant";
|
||||
import { type SpeciesStatBoosterItem, type ModifierTypes } from "./modifier/modifier-type";
|
||||
|
||||
/**
|
||||
* Overrides for testing different in game situations
|
||||
@ -128,7 +128,7 @@ export const EGG_GACHA_PULL_COUNT_OVERRIDE: number = 0;
|
||||
* - SpeciesStatBoosterItem is for SPECIES_STAT_BOOSTER
|
||||
*/
|
||||
interface ModifierOverride {
|
||||
name: keyof typeof modifierTypes & string,
|
||||
name: ModifierTypes & string,
|
||||
count?: integer
|
||||
type?: TempBattleStat|Stat|Nature|Type|BerryType|SpeciesStatBoosterItem
|
||||
}
|
||||
|
61
src/test/pre.test.ts
Normal file
61
src/test/pre.test.ts
Normal file
@ -0,0 +1,61 @@
|
||||
import { StatusEffect } from "#app/data/status-effect";
|
||||
import * as _Overrides from "#app/overrides";
|
||||
import { Abilities } from "#enums/abilities";
|
||||
import { Biome } from "#enums/biome";
|
||||
import { WeatherType } from "#enums/weather-type";
|
||||
import { expect, test } from "vitest";
|
||||
|
||||
test("Overrides are default values", () => {
|
||||
const defaultOverrides = {
|
||||
SEED_OVERRIDE: "",
|
||||
WEATHER_OVERRIDE: WeatherType.NONE,
|
||||
DOUBLE_BATTLE_OVERRIDE: false,
|
||||
SINGLE_BATTLE_OVERRIDE: false,
|
||||
STARTING_WAVE_OVERRIDE: 0,
|
||||
STARTING_BIOME_OVERRIDE: Biome.TOWN,
|
||||
ARENA_TINT_OVERRIDE: null,
|
||||
XP_MULTIPLIER_OVERRIDE: null,
|
||||
STARTING_MONEY_OVERRIDE: 0,
|
||||
FREE_CANDY_UPGRADE_OVERRIDE: false,
|
||||
POKEBALL_OVERRIDE: _Overrides.POKEBALL_OVERRIDE, // Pass through pokeballs
|
||||
// Player
|
||||
STARTER_FORM_OVERRIDES: {},
|
||||
STARTING_LEVEL_OVERRIDE: 0,
|
||||
STARTER_SPECIES_OVERRIDE: 0,
|
||||
ABILITY_OVERRIDE: Abilities.NONE,
|
||||
PASSIVE_ABILITY_OVERRIDE: Abilities.NONE,
|
||||
STATUS_OVERRIDE: StatusEffect.NONE,
|
||||
GENDER_OVERRIDE: null,
|
||||
MOVESET_OVERRIDE: [],
|
||||
SHINY_OVERRIDE: false,
|
||||
VARIANT_OVERRIDE: 0,
|
||||
// Opponent
|
||||
OPP_SPECIES_OVERRIDE: 0,
|
||||
OPP_LEVEL_OVERRIDE: 0,
|
||||
OPP_ABILITY_OVERRIDE: Abilities.NONE,
|
||||
OPP_PASSIVE_ABILITY_OVERRIDE: Abilities.NONE,
|
||||
OPP_STATUS_OVERRIDE: StatusEffect.NONE,
|
||||
OPP_GENDER_OVERRIDE: null,
|
||||
OPP_MOVESET_OVERRIDE: [],
|
||||
OPP_SHINY_OVERRIDE: false,
|
||||
OPP_VARIANT_OVERRIDE: 0,
|
||||
OPP_IVS_OVERRIDE: [],
|
||||
// Eggs
|
||||
EGG_IMMEDIATE_HATCH_OVERRIDE: false,
|
||||
EGG_TIER_OVERRIDE: null,
|
||||
EGG_SHINY_OVERRIDE: false,
|
||||
EGG_VARIANT_OVERRIDE: null,
|
||||
EGG_FREE_GACHA_PULLS_OVERRIDE: false,
|
||||
EGG_GACHA_PULL_COUNT_OVERRIDE: 0,
|
||||
// Items
|
||||
STARTING_MODIFIER_OVERRIDE: [],
|
||||
OPP_MODIFIER_OVERRIDE: [],
|
||||
STARTING_HELD_ITEMS_OVERRIDE: [],
|
||||
OPP_HELD_ITEMS_OVERRIDE: [],
|
||||
NEVER_CRIT_OVERRIDE: false,
|
||||
ITEM_REWARD_OVERRIDE: [],
|
||||
} satisfies typeof _Overrides;
|
||||
|
||||
const Overrides = Object.assign({}, _Overrides);
|
||||
expect(Overrides).toEqual(defaultOverrides);
|
||||
});
|
@ -29,6 +29,7 @@
|
||||
"node_modules",
|
||||
"dist",
|
||||
"vite.config.ts",
|
||||
"vitest.config.ts"
|
||||
"vitest.config.ts",
|
||||
"vitest.workspace.ts",
|
||||
]
|
||||
}
|
@ -3,7 +3,6 @@ import tsconfigPaths from 'vite-tsconfig-paths';
|
||||
|
||||
export const defaultConfig = {
|
||||
plugins: [tsconfigPaths() as any],
|
||||
server: { host: '0.0.0.0', port: 8000 },
|
||||
clearScreen: false,
|
||||
build: {
|
||||
minify: 'esbuild' as const,
|
||||
|
@ -1,9 +1,12 @@
|
||||
import { defineConfig } from 'vitest/config';
|
||||
import { defineProject } from 'vitest/config';
|
||||
import { defaultConfig } from './vite.config';
|
||||
|
||||
export default defineConfig(({mode}) => ({
|
||||
export default defineProject(({ mode }) => ({
|
||||
...defaultConfig,
|
||||
test: {
|
||||
name: "main",
|
||||
include: ["./src/test/**/*.{test,spec}.ts"],
|
||||
exclude: ["./src/test/pre.test.ts"],
|
||||
setupFiles: ['./src/test/vitest.setup.ts'],
|
||||
server: {
|
||||
deps: {
|
||||
|
14
vitest.workspace.ts
Normal file
14
vitest.workspace.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { defineWorkspace } from "vitest/config";
|
||||
import { defaultConfig } from "./vite.config";
|
||||
|
||||
export default defineWorkspace([
|
||||
{
|
||||
...defaultConfig,
|
||||
test: {
|
||||
name: "pre",
|
||||
include: ["src/test/pre.test.ts"],
|
||||
environment: "jsdom",
|
||||
},
|
||||
},
|
||||
"./vitest.config.ts",
|
||||
]);
|
Loading…
Reference in New Issue
Block a user