MCPcopy Index your code
hub / github.com/Sandpack/nodebox-runtime / runTestServer

Function runTestServer

tests/setup/runTestServer.ts:12–64  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10}
11
12export async function runTestServer(): Promise<TestServerReturnType> {
13 const serverReady = new DeferredPromise<TestServerReturnType>();
14 const app = setupApp();
15 app.log.level = 'error';
16
17 app.register(fastifyStatic, {
18 root: path.join(__dirname, 'server'),
19 index: ['index.html'],
20 decorateReply: false,
21 });
22
23 // Serve the Node emulator build.
24 app.register(fastifyStatic, {
25 prefix: '/deps/nodebox/',
26 root: path.join(__dirname, '../..', 'packages/nodebox/build'),
27 decorateReply: false,
28 });
29
30 // Serve project packs to be available in the test server runtime.
31 app.register(fastifyStatic, {
32 prefix: '/projects/',
33 root: path.join(__dirname, 'projects'),
34 decorateReply: false,
35 setHeaders(res, filePath) {
36 const parsedPath = path.parse(filePath);
37
38 if (parsedPath.ext === '.gz') {
39 res.setHeader('Content-Encoding', 'gzip');
40 } else if (parsedPath.ext === '.br') {
41 res.setHeader('Content-Encoding', 'br');
42 }
43 },
44 });
45
46 // Serve Msgpack to unpack project files on runtime.
47 app.register(fastifyStatic, {
48 prefix: '/deps/msgpack/',
49 root: path.join(__dirname, '../..', 'node_modules/@msgpack/msgpack'),
50 decorateReply: false,
51 });
52
53 app.listen({ port: undefined }, (error, address) => {
54 if (error) {
55 app.log.error(error);
56 serverReady.reject(error);
57 return;
58 }
59
60 serverReady.resolve({ app, address });
61 });
62
63 return serverReady;
64}

Callers 15

runTestServerFunction · 0.90
fastify.test.tsFile · 0.50
vite.start.test.tsFile · 0.50
next.start.test.tsFile · 0.50
express.test.tsFile · 0.50
multiple.test.tsFile · 0.50

Calls 2

setupAppFunction · 0.90
listenMethod · 0.80

Tested by

no test coverage detected