diff --git a/package.json b/package.json index 160ca965bc8..ebaeac728cf 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/data/nature.ts b/src/data/nature.ts index 0d9be0f663d..1ae3b76a6b6 100644 --- a/src/data/nature.ts +++ b/src/data/nature.ts @@ -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]); diff --git a/src/data/pokeball.ts b/src/data/pokeball.ts index 5964884d967..f26451b802b 100644 --- a/src/data/pokeball.ts +++ b/src/data/pokeball.ts @@ -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; diff --git a/src/data/pokemon-stat.ts b/src/data/pokemon-stat.ts index 63dc0cfbc51..16570785a62 100644 --- a/src/data/pokemon-stat.ts +++ b/src/data/pokemon-stat.ts @@ -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 = ""; diff --git a/src/data/weather.ts b/src/data/weather.ts index f671c754873..901ad08d164 100644 --- a/src/data/weather.ts +++ b/src/data/weather.ts @@ -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; diff --git a/src/enums/nature.ts b/src/enums/nature.ts new file mode 100644 index 00000000000..5ab8f3c850b --- /dev/null +++ b/src/enums/nature.ts @@ -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, +} diff --git a/src/enums/pokeball.ts b/src/enums/pokeball.ts new file mode 100644 index 00000000000..8d97fea464c --- /dev/null +++ b/src/enums/pokeball.ts @@ -0,0 +1,8 @@ +export enum PokeballType { + POKEBALL, + GREAT_BALL, + ULTRA_BALL, + ROGUE_BALL, + MASTER_BALL, + LUXURY_BALL, +} diff --git a/src/enums/stat.ts b/src/enums/stat.ts new file mode 100644 index 00000000000..a40319664d6 --- /dev/null +++ b/src/enums/stat.ts @@ -0,0 +1,8 @@ +export enum Stat { + HP = 0, + ATK, + DEF, + SPATK, + SPDEF, + SPD, +} diff --git a/src/enums/weather-type.ts b/src/enums/weather-type.ts new file mode 100644 index 00000000000..fa699bb3514 --- /dev/null +++ b/src/enums/weather-type.ts @@ -0,0 +1,12 @@ +export enum WeatherType { + NONE, + SUNNY, + RAIN, + SANDSTORM, + HAIL, + SNOW, + FOG, + HEAVY_RAIN, + HARSH_SUN, + STRONG_WINDS, +} diff --git a/src/modifier/modifier-type.ts b/src/modifier/modifier-type.ts index d8ec0072bd4..3b43cda6896 100644 --- a/src/modifier/modifier-type.ts +++ b/src/modifier/modifier-type.ts @@ -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), diff --git a/src/overrides.ts b/src/overrides.ts index 3e894967893..8ee801cbf26 100644 --- a/src/overrides.ts +++ b/src/overrides.ts @@ -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 } diff --git a/src/test/pre.test.ts b/src/test/pre.test.ts new file mode 100644 index 00000000000..23f3ade72c2 --- /dev/null +++ b/src/test/pre.test.ts @@ -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); +}); diff --git a/tsconfig.json b/tsconfig.json index 682b3a7084b..546ea2a9d12 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -29,6 +29,7 @@ "node_modules", "dist", "vite.config.ts", - "vitest.config.ts" + "vitest.config.ts", + "vitest.workspace.ts", ] } \ No newline at end of file diff --git a/vite.config.ts b/vite.config.ts index f0830f5b9be..9f5aeb31c02 100644 --- a/vite.config.ts +++ b/vite.config.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, diff --git a/vitest.config.ts b/vitest.config.ts index 7f16059a8ad..d1827103807 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -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: { diff --git a/vitest.workspace.ts b/vitest.workspace.ts new file mode 100644 index 00000000000..38121942004 --- /dev/null +++ b/vitest.workspace.ts @@ -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", +]);