18 lines
1.1 KiB
JavaScript
18 lines
1.1 KiB
JavaScript
const {test}=require('node:test');
|
|
const assert=require('node:assert/strict');
|
|
const fs=require('node:fs/promises'),os=require('node:os'),path=require('node:path');
|
|
const {Engine}=require('../src/main/engine.cjs');
|
|
test('cancelling a worker stops its process tree and cleans unpublished output',async()=>{
|
|
const root=path.resolve(__dirname,'..'),folder=await fs.mkdtemp(path.join(os.tmpdir(),'filebow-cancel-test-'));
|
|
try{
|
|
const image=path.join(folder,'image.png');await fs.copyFile(path.join(root,'assets/icon.png'),image);
|
|
const engine=new Engine(root,true),controller=new AbortController();
|
|
const timer=setTimeout(()=>controller.abort(),450);
|
|
try{await assert.rejects(engine.run({op:'convert',files:Array(500).fill(image),target:'avif'},()=>{},controller.signal),/Cancelled/);}
|
|
finally{clearTimeout(timer);engine.stop();}
|
|
assert.equal(engine.children.size,0);
|
|
assert.ok(!(await fs.readdir(folder)).some(name=>name.startsWith('.filebow-')));
|
|
assert.ok((await fs.stat(image)).size>0);
|
|
}finally{await fs.rm(folder,{recursive:true,force:true});}
|
|
});
|