29 lines
1.8 KiB
JavaScript
29 lines
1.8 KiB
JavaScript
import { fixture } from '../fixture.mjs';
|
|
import { browser } from '../browser.mjs';
|
|
|
|
// This isolated slice has no shell mount yet. Attach the actual feature to the local Console fixture.
|
|
export async function filesFixture(t) {
|
|
const f = await fixture(); t.after(() => f.close());
|
|
const b = await browser({ machine: false }); t.after(() => b.close());
|
|
const errors = [];
|
|
b.on('Runtime.exceptionThrown', event => errors.push(event.exceptionDetails.text));
|
|
await b.call('Fetch.enable', { patterns: [{ urlPattern: '*' }] });
|
|
b.on('Fetch.requestPaused', e => {
|
|
const same = e.request.url.startsWith(f.base + '/') || e.request.url === 'about:blank';
|
|
b.call(same ? 'Fetch.continueRequest' : 'Fetch.failRequest', same ? { requestId: e.requestId } : { requestId: e.requestId, errorReason: 'BlockedByClient' }).catch(error => errors.push(error.message));
|
|
});
|
|
await b.call('Page.addScriptToEvaluateOnNewDocument', { source: `(() => {
|
|
const real = window.fetch.bind(window);
|
|
window.fixtureState = null; window.fixtureWorkspace = null;
|
|
window.fetch = async (url, init) => {
|
|
const path = String(url);
|
|
if (path === '/api/config') return new Response(JSON.stringify({requests:true}), {status: 200, headers: {'content-type':'application/json'}});
|
|
if (path === '/api/requests/request-1') return new Response(JSON.stringify(window.fixtureState), {status: 200, headers: {'content-type':'application/json'}});
|
|
if (path === '/api/requests/request-1/workspace') return window.fixtureWorkspace === null ? new Response('{}', {status: 503}) : new Response(JSON.stringify(window.fixtureWorkspace), {status: 200, headers: {'content-type':'application/json'}});
|
|
if (path.startsWith('/api/')) return new Response('{}', {status: 503});
|
|
return real(url, init);
|
|
};
|
|
})();` });
|
|
return { f, b, errors };
|
|
}
|