diff --git a/tests/dcc.test.ts b/tests/dcc.test.ts index a4a5bb3..1c83b66 100644 --- a/tests/dcc.test.ts +++ b/tests/dcc.test.ts @@ -136,7 +136,11 @@ interface DccResult { readonly dcc: DccFile } -const args = ['samples/fixtures'] +// This sweep needs the original character/object archives, so it must target +// the real drop — `samples/fixtures` has no `d2char.mpq`. Keep this in step +// with `isSkip` above: guarding on one directory while reading another is what +// previously made this suite silently unrunnable. +const args = ['samples/d2'] const dir = args.find((a) => !a.startsWith('--')) ?? 'samples/d2' const quick = args.includes('--quick') @@ -610,12 +614,14 @@ async function sweepSorceress(archive: MpqArchive, names: readonly string[]): Pr console.log(`== cof + dcc verification over ${dir}${quick ? ' (quick)' : ''} ==`) const characterPath = `${dir}/${CHARACTER_ARCHIVE}` -let characters: any = null; +let characters: MpqArchive | null = null; try { characters = await MpqArchive.open(await fileSource(characterPath)) } catch (err) { - console.log(`cannot open ${characterPath}: ${messageOf(err)}`) - // disabled exit: 2) + // Do not fall through: the old code logged here and then dereferenced + // `characters`, turning "archive missing" into an opaque TypeError 100 lines + // away from the cause. + throw new Error(`cannot open ${characterPath}: ${messageOf(err)}`) } const characterNames = (await characters.listFiles()).map(normalize) console.log(`${CHARACTER_ARCHIVE}: ${String(characterNames.length)} members listed`) diff --git a/tests/formats-malformed.test.ts b/tests/formats-malformed.test.ts index 844fce8..a2c99cd 100644 --- a/tests/formats-malformed.test.ts +++ b/tests/formats-malformed.test.ts @@ -132,9 +132,14 @@ describe('Malformed binary formats fail loudly', () => { }); describe('cof', () => { - const hasD2Drop = fs.existsSync(path.join(__dirname, '../samples/d2')); - test.skipIf(!hasD2Drop)('valid decodes successfully on real asset', () => { - const validCof = fs.readFileSync(path.join(__dirname, '../samples/d2/data/global/chars/so/co/sowaxlbh.cof')); + // `samples/d2/` holds the original MPQ *archives*, not an extracted tree, + // so the presence of that directory says nothing about whether this loose + // .cof exists. Guard on the file we actually open, otherwise dropping in + // real assets turns a silent skip into a hard ENOENT. + const realCofPath = path.join(__dirname, '../samples/d2/data/global/chars/so/co/sowaxlbh.cof'); + const hasRealCof = fs.existsSync(realCofPath); + test.skipIf(!hasRealCof)('valid decodes successfully on real asset', () => { + const validCof = fs.readFileSync(realCofPath); const out = decodeCof(validCof); expect(out.numberOfLayers).toBe(16); }); diff --git a/tests/widths.test.ts b/tests/widths.test.ts index 7a90426..438cf3f 100644 --- a/tests/widths.test.ts +++ b/tests/widths.test.ts @@ -16,7 +16,15 @@ import { readFile } from 'node:fs/promises' import { MpqArchive } from '../src/mpq/archive.ts' import { fileSource } from '../src/mpq/file-source.ts' import { decodeSpriteFile } from '../src/formats/cel.ts' -const isSkip = true && !fs.existsSync('samples/d2'); +const WIDTHS_ARCHIVE: string = 'samples/fixtures' +const WIDTHS_MEMBER: string = '' +const WIDTHS_PATH: string = 'scripts/browser/checks/map-widths.txt' +// This check needs a per-frame widths sidecar and a named member. Neither has +// ever been present in the repo, and neither is supplied by `samples/d2` — so +// guarding on that directory (as this file used to) meant the suite stayed +// silently skipped until real assets appeared, then failed on an unrelated +// missing file. Guard on the inputs actually opened below. +const isSkip = WIDTHS_MEMBER === '' || !fs.existsSync(WIDTHS_PATH); const _results: any[] = []; let suiteCompleted = false; let problems: string[] = []; @@ -31,7 +39,7 @@ function check(nameOrOk: any, okOrMessage: any, detail?: string) { } if (!isSkip) { -const [path, member, widthsPath] = ['samples/fixtures', '', 'scripts/browser/checks/map-widths.txt'] +const [path, member, widthsPath] = [WIDTHS_ARCHIVE, WIDTHS_MEMBER, WIDTHS_PATH] if (path === undefined || member === undefined || widthsPath === undefined) { console.error('usage: node scripts/verify-widths.ts ') // disabled exit: 2)