Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
laptou committed Jul 15, 2022
1 parent a6db24e commit 09caf6e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export interface AstroGlobal extends AstroGlobalPartial {

/**
* Object provided by the server (**SSR Only**).
*
*
* [Astro reference](https://docs.astro.build/en/guides/server-side-rendering/#astrocontext)
*/
context: any;
Expand Down
74 changes: 37 additions & 37 deletions packages/integrations/node/test/context.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,50 @@ import { exec } from 'child_process';
import { createServer, Server } from 'http';

function buildFixture(path) {
const cwd = new URL(path, import.meta.url).pathname;
return new Promise((res, rej) => {
exec('pnpm astro build', { cwd }, (err) => {
if (err) {
rej(err);
} else {
res();
}
});
});
const cwd = new URL(path, import.meta.url).pathname;
return new Promise((res, rej) => {
exec('pnpm astro build', { cwd }, (err) => {
if (err) {
rej(err);
} else {
res();
}
});
});
}

async function loadFixture(path) {
const base = new URL(path, import.meta.url);
const entrypoint = new URL('dist/server/entry.mjs', base + '/');
const { handler } = await import(entrypoint.pathname);
return handler;
const base = new URL(path, import.meta.url);
const entrypoint = new URL('dist/server/entry.mjs', base + '/');
const { handler } = await import(entrypoint.pathname);
return handler;
}

describe('SSR context', () => {
let handler;
/** @type {Server} */
let server;
let handler;
/** @type {Server} */
let server;

before(async () => {
await buildFixture('./fixtures/context');
handler = await loadFixture('./fixtures/context');
server = createServer((req, res) => {
handler(req, res, { info: 'peek-a-boo' });
});
await new Promise(res => server.listen({ port: 8087 }, res));
});
before(async () => {
await buildFixture('./fixtures/context');
handler = await loadFixture('./fixtures/context');
server = createServer((req, res) => {
handler(req, res, { info: 'peek-a-boo' });
});
await new Promise((res) => server.listen({ port: 8087 }, res));
});

it('should contain information from context', async () => {
const response = await fetch('http://localhost:8087/');
const body = await response.text();
expect(body).to.contain('peek-a-boo');
});
it('should contain information from context', async () => {
const response = await fetch('http://localhost:8087/');
const body = await response.text();
expect(body).to.contain('peek-a-boo');
});

after((done) => {
if (server) {
server.close(done);
} else {
done();
}
});
after((done) => {
if (server) {
server.close(done);
} else {
done();
}
});
});

0 comments on commit 09caf6e

Please sign in to comment.