- The harness builds the DOM without the page's 2 MB of script text and runs the scripts straight in the window: a page load in tests takes about half the time (jsdom's parser was slow on the script text). - That also took the game's source out of the DOM, which showed three tests that matched a phrase in the page source rather than the screen; they now check the panel, the routing window and the dictionary. - CI plans its split once and runs the tests on 6 runners; every run on main records each file's time and caches it, so the parts stay even without anyone refreshing tests/durations.json. - auto-release.yml and release.yml call the same sharded tests instead of running all 170 files on one runner each (11 and 15 min); a release is tested once, before it is tagged. - Audit: five tests that duplicated a gameplay rule or checked nothing are gone; the two slowest checks sample a third of the cities, and a year of play to reach one due date became a moved due date.
46 lines
2.5 KiB
JavaScript
46 lines
2.5 KiB
JavaScript
const test=require('node:test');
|
|
const assert=require('node:assert/strict');
|
|
const {load}=require('./harness');
|
|
// #257: months have their real lengths, and leap years come every four years (not every hundred, but every four hundred).
|
|
test('#257 the calendar has real months and leap years',()=>{
|
|
const {ev,dom,errors}=load();try{
|
|
ev("ACT.start({})");
|
|
assert.equal(ev('dateStr(0)'),'Y1 · Jan 1');
|
|
assert.equal(ev('dateStr(30)'),'Y1 · Jan 31','January has 31 days');
|
|
assert.equal(ev('dateStr(31)'),'Y1 · Feb 1');
|
|
assert.equal(ev('dateStr(58)'),'Y1 · Feb 28');
|
|
assert.equal(ev('dateStr(59)'),'Y1 · Mar 1','no 29 February in Y1');
|
|
assert.equal(ev('dateStr(364)'),'Y1 · Dec 31');
|
|
assert.equal(ev('dateStr(365)'),'Y2 · Jan 1');
|
|
const y4=ev('yearStart(4)');assert.equal(y4,3*365);
|
|
assert.equal(ev(`dateStr(${y4}+59)`),'Y4 · Feb 29','Y4 is a leap year');
|
|
assert.equal(ev(`dateStr(${y4}+365)`),'Y4 · Dec 31');
|
|
assert.equal(ev(`dateStr(${y4}+366)`),'Y5 · Jan 1');
|
|
assert.equal(ev('[100,200,400].map(leapY).join()'),'false,false,true');
|
|
// every day is one date, in order: a round trip through dayOf over 401 years
|
|
assert.equal(ev(`(()=>{for(let d=0;d<yearStart(402);d++){const c=cal(d);if(dayOf(c.y,c.m,c.d)!==d)return d;}return -1})()`),-1);
|
|
assert.equal(ev('[0,31,59,90].map(monLen).join()'),'31,28,31,30');
|
|
assert.deepEqual(errors,[]);
|
|
}finally{dom.window.close();}
|
|
});
|
|
test('#257 loan statements and the intern budget follow calendar months',()=>{
|
|
const {ev,dom}=load();try{
|
|
ev("ACT.start({})");
|
|
assert.equal(ev('monthiversary(30,58)'),true,'a loan taken on 31 January has its statement on 28 February');
|
|
assert.equal(ev('monthiversary(30,59)'),false);
|
|
assert.equal(ev('monthiversary(30,89)'),true,'and on 31 March');
|
|
assert.equal(ev('monthiversary(30,30)'),false,'not on the day it starts');
|
|
assert.equal(ev('[30,31,58,59].map(monthIdx).join()'),'0,1,1,2');
|
|
// an old save, mid-month in 30-day months, keeps its intern budget month
|
|
ev("const s=JSON.parse(JSON.stringify(S));delete s.calV;s.day=95;s.ops.mon=3;migrate(s);window.__s=s");
|
|
assert.equal(ev('__s.ops.mon'),ev('monthIdx(95)'));assert.equal(ev('__s.calV'),1);
|
|
assert.equal(ev('S.calV'),1,'new games start on the calendar');
|
|
}finally{dom.window.close();}
|
|
});
|
|
test('#257 conferences fall on the 10th of their month',()=>{
|
|
const {ev,dom}=load();try{
|
|
ev("ACT.start({});S.day=0");
|
|
const c=ev("upcomingConfs(400).map(x=>dateStr(x.day))");
|
|
assert.ok(c.length>0);for(const x of c)assert.match(x,/ 10$/);
|
|
}finally{dom.window.close();}
|
|
});
|