6fd161d769
* Start of work on astroConfig.mode === 'server' * Add tests and more * adapter -> deploy in some places * Add fallback for `adapter` config * Update more tests * Update image tests * Fix clientAddress test * Updates based on PR review * Add a changeset * Update integrations tests + readme * Oops * Remove old option * Rename `mode` to `output` * Update Node adapter test * Update test * fred pass * fred pass * fred pass * fix test Co-authored-by: Fred K. Schott <fkschott@gmail.com>
34 lines
880 B
JavaScript
34 lines
880 B
JavaScript
import nodejs from '../dist/index.js';
|
|
import { loadFixture, createRequestAndResponse, toPromise } from './test-utils.js';
|
|
import { expect } from 'chai';
|
|
|
|
describe('API routes', () => {
|
|
/** @type {import('./test-utils').Fixture} */
|
|
let fixture;
|
|
|
|
before(async () => {
|
|
fixture = await loadFixture({
|
|
root: './fixtures/api-route/',
|
|
output: 'server',
|
|
adapter: nodejs(),
|
|
});
|
|
await fixture.build();
|
|
});
|
|
|
|
it('Can get the request body', async () => {
|
|
const { handler } = await import('./fixtures/api-route/dist/server/entry.mjs');
|
|
|
|
let { req, res, done } = createRequestAndResponse({
|
|
method: 'POST',
|
|
url: '/recipes',
|
|
});
|
|
|
|
handler(req, res);
|
|
req.send(JSON.stringify({ id: 2 }));
|
|
|
|
let [buffer] = await done;
|
|
let json = JSON.parse(buffer.toString('utf-8'));
|
|
expect(json.length).to.equal(1);
|
|
expect(json[0].name).to.equal('Broccoli Soup');
|
|
});
|
|
});
|