-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
34 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,47 @@ | ||
import { expect } from 'chai'; | ||
import * as cheerio from 'cheerio'; | ||
import { loadFixture } from './test-utils.js'; | ||
import * as fs from 'fs'; | ||
|
||
import { FormData, File } from 'node-fetch' | ||
import { FormData, File } from 'node-fetch'; | ||
|
||
describe('API routes', () => { | ||
describe('Development - SSR', () => { | ||
/** @type {import('./test-utils').Fixture} */ | ||
let fixture; | ||
/** @type {import('./test-utils').DevServer} */ | ||
let devServer; | ||
before(async () => { | ||
fixture = await loadFixture({ | ||
output: 'server', | ||
root: './fixtures/api-routes/' | ||
}); | ||
devServer = await fixture.startDevServer(); | ||
}); | ||
|
||
after(async () => { | ||
await devServer.stop(); | ||
}); | ||
/** @type {import('./test-utils').Fixture} */ | ||
let fixture; | ||
|
||
it('Can be passed binary data from multipart formdata', async () => { | ||
const formData = new FormData(); | ||
const raw = await fs.promises.readFile(new URL('./fixtures/api-routes/src/images/penguin.jpg', import.meta.url)); | ||
const file = new File([raw], 'penguin.jpg', { type: 'text/jpg' }); | ||
formData.set('file', file, 'penguin.jpg'); | ||
before(async () => { | ||
fixture = await loadFixture({ root: './fixtures/api-routes/' }); | ||
await fixture.build(); | ||
}); | ||
|
||
const res = await fixture.fetch('/binary', { | ||
method: 'POST', | ||
body: formData | ||
describe('Deprecated API', () => { | ||
it('two argument supported', async () => { | ||
const one = JSON.parse(await fixture.readFile('/old-api/twoarg/one.json')); | ||
expect(one).to.deep.equal({ | ||
param: 'one', | ||
pathname: '/old-api/twoarg/one.json', | ||
}); | ||
const two = JSON.parse(await fixture.readFile('/old-api/twoarg/two.json')); | ||
expect(two).to.deep.equal({ | ||
param: 'two', | ||
pathname: '/old-api/twoarg/two.json', | ||
}); | ||
|
||
expect(res.status).to.equal(200); | ||
}); | ||
}); | ||
|
||
describe('Build - SSG', () => { | ||
/** @type {import('./test-utils').Fixture} */ | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ root: './fixtures/api-routes/' }); | ||
await fixture.build(); | ||
}); | ||
|
||
describe('Deprecated API', () => { | ||
it('two argument supported', async () => { | ||
const one = JSON.parse(await fixture.readFile('/old-api/twoarg/one.json')); | ||
expect(one).to.deep.equal({ | ||
param: 'one', | ||
pathname: '/old-api/twoarg/one.json', | ||
}); | ||
const two = JSON.parse(await fixture.readFile('/old-api/twoarg/two.json')); | ||
expect(two).to.deep.equal({ | ||
param: 'two', | ||
pathname: '/old-api/twoarg/two.json', | ||
}); | ||
}); | ||
|
||
it('param first argument is supported', async () => { | ||
const one = JSON.parse(await fixture.readFile('/old-api/onearg/one.json')); | ||
expect(one).to.deep.equal({ | ||
param: 'one', | ||
}); | ||
it('param first argument is supported', async () => { | ||
const one = JSON.parse(await fixture.readFile('/old-api/onearg/one.json')); | ||
expect(one).to.deep.equal({ | ||
param: 'one', | ||
}); | ||
}); | ||
|
||
describe('1.0 API', () => { | ||
it('Receives a context argument', async () => { | ||
const one = JSON.parse(await fixture.readFile('/context/data/one.json')); | ||
expect(one).to.deep.equal({ | ||
param: 'one', | ||
pathname: '/context/data/one.json', | ||
}); | ||
}); | ||
|
||
describe('1.0 API', () => { | ||
it('Receives a context argument', async () => { | ||
const one = JSON.parse(await fixture.readFile('/context/data/one.json')); | ||
expect(one).to.deep.equal({ | ||
param: 'one', | ||
pathname: '/context/data/one.json', | ||
}); | ||
}); | ||
}) | ||
}); | ||
}); |
Binary file not shown.
32 changes: 0 additions & 32 deletions
32
packages/astro/test/fixtures/api-routes/src/pages/binary.js
This file was deleted.
Oops, something went wrong.
19 changes: 0 additions & 19 deletions
19
packages/astro/test/fixtures/api-routes/src/pages/index.astro
This file was deleted.
Oops, something went wrong.