[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:
Dmitriy K 2024-07-11 13:22:22 -04:00 committed by GitHub
parent 4b3984cf35
commit 2f81bd504c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 166 additions and 79 deletions

View File

@ -9,10 +9,10 @@
"build": "vite build", "build": "vite build",
"build:beta": "vite build --mode beta", "build:beta": "vite build --mode beta",
"preview": "vite preview", "preview": "vite preview",
"test": "vitest run", "test": "vitest run --project pre && vitest run --project main",
"test:cov": "vitest run --coverage", "test:cov": "vitest run --project pre && vitest run --project main --coverage",
"test:watch": "vitest watch --coverage", "test:watch": "vitest run --project pre && vitest watch --project main --coverage",
"test:silent": "vitest run --silent", "test:silent": "vitest run --project pre && vitest run --project main --silent",
"eslint": "eslint --fix .", "eslint": "eslint --fix .",
"eslint-ci": "eslint .", "eslint-ci": "eslint .",
"docs": "typedoc", "docs": "typedoc",

View File

@ -1,36 +1,11 @@
import { Stat, getStatName } from "./pokemon-stat"; import { Stat, getStatName } from "./pokemon-stat";
import * as Utils from "../utils"; import * as Utils from "../utils";
import { TextStyle, getBBCodeFrag } from "../ui/text"; import { TextStyle, getBBCodeFrag } from "../ui/text";
import { Nature } from "#enums/nature";
import { UiTheme } from "#enums/ui-theme"; import { UiTheme } from "#enums/ui-theme";
import i18next from "i18next"; import i18next from "i18next";
export enum Nature { export { 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 function getNatureName(nature: Nature, includeStatEffects: boolean = false, forStarterSelect: boolean = false, ignoreBBCode: boolean = false, uiTheme: UiTheme = UiTheme.DEFAULT): string { 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]); let ret = Utils.toReadableString(Nature[nature]);

View File

@ -1,14 +1,8 @@
import { PokeballType } from "#enums/pokeball";
import BattleScene from "../battle-scene"; import BattleScene from "../battle-scene";
import i18next from "i18next"; import i18next from "i18next";
export enum PokeballType { export { PokeballType };
POKEBALL,
GREAT_BALL,
ULTRA_BALL,
ROGUE_BALL,
MASTER_BALL,
LUXURY_BALL
}
export const MAX_PER_TYPE_POKEBALLS: integer = 99; export const MAX_PER_TYPE_POKEBALLS: integer = 99;

View File

@ -1,13 +1,7 @@
import { Stat } from "#enums/stat";
import i18next from "i18next"; import i18next from "i18next";
export enum Stat { export { Stat };
HP = 0,
ATK,
DEF,
SPATK,
SPDEF,
SPD
}
export function getStatName(stat: Stat, shorten: boolean = false) { export function getStatName(stat: Stat, shorten: boolean = false) {
let ret: string = ""; let ret: string = "";

View File

@ -1,4 +1,5 @@
import { Biome } from "#enums/biome"; import { Biome } from "#enums/biome";
import { WeatherType } from "#enums/weather-type";
import { getPokemonNameWithAffix } from "../messages"; import { getPokemonNameWithAffix } from "../messages";
import Pokemon from "../field/pokemon"; import Pokemon from "../field/pokemon";
import { Type } from "./type"; import { Type } from "./type";
@ -9,19 +10,7 @@ import { SuppressWeatherEffectAbAttr } from "./ability";
import { TerrainType, getTerrainName } from "./terrain"; import { TerrainType, getTerrainName } from "./terrain";
import i18next from "i18next"; import i18next from "i18next";
export enum WeatherType { export { WeatherType };
NONE,
SUNNY,
RAIN,
SANDSTORM,
HAIL,
SNOW,
FOG,
HEAVY_RAIN,
HARSH_SUN,
STRONG_WINDS
}
export class Weather { export class Weather {
public weatherType: WeatherType; public weatherType: WeatherType;
public turnsLeft: integer; public turnsLeft: integer;

27
src/enums/nature.ts Normal file
View 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
View 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
View File

@ -0,0 +1,8 @@
export enum Stat {
HP = 0,
ATK,
DEF,
SPATK,
SPDEF,
SPD,
}

12
src/enums/weather-type.ts Normal file
View File

@ -0,0 +1,12 @@
export enum WeatherType {
NONE,
SUNNY,
RAIN,
SANDSTORM,
HAIL,
SNOW,
FOG,
HEAVY_RAIN,
HARSH_SUN,
STRONG_WINDS,
}

View File

@ -1154,6 +1154,8 @@ class WeightedModifierType {
} }
} }
export type ModifierTypes = keyof typeof modifierTypes;
export const modifierTypes = { export const modifierTypes = {
POKEBALL: () => new AddPokeballModifierType("pb", PokeballType.POKEBALL, 5), POKEBALL: () => new AddPokeballModifierType("pb", PokeballType.POKEBALL, 5),
GREAT_BALL: () => new AddPokeballModifierType("gb", PokeballType.GREAT_BALL, 5), GREAT_BALL: () => new AddPokeballModifierType("gb", PokeballType.GREAT_BALL, 5),

View File

@ -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 { Abilities } from "#enums/abilities";
import { BerryType } from "#enums/berry-type"; import { BerryType } from "#enums/berry-type";
import { Biome } from "#enums/biome"; import { Biome } from "#enums/biome";
import { Moves } from "#enums/moves"; import { Moves } from "#enums/moves";
import { Nature } from "#enums/nature";
import { PokeballType } from "#enums/pokeball";
import { Species } from "#enums/species"; import { Species } from "#enums/species";
import { Stat } from "#enums/stat";
import { TimeOfDay } from "#enums/time-of-day"; 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 * 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 * - SpeciesStatBoosterItem is for SPECIES_STAT_BOOSTER
*/ */
interface ModifierOverride { interface ModifierOverride {
name: keyof typeof modifierTypes & string, name: ModifierTypes & string,
count?: integer count?: integer
type?: TempBattleStat|Stat|Nature|Type|BerryType|SpeciesStatBoosterItem type?: TempBattleStat|Stat|Nature|Type|BerryType|SpeciesStatBoosterItem
} }

61
src/test/pre.test.ts Normal file
View 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);
});

View File

@ -29,6 +29,7 @@
"node_modules", "node_modules",
"dist", "dist",
"vite.config.ts", "vite.config.ts",
"vitest.config.ts" "vitest.config.ts",
"vitest.workspace.ts",
] ]
} }

View File

@ -3,7 +3,6 @@ import tsconfigPaths from 'vite-tsconfig-paths';
export const defaultConfig = { export const defaultConfig = {
plugins: [tsconfigPaths() as any], plugins: [tsconfigPaths() as any],
server: { host: '0.0.0.0', port: 8000 },
clearScreen: false, clearScreen: false,
build: { build: {
minify: 'esbuild' as const, minify: 'esbuild' as const,

View File

@ -1,9 +1,12 @@
import { defineConfig } from 'vitest/config'; import { defineProject } from 'vitest/config';
import { defaultConfig } from './vite.config'; import { defaultConfig } from './vite.config';
export default defineConfig(({mode}) => ({ export default defineProject(({ mode }) => ({
...defaultConfig, ...defaultConfig,
test: { test: {
name: "main",
include: ["./src/test/**/*.{test,spec}.ts"],
exclude: ["./src/test/pre.test.ts"],
setupFiles: ['./src/test/vitest.setup.ts'], setupFiles: ['./src/test/vitest.setup.ts'],
server: { server: {
deps: { deps: {

14
vitest.workspace.ts Normal file
View 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",
]);