-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes custom 404 pages in astro dev (#3331)
* Fixing pathname matching for custom 404 pages * fixes custom 404 routes in dev * refactor: removing node path dependency * refactor: using core's path utils
- Loading branch information
Tony Sullivan
authored
May 10, 2022
1 parent
d04928e
commit e22f736
Showing
8 changed files
with
89 additions
and
1 deletion.
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 | ||
--- | ||
|
||
Fixes an issue preventing custom 404 pages in dev |
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,41 @@ | ||
import { expect } from 'chai'; | ||
import * as cheerio from 'cheerio'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
describe('Custom 404', () => { | ||
let fixture; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/custom-404/', | ||
}); | ||
}); | ||
|
||
describe('dev', () => { | ||
let devServer; | ||
let $; | ||
|
||
before(async () => { | ||
devServer = await fixture.startDevServer(); | ||
}); | ||
|
||
after(async () => { | ||
await devServer.stop(); | ||
}); | ||
|
||
it('renders /', async () => { | ||
const html = await fixture.fetch('/').then((res) => res.text()); | ||
$ = cheerio.load(html); | ||
|
||
expect($('h1').text()).to.equal('Home'); | ||
}); | ||
|
||
it('renders 404 for /a', async () => { | ||
const html = await fixture.fetch('/a').then((res) => res.text()); | ||
$ = cheerio.load(html); | ||
|
||
expect($('h1').text()).to.equal('Page not found'); | ||
expect($('p').text()).to.equal('/a/'); | ||
}) | ||
}); | ||
}); |
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,4 @@ | ||
import { defineConfig } from 'astro/config'; | ||
|
||
// https://astro.build/config | ||
export default defineConfig({}); |
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,8 @@ | ||
{ | ||
"name": "@test/custom-404", | ||
"version": "0.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"astro": "workspace:*" | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/astro/test/fixtures/custom-404/src/pages/404.astro
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,12 @@ | ||
--- | ||
--- | ||
|
||
<html lang="en"> | ||
<head> | ||
<title>Not Found - Custom 404</title> | ||
</head> | ||
<body> | ||
<h1>Page not found</h1> | ||
<p>{Astro.canonicalURL.pathname}</p> | ||
</body> | ||
</html> |
11 changes: 11 additions & 0 deletions
11
packages/astro/test/fixtures/custom-404/src/pages/index.astro
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,11 @@ | ||
--- | ||
--- | ||
|
||
<html lang="en"> | ||
<head> | ||
<title>Custom 404</title> | ||
</head> | ||
<body> | ||
<h1>Home</h1> | ||
</body> | ||
</html> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.