All files / nodejs-test-workers/src/workers mock-fetch.ts

0% Statements 0/12
0% Branches 0/2
0% Functions 0/3
0% Lines 0/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38                                                                           
import '@metamask/kernel-shims/endoify-node';
import { Logger } from '@metamask/logger';
import type { VatId } from '@metamask/ocap-kernel';
import { makeNodeJsVatSupervisor } from '@ocap/nodejs';
 
const LOG_TAG = 'nodejs-test-vat-worker';
 
let logger = new Logger(LOG_TAG);
 
/* eslint-disable n/no-unsupported-features/node-builtins */
 
main().catch((reason) => logger.error('main exited with error', reason));
 
/**
 * The main function for the vat worker.
 */
async function main(): Promise<void> {
  // eslint-disable-next-line n/no-process-env
  const vatId = process.env.NODE_VAT_ID as VatId;
  if (!vatId) {
    throw new Error('no vatId set for env variable NODE_VAT_ID');
  }
  const { logger: streamLogger } = await makeNodeJsVatSupervisor(
    vatId,
    LOG_TAG,
    {
      fetch: {
        fromFetch: async (input: string | URL | Request) => {
          logger.debug('fetch', input);
          return new Response('Hello, world!');
        },
      },
    },
  );
  logger = streamLogger;
  logger.debug('vat-worker main');
}