Repository navigation
Expand file tree
/
Copy pathpostinstall.test.mjs
More file actions
5 lines (5 loc) · 2.18 KB
/
Copy pathpostinstall.test.mjs
File metadata and controls
5 lines (5 loc) · 2.18 KB
1
2
3
4
5
import {test} from 'node:test';import assert from 'node:assert/strict';import {mkdtemp,writeFile,readFile,rm,readdir} from 'node:fs/promises';import {tmpdir} from 'node:os';import {join} from 'node:path';import {execFileSync,spawnSync} from 'node:child_process';
const config=JSON.parse(await readFile('dist/client-patches.json','utf8'));
function fixture(s){return `var ${s.start.split('=')[0]}=()=>{return 'launcher sentinel'},${s.name}=()=>{return 'shade sentinel'}${s.boundary}{return 0};var stage={${s.root}]};class Handler{${s.method}return 0;}};${s.wheelPrefix.includes('const c=')?'const c=d=>{if(d.defaultPrevented)return;const p=d.deltaY;}':'const e=e=>{if(e.defaultPrevented)return;const n=e.deltaY;}'}`;}
test('packaged postinstall preserves other integrations and is repeatable',async()=>{const dir=await mkdtemp(join(tmpdir(),'deskthing-postinstall-'));try{for(const s of config.specs)await writeFile(join(dir,s.file),fixture(s));execFileSync(process.execPath,['dist/postinstall.mjs','--assets',dir]);const before=[];for(const s of config.specs){const text=await readFile(join(dir,s.file),'utf8');new Function(text);before.push(text);if(config.feature!=='launcher')assert.ok(text.includes('launcher sentinel'));if(config.feature!=='control')assert.ok(text.includes('shade sentinel'));}assert.ok((await readdir(dir)).some(x=>x.endsWith('.backup')));execFileSync(process.execPath,['dist/postinstall.mjs','--assets',dir]);for(let i=0;i<config.specs.length;i++)assert.equal(await readFile(join(dir,config.specs[i].file),'utf8'),before[i]);}finally{await rm(dir,{recursive:true,force:true});}});
test('unsupported second bundle causes no partial writes to the first bundle',async()=>{const dir=await mkdtemp(join(tmpdir(),'deskthing-unsupported-'));try{const original=fixture(config.specs[0]);await writeFile(join(dir,config.specs[0].file),original);await writeFile(join(dir,config.specs[1].file),'unsupported');const result=spawnSync(process.execPath,['dist/postinstall.mjs','--assets',dir]);assert.notEqual(result.status,0);assert.equal(await readFile(join(dir,config.specs[0].file),'utf8'),original);assert.ok(!(await readdir(dir)).some(x=>x.endsWith('.backup')));}finally{await rm(dir,{recursive:true,force:true});}});