-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
4 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
packages/playground/legacy/__tests__/ssr/legacy-ssr.spec.ts
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,20 @@ | ||
import { isBuild } from '../../../testUtils' | ||
import { port } from './serve' | ||
|
||
const url = `http://localhost:${port}` | ||
|
||
if (isBuild) { | ||
test('should work', async () => { | ||
await page.goto(url) | ||
expect(await page.textContent('#app')).toMatch('Hello') | ||
}) | ||
|
||
test('import.meta.env.LEGACY', async () => { | ||
// SSR build is always modern | ||
expect(await page.textContent('#env')).toMatch('false') | ||
}) | ||
} else { | ||
// this test doesn't support serve mode | ||
// must contain at least one test | ||
test('should work', () => void 0) | ||
} |
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,52 @@ | ||
// @ts-check | ||
// this is automtically detected by scripts/jestPerTestSetup.ts and will replace | ||
// the default e2e test serve behavior | ||
const path = require('path') | ||
|
||
const port = (exports.port = 9527) | ||
|
||
/** | ||
* @param {string} root | ||
* @param {boolean} _isProd | ||
*/ | ||
exports.serve = async function serve(root, _isProd) { | ||
const { build } = require('vite') | ||
await build({ | ||
root, | ||
logLevel: 'silent', | ||
build: { | ||
target: 'esnext', | ||
ssr: 'entry-server.js', | ||
outDir: 'dist/server' | ||
} | ||
}) | ||
|
||
const express = require('express') | ||
const app = express() | ||
|
||
app.use('/', async (_req, res) => { | ||
const { render } = require(path.resolve( | ||
root, | ||
'./dist/server/entry-server.js' | ||
)) | ||
const html = await render() | ||
res.status(200).set({ 'Content-Type': 'text/html' }).end(html) | ||
}) | ||
|
||
return new Promise((resolve, reject) => { | ||
try { | ||
const server = app.listen(port, () => { | ||
resolve({ | ||
// for test teardown | ||
async close() { | ||
await new Promise((resolve) => { | ||
server.close(resolve) | ||
}) | ||
} | ||
}) | ||
}) | ||
} catch (e) { | ||
reject(e) | ||
} | ||
}) | ||
} |
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,7 @@ | ||
// This counts as 'server-side' rendering, yes? | ||
export async function render() { | ||
return /* html */ ` | ||
<div id="app">Hello</div> | ||
<div id="env">${import.meta.env.LEGACY}</div> | ||
` | ||
} |
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