// Full desktop startup test; uses a temporary copy and disables collection/publication. const fs=require('fs'),path=require('path'),os=require('os'),{spawn}=require('child_process'); const root=path.resolve(__dirname,'..'); const dir=fs.mkdtempSync(path.join(os.tmpdir(),'carpincho-startup-')); fs.cpSync(path.join(root,'src'),dir,{recursive:true,filter:p=>!p.includes('/node_modules')&&!p.includes('/logs')&&!p.endsWith('/ConfiguracionGeneral.js')}); fs.symlinkSync(path.join(root,'src/node_modules'),path.join(dir,'node_modules'),'dir'); fs.mkdirSync(path.join(dir,'logs')); for(const f of ['debug.log','TanquePendientes.log','registro_diario.log']) fs.writeFileSync(path.join(dir,'logs',f),f==='debug.log'?'':'[]'); const conf=require(path.join(root,'test/fixtures/configuracion.cjs'))();conf.ConfPublicador=[]; fs.writeFileSync(path.join(dir,'conf/ConfiguracionGeneral.js'),'module.exports='+JSON.stringify(conf)); const probe=``; const html=path.join(dir,'gui/index.html');fs.writeFileSync(html,fs.readFileSync(html,'utf8').replace('',''+probe)); const pkgPath=path.join(dir,'package.json');let pkg=JSON.parse(fs.readFileSync(pkgPath));pkg['chromium-args']+=' --enable-logging=stderr';fs.writeFileSync(pkgPath,JSON.stringify(pkg)); const nw=process.argv[2]||process.env.NW_BINARY||'nw'; const child=spawn(nw,[dir,'--user-data-dir='+path.join(dir,'profile')],{cwd:dir,stdio:['ignore','ignore','pipe']});let log='';child.stderr.on('data',d=>log+=d);const timer=setTimeout(()=>child.kill(),20000); child.on('error',error=>{clearTimeout(timer);console.error(error.message);process.exitCode=1;}); child.on('exit',()=>{clearTimeout(timer);fs.writeFileSync(path.join(dir,'stderr.log'),log);console.log(dir);if(fs.existsSync(path.join(dir,'result.json'))) {const result=JSON.parse(fs.readFileSync(path.join(dir,'result.json'),'utf8'));console.log(result);if(result.errors.length)process.exitCode=1;}else {console.log(log.slice(-4500));process.exitCode=1;}});