Files
search-with-chatgpt-powered…/test/open-chat.test.js
T

15 lines
822 B
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
const { openChat } = await import('../background/open-chat.js').catch(()=>({}));
test('window failure falls back to tab, background mode stays inactive, final failure rejects', async()=>{
assert.equal(typeof openChat,'function');
const opened=[];
const browser={windows:{create:async()=>{throw Error('window failed');}},tabs:{create:async v=>opened.push(v)}};
await openChat(browser,'https://chatgpt.com/','new-window');
assert.deepEqual(opened,[{url:'https://chatgpt.com/',active:true}]);
await openChat(browser,'https://chatgpt.com/','background-tab');
assert.equal(opened[1].active,false);
browser.tabs.create=async()=>{throw Error('tab failed');};
await assert.rejects(openChat(browser,'https://chatgpt.com/','new-window'));
});