diff options
Diffstat (limited to 'packages/astro/test/dynamic-endpoint-collision.test.js')
-rw-r--r-- | packages/astro/test/dynamic-endpoint-collision.test.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/packages/astro/test/dynamic-endpoint-collision.test.js b/packages/astro/test/dynamic-endpoint-collision.test.js new file mode 100644 index 000000000..e1f4b2f03 --- /dev/null +++ b/packages/astro/test/dynamic-endpoint-collision.test.js @@ -0,0 +1,54 @@ +import { expect } from 'chai'; +import { load as cheerioLoad } from 'cheerio'; +import { loadFixture, silentLogging } from './test-utils.js'; + +describe('Dynamic endpoint collision', () => { + describe('build', () => { + let fixture; + let errorMsg; + before(async () => { + fixture = await loadFixture({ + root: './fixtures/dynamic-endpoint-collision/', + }); + try { + await fixture.build(); + } catch (error) { + errorMsg = error; + } + }); + + it('throw error when dynamic endpoint has path collision', async () => { + expect(errorMsg.errorCode).to.eq(3026); + }); + }); + + describe('dev', () => { + let fixture; + let devServer; + + before(async () => { + fixture = await loadFixture({ + root: './fixtures/dynamic-endpoint-collision/', + }); + + devServer = await fixture.startDevServer({ + logging: silentLogging, + }); + }); + + after(async () => { + await devServer.stop(); + }); + + it('throw error when dynamic endpoint has path collision', async () => { + const html = await fixture.fetch('/api/catch').then((res) => res.text()); + const $ = cheerioLoad(html); + expect($('title').text()).to.equal('PrerenderDynamicEndpointPathCollide'); + }); + + it("don't throw error when dynamic endpoint doesn't load the colliding path", async () => { + const res = await fixture.fetch('/api/catch/one').then((r) => r.text()); + expect(res).to.equal('{"slug":"one"}'); + }); + }); +}); |