You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.6 KiB
47 lines
1.6 KiB
import { readFile } from 'node:fs/promises';
|
|
import { createHash } from 'node:crypto';
|
|
import { expect, it } from 'vitest';
|
|
import { gameSounds } from '../shared/sounds.mjs';
|
|
|
|
it('todos los efectos declarados existen, son WAV válidos y contienen audio', async () => {
|
|
const paths = new Set(
|
|
Object.values(gameSounds).flatMap((game) =>
|
|
Object.values(game).map((effect) => effect.src),
|
|
),
|
|
);
|
|
for (const path of paths) {
|
|
const bytes = await readFile(new URL(`../static${path}`, import.meta.url));
|
|
expect(bytes.toString('ascii', 0, 4)).toBe('RIFF');
|
|
expect(bytes.toString('ascii', 8, 12)).toBe('WAVE');
|
|
const rate = bytes.readUInt32LE(24),
|
|
length = bytes.readUInt32LE(40);
|
|
expect(length).toBe(bytes.length - 44);
|
|
expect(length / (rate * 2)).toBeGreaterThanOrEqual(0.1);
|
|
let energy = 0;
|
|
for (let i = 44; i < bytes.length; i += 2)
|
|
energy += bytes.readInt16LE(i) ** 2;
|
|
expect(energy / (length / 2)).toBeGreaterThan(10000);
|
|
}
|
|
});
|
|
it('los movimientos de los cinco juegos y las dos acciones del cubilete tienen audios distintos', async () => {
|
|
const effects = [
|
|
gameSounds.ajedrez.move,
|
|
gameSounds.damas.move,
|
|
gameSounds.go.move,
|
|
gameSounds.parchis.move,
|
|
gameSounds.oca.move,
|
|
gameSounds.parchis.shake,
|
|
gameSounds.parchis.roll,
|
|
];
|
|
const hashes = await Promise.all(
|
|
effects.map(async (effect) =>
|
|
createHash('sha256')
|
|
.update(
|
|
await readFile(new URL(`../static${effect.src}`, import.meta.url)),
|
|
)
|
|
.digest('hex'),
|
|
),
|
|
);
|
|
expect(new Set(hashes).size).toBe(effects.length);
|
|
});
|