const fs=require('node:fs');const path=require('node:path');const vm=require('node:vm');const assert=require('node:assert/strict'); const root=path.resolve(__dirname,'..'); for(const file of fs.readdirSync(path.join(root,'dist')).filter(name=>name.endsWith('.js')))new vm.Script(fs.readFileSync(path.join(root,'dist',file),'utf8'),{filename:file}); function setup(saved){ const memory=new Map(saved?[['mangabom.billing',JSON.stringify(saved)]]:[]); const el=(dataset={})=>({dataset,textContent:'',events:{},attributes:{},setAttribute(k,v){this.attributes[k]=v},addEventListener(k,fn){this.events[k]=fn}}); const choices=[el({billing:'month'}),el({billing:'year'})],prices=[el({planPrice:'99'}),el({planPrice:'399'})],periods=[el(),el()],plans=[el({plan:'MANGABOM+',monthly:'99'}),el({plan:'Коллекционер',monthly:'399'})],note=el(),status=el(); const document={querySelectorAll:s=>({'[data-billing]':choices,'[data-plan-price]':prices,'[data-plan-period]':periods,'[data-plan]':plans}[s]||[]),querySelector:s=>({'#billing-note':note,'#plan-status':status}[s])}; vm.runInNewContext(fs.readFileSync(path.join(root,'dist/support.js'),'utf8'),{document,Intl,localStorage:{getItem:k=>memory.get(k)||null,setItem:(k,v)=>memory.set(k,v)}}); return{choices,prices,periods,plans,note,status,memory}; } let app=setup();assert.deepEqual(app.prices.map(x=>x.textContent),['99','399']);assert.equal(app.choices[0].attributes['aria-pressed'],'true'); app.choices[1].events.click();assert.deepEqual(app.prices.map(x=>x.textContent.replace(/\s/g,'')),['986,04','3974,04']);assert.equal(app.periods[0].textContent,'в год');assert.equal(JSON.parse(app.memory.get('mangabom.billing')),'year'); app.plans[0].events.click();assert.match(app.status.textContent,/986,04/);assert.match(app.status.textContent,/недоступно/); app.choices[0].events.click();assert.deepEqual(app.prices.map(x=>x.textContent),['99','399']);assert.equal(app.status.textContent,''); app=setup('year');assert.equal(app.choices[1].attributes['aria-pressed'],'true');assert.equal(app.prices[0].textContent,'986,04'); console.log('PASS: exact 17% annual discount, shared monthly/yearly switch, saved choice, honest plan preview and all JavaScript syntax.');