File size: 2,120 Bytes
c140718 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | import test from 'node:test';
import assert from 'node:assert/strict';
import {readFileSync,existsSync} from 'node:fs';
const data=JSON.parse(readFileSync(new URL('../data.json',import.meta.url),'utf8'));
test('snapshot covers all World Bank economies with every indicator key present',()=>{
assert.ok(data.countries.length>=190,'economy count');
const keys=Object.keys(data.indicators);
assert.ok(keys.includes('sao')&&keys.includes('volume')&&keys.includes('catastrophic')&&keys.includes('impoverishing'),'LCoGS indicators present');
for(const c of data.countries){assert.match(c.id,/^[A-Z]{3}$/);assert.deepEqual(Object.keys(c.series).sort(),keys.slice().sort(),c.id);
for(const [k,s] of Object.entries(c.series)){let prev=-1;for(const [y,v] of s){assert.ok(y>prev&&y>=data.yearRange[0]&&y<=data.yearRange[1],`${c.id} ${k} year order`);assert.ok(Number.isFinite(v),`${c.id} ${k} finite`);prev=y;}}}
});
test('indicator groups only reference defined indicators and LCoGS targets are the Commission values',()=>{
for(const g of data.indicatorGroups)for(const k of g.indicators)assert.ok(data.indicators[k],k);
assert.equal(data.indicators.sao.target,20);assert.equal(data.indicators.volume.target,5000);assert.equal(data.indicators.catastrophic.target,0);assert.equal(data.indicators.impoverishing.target,0);
});
test('no value is fabricated: every non-empty series belongs to a source with a URL and licence note',()=>{
const sourceIds=new Set(data.sources.map(s=>s.id));
for(const [k,d] of Object.entries(data.indicators))assert.ok(sourceIds.has(d.sourceId),k+' source '+d.sourceId);
for(const s of data.sources){assert.match(s.url,/^https:\/\//);assert.ok(s.licenseNote);}
});
test('built index.html embeds the same snapshot version as data.json',{skip:!existsSync(new URL('../index.html',import.meta.url))},()=>{
const html=readFileSync(new URL('../index.html',import.meta.url),'utf8');
assert.ok(html.includes(`window.ASCEND_DATA={"version":"${data.version}"`),'embedded data version');
assert.ok(!html.includes('<script type="module" src="app.mjs">'),'module script was inlined');
});
|