-
-
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.
test: Add simple tests for output files & local fetch patch
- Loading branch information
1 parent
c823a99
commit 0bf98c5
Showing
9 changed files
with
80 additions
and
3 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
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,24 @@ | ||
import { test } from 'uvu'; | ||
import * as assert from 'uvu/assert'; | ||
|
||
import { setupTest, teardownTest, loadFixture, viteBuild } from './lib/lifecycle.js'; | ||
import { getOutputFile } from './lib/utils.js'; | ||
|
||
let env; | ||
test.before.each(async () => { | ||
env = await setupTest(); | ||
}); | ||
|
||
test.after.each(async () => { | ||
await teardownTest(env); | ||
}); | ||
|
||
test('Should support isomorphic fetch', async () => { | ||
await loadFixture('features/local-fetch', env); | ||
await viteBuild(env.tmp.path); | ||
|
||
const prerenderedHtml = await getOutputFile(env.tmp.path, 'index.html'); | ||
assert.match(prerenderedHtml, '<body>Local fetch works'); | ||
}); | ||
|
||
test.run(); |
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,9 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
</head> | ||
<body> | ||
<script prerender type="module" src="/src/index.js"></script> | ||
</body> | ||
</html> |
1 change: 1 addition & 0 deletions
1
tests/fixtures/features/local-fetch/public/local-fetch-test.txt
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 @@ | ||
Local fetch works |
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 @@ | ||
export async function prerender() { | ||
const res = await fetch('/local-fetch-test.txt') | ||
return await res.text(); | ||
} |
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,6 @@ | ||
import { defineConfig } from 'vite'; | ||
import { vitePrerenderPlugin } from 'vite-prerender-plugin'; | ||
|
||
export default defineConfig({ | ||
plugins: [vitePrerenderPlugin()], | ||
}); |
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 +1,3 @@ | ||
export async function prerender() {} | ||
export async function prerender() { | ||
return `<h1>Simple Test Result</h1>`; | ||
} |
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,32 @@ | ||
import { test } from 'uvu'; | ||
import * as assert from 'uvu/assert'; | ||
import path from 'node:path'; | ||
import { promises as fs } from 'node:fs'; | ||
|
||
import { setupTest, teardownTest, loadFixture, viteBuild } from './lib/lifecycle.js'; | ||
import { getOutputFile } from './lib/utils.js'; | ||
|
||
let env; | ||
test.before.each(async () => { | ||
env = await setupTest(); | ||
}); | ||
|
||
test.after.each(async () => { | ||
await teardownTest(env); | ||
}); | ||
|
||
test('Should prerender and output correct file structure', async () => { | ||
await loadFixture('simple', env); | ||
await viteBuild(env.tmp.path); | ||
|
||
const prerenderedHtml = await getOutputFile(env.tmp.path, 'index.html'); | ||
assert.match(prerenderedHtml, '<h1>Simple Test Result</h1>'); | ||
|
||
const outDir = path.join(env.tmp.path, 'dist'); | ||
const outDirAssets = path.join(outDir, 'assets'); | ||
|
||
assert.equal((await fs.readdir(outDir)).length, 2); | ||
assert.equal((await fs.readdir(outDirAssets)).length, 1); | ||
}); | ||
|
||
test.run(); |