Files
code/tests/acceptance/3/criteria.test.js
e0425bed061809c5ce17450fe47dc970090a0938 6b8f44119e
All checks were successful
elffuss/validation Validation passed
Solution 0x652a4c8d8d614a77a0eafb2df15ecc122e7733c2d0939ac32325dd8c8b78002d
T2T-Item: 0x652a4c8d8d614a77a0eafb2df15ecc122e7733c2d0939ac32325dd8c8b78002d
T2T-Issue: 0x848d97f788f6a99d51bb5fed8b5045346c66a05c693b03fbe211bd811ee80443
2026-10-02 06:50:38 +00:00

59 lines
2.3 KiB
JavaScript

import { test } from 'node:test'
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import * as mod from '../../../web/js/main.js' // the code under test: call it as mod.<name>(...)
const source = readFileSync(new URL('../../../web/js/main.js', import.meta.url), 'utf8') // the text of web/js/main.js, for a criterion about how the file is written
test('criterion 1', () => {
// Every `litert:<key>` menu id of web/js/main.js corresponds to a key of `MODELS` exported by `providers/litert.js`.
const litertModels = mod.providers.litert.MODELS || {};
const menuIds = mod.menuIds || [];
const litertMenuIds = menuIds.filter(id => id.startsWith('litert:'));
for (const litertId of litertMenuIds) {
const key = litertId.substring(7);
assert.ok(litertModels.hasOwnProperty(key), `Menu ID ${litertId} must correspond to a key in LiteRT MODELS.`);
}
})
test('criterion 2', () => {
// Every key of `MODELS` that the current menu offers is still offered.
const litertModels = mod.providers.litert.MODELS || {};
const menuIds = mod.menuIds || [];
for (const key in litertModels) {
const menuId = `litert:${key}`;
assert.ok(menuIds.includes(menuId), `LiteRT model key ${key} must have a corresponding menu entry.`);
}
})
test('criterion 3', () => {
// The label of each LiteRT menu entry equals the `label` of its `MODELS` entry.
const litertModels = mod.providers.litert.MODELS || {};
const menuIds = mod.menuIds || [];
for (const key in litertModels) {
const menuId = `litert:${key}`;
const model = litertModels[key];
const menuEntry = menuIds.find(id => id === menuId);
if (menuEntry) {
const menuEntryData = mod.menuData.find(m => m.id === menuId);
assert.equal(model.label, menuEntryData.label, `Label mismatch for LiteRT model ${key}.`);
}
}
})
test('criterion 4', () => {
// The menu contains no engine entry that the engine registry does not list.
const engineRegistry = mod.engineRegistry || {};
const menuIds = mod.menuIds || [];
for (const menuId of menuIds) {
if (menuId.startsWith('engine:')) {
const engineKey = menuId.substring(7);
assert.ok(engineRegistry.hasOwnProperty(engineKey), `Menu entry ${menuId} references an engine not in the registry.`);
}
}
})