-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix support for trailing
/
in cloudflare-pages
- Loading branch information
Showing
6 changed files
with
40 additions
and
31 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,12 +1,13 @@ | ||
{ | ||
"name": "nexered", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Next.js config redirect export for cloudflare", | ||
"repository": "github:varanauskas/nexered", | ||
"author": "Tadas Varanauskas <[email protected]>", | ||
"license": "MIT", | ||
"private": false, | ||
"scripts": { | ||
"test": "jest", | ||
"build": "tsc", | ||
"cleanup": "rm -rf ./dist", | ||
"prepack": "npm run cleanup && npm run build" | ||
|
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 |
---|---|---|
@@ -1,41 +1,48 @@ | ||
import { existsSync } from "fs"; | ||
import { readFile } from "fs/promises"; | ||
import { rm } from "fs/promises"; | ||
import { readFile, rm } from "fs/promises"; | ||
import { mkdtemp } from "fs/promises"; | ||
import { tmpdir } from "os"; | ||
import { join } from "path"; | ||
import { main } from "../../src"; | ||
|
||
const EXPECTED = `/base/about /base 308 | ||
/base/about/ /base 308 | ||
/base/old-blog/* /base/blog/:splat 307 | ||
/base/old-blog/:slug /base/news/:slug 308 | ||
/base/old-blog/:slug/ /base/news/:slug 308 | ||
/base/blog/* /base/news/:splat 308 | ||
/base/with-basePath /base/another 307 | ||
/base/with-basePath/ /base/another 307 | ||
/without-basePath /another 307 | ||
/base/custom-status-code /base/status-code-303 303`; | ||
/without-basePath/ /another 307 | ||
/base/custom-status-code /base/status-code-303 303 | ||
/base/custom-status-code/ /base/status-code-303 303`; | ||
|
||
describe("cloudflare provider", () => { | ||
let __NEXT_TEST_MODE: string | undefined; | ||
let outputDir: string; | ||
|
||
beforeAll(() => { | ||
__NEXT_TEST_MODE = process.env.__NEXT_TEST_MODE; | ||
process.env.__NEXT_TEST_MODE = 'jest'; | ||
}); | ||
|
||
afterAll(() => process.env.__NEXT_TEST_MODE = __NEXT_TEST_MODE); | ||
beforeEach(async () => { outputDir = await mkdtemp(join(tmpdir(), 'nexered-cloudflare-pages-test-')) }); | ||
|
||
afterEach(() => rm(outputDir, { recursive: true, force: true })); | ||
|
||
afterAll(() => { process.env.__NEXT_TEST_MODE = __NEXT_TEST_MODE; }); | ||
|
||
it("correctly populates _redirects file with redirects", async () => { | ||
const nextDir = join(__dirname, '/with-redirects'); | ||
const outputDir = join(nextDir, '/out'); | ||
await main('cloudflare-pages', nextDir, outputDir); | ||
const data = await readFile(join(outputDir, '/_redirects'), "ascii"); | ||
expect(data).toEqual(EXPECTED); | ||
await rm(outputDir, { recursive: true, force: true }); | ||
}); | ||
|
||
it("does not create redirects if not necessary", async () => { | ||
const nextDir = join(__dirname, '/empty'); | ||
const outputDir = join(nextDir, '/out'); | ||
await main('cloudflare-pages', nextDir, outputDir); | ||
expect(await existsSync(join(outputDir, '/_redirects'))).toBe(false); | ||
await rm(outputDir, { recursive: true, force: true }); | ||
expect(existsSync(join(outputDir, '/_redirects'))).toBe(false); | ||
}); | ||
}); |