diablo2-web/tests/act-scene-monster-plan.test.ts

47 lines
2.1 KiB
TypeScript

/**
* The act scene must not invent monsters (issue #58 item 5).
*
* `DEMO_MONSTERS` was three hand-written monsters the scene spawned 12 of
* whenever a level's plan came back empty — including in a town whose name did
* not happen to contain the English substring "town". They also rendered as red
* boxes, because `demo-*` ids are in no art table, so a data failure looked like
* content twice over.
*/
import { describe, expect, it } from 'vitest'
import { readFileSync } from 'node:fs'
import { monsterPlanStatusText } from '../src/scene/act-scene.ts'
import * as demoData from '../src/game/demo-data.ts'
const ACT_SCENE_SOURCE = readFileSync(new URL('../src/scene/act-scene.ts', import.meta.url), 'utf8')
/**
* Comments are stripped before scanning: the docstrings deliberately still name
* the deleted fallback to explain why it is gone, and that is not a code path.
*/
const ACT_SCENE_CODE = ACT_SCENE_SOURCE.replace(/\/\*[\s\S]*?\*\//g, '').replace(/\/\/[^\n]*/g, '')
describe('no synthetic monster fallback', () => {
it('demo-data no longer exports a monster roster', () => {
expect(Object.keys(demoData)).not.toContain('DEMO_MONSTERS')
// The other demo tables are still used by the scene's engine options.
expect(Object.keys(demoData)).toContain('DEMO_SKILLS')
})
it('the act scene has no placeholder spawn path left', () => {
expect(ACT_SCENE_CODE).not.toContain('DEMO_MONSTERS')
expect(ACT_SCENE_CODE).not.toContain('PLACEHOLDER_MONSTER_COUNT')
// The spawn gate was an English substring match on the *display* name, so a
// renamed or translated town spawned 12 fake monsters in the square. (The
// pack index's `slug.includes('town')` level lookup is a different thing
// and is still there.)
expect(ACT_SCENE_CODE).not.toContain("toLowerCase().includes('town')")
expect(ACT_SCENE_CODE).not.toContain('spawnMonsters(')
})
it('reports an empty plan rather than hiding it', () => {
expect(monsterPlanStatusText(0)).toContain('本关未规划到怪物')
expect(monsterPlanStatusText(0)).toContain('怪物 0')
expect(monsterPlanStatusText(37)).toBe(' · 怪物 37')
})
})