MCPcopy
hub / github.com/sindresorhus/got / exec

Function exec

test/helpers/with-server.ts:23–79  ·  view source on GitHub ↗
(t, run)

Source from the content-addressed store, hash-verified

21
22const generateHook = ({install, options: testServerOptions}: {install?: boolean; options?: HttpServerOptions}): Macro<[RunTestWithServer]> => ({
23 async exec(t, run) {
24 // Re-enable body parsing to investigate https://github.com/sindresorhus/got/issues/1186
25 const server = await createHttpTestServer(is.plainObject(testServerOptions)
26 ? testServerOptions
27 : {
28 bodyParser: {
29 type: () => false,
30 } as any,
31 });
32
33 const clock = install
34 ? FakeTimers.install({
35 toFake: ['setTimeout', 'clearTimeout', 'setInterval', 'clearInterval'],
36 shouldAdvanceTime: true,
37 advanceTimeDelta: 1,
38 })
39 : FakeTimers.createClock() as GlobalClock;
40
41 const context: Record<string, unknown> = {};
42 Object.defineProperty(context, 'avaTest', {
43 value: t.title,
44 enumerable: false,
45 writable: true,
46 configurable: true,
47 });
48
49 const options: ExtendOptions = {
50 context,
51 handlers: [
52 (options, next) => {
53 const result = next(options);
54
55 clock.tick(0);
56
57 // @ts-expect-error FIXME: Incompatible union type signatures
58 result.on('response', () => {
59 clock.tick(0);
60 });
61
62 return result;
63 },
64 ],
65 };
66
67 const preparedGot = got.extend({prefixUrl: server.url, ...options});
68
69 try {
70 await run(t, server, preparedGot, clock);
71 } finally {
72 await server.close();
73 }
74
75 if (install) {
76 // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
77 (clock as InstalledClock).uninstall();
78 }
79 },
80});

Callers

nothing calls this directly

Calls 3

createHttpTestServerFunction · 0.85
nextFunction · 0.85
createHttpsTestServerFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…