-
-
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.
Properly support trailingSlash: never with a base (#5358)
* Properly support trailingSlash: never with a base * adding a changeset * Pass through the base * only mess with pathname when trailingSlash === 'never' * maybe fixes stuff * Update based on review notes
- Loading branch information
Showing
10 changed files
with
179 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Properly support trailingSlash: never with a base |
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
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
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
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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { expect } from 'chai'; | ||
|
||
import { runInContainer } from '../../../dist/core/dev/index.js'; | ||
import { createFs, createRequestAndResponse } from '../test-utils.js'; | ||
|
||
const root = new URL('../../fixtures/alias/', import.meta.url); | ||
|
||
describe('base configuration', () => { | ||
describe('with trailingSlash: "never"', () => { | ||
describe('index route', () => { | ||
it('Requests that include a trailing slash 404', async () => { | ||
const fs = createFs({ | ||
'/src/pages/index.astro': `<h1>testing</h1>`, | ||
}, root); | ||
|
||
await runInContainer({ | ||
fs, | ||
root, | ||
userConfig: { | ||
base: '/docs', | ||
trailingSlash: 'never', | ||
}, | ||
}, async (container) => { | ||
const { req, res, done } = createRequestAndResponse({ | ||
method: 'GET', | ||
url: '/docs/', | ||
}); | ||
container.handle(req, res); | ||
await done; | ||
expect(res.statusCode).to.equal(404); | ||
}); | ||
}); | ||
|
||
it('Requests that exclude a trailing slash 200', async () => { | ||
const fs = createFs({ | ||
'/src/pages/index.astro': `<h1>testing</h1>`, | ||
}, root); | ||
|
||
await runInContainer({ | ||
fs, | ||
root, | ||
userConfig: { | ||
base: '/docs', | ||
trailingSlash: 'never', | ||
}, | ||
}, async (container) => { | ||
const { req, res, done } = createRequestAndResponse({ | ||
method: 'GET', | ||
url: '/docs', | ||
}); | ||
container.handle(req, res); | ||
await done; | ||
expect(res.statusCode).to.equal(200); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('sub route', () => { | ||
it('Requests that include a trailing slash 404', async () => { | ||
const fs = createFs({ | ||
'/src/pages/sub/index.astro': `<h1>testing</h1>`, | ||
}, root); | ||
|
||
await runInContainer({ | ||
fs, | ||
root, | ||
userConfig: { | ||
base: '/docs', | ||
trailingSlash: 'never', | ||
}, | ||
}, async (container) => { | ||
const { req, res, done } = createRequestAndResponse({ | ||
method: 'GET', | ||
url: '/docs/sub/', | ||
}); | ||
container.handle(req, res); | ||
await done; | ||
expect(res.statusCode).to.equal(404); | ||
}); | ||
}); | ||
|
||
it('Requests that exclude a trailing slash 200', async () => { | ||
const fs = createFs({ | ||
'/src/pages/sub/index.astro': `<h1>testing</h1>`, | ||
}, root); | ||
|
||
await runInContainer({ | ||
fs, | ||
root, | ||
userConfig: { | ||
base: '/docs', | ||
trailingSlash: 'never', | ||
}, | ||
}, async (container) => { | ||
const { req, res, done } = createRequestAndResponse({ | ||
method: 'GET', | ||
url: '/docs/sub', | ||
}); | ||
container.handle(req, res); | ||
await done; | ||
expect(res.statusCode).to.equal(200); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { expect } from 'chai'; | ||
|
||
import { createFs } from '../test-utils.js'; | ||
import { createRouteManifest } from '../../../dist/core/routing/manifest/create.js'; | ||
import { createDefaultDevSettings } from '../../../dist/core/config/index.js'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
const root = new URL('../../fixtures/alias/', import.meta.url); | ||
|
||
describe('routing - createRouteManifest', () => { | ||
it('using trailingSlash: "never" does not match the index route when it contains a trailing slash', async () => { | ||
const fs = createFs({ | ||
'/src/pages/index.astro': `<h1>test</h1>`, | ||
}, root); | ||
const settings = await createDefaultDevSettings({ | ||
base: '/search', | ||
trailingSlash: 'never' | ||
}, root); | ||
const manifest = createRouteManifest({ | ||
cwd: fileURLToPath(root), | ||
settings, | ||
fsMod: fs | ||
}); | ||
const [{ pattern }] = manifest.routes; | ||
expect(pattern.test('')).to.equal(true); | ||
expect(pattern.test('/')).to.equal(false); | ||
}); | ||
}); |
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