forked from vitejs/vite
-
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.
- Loading branch information
Showing
9 changed files
with
3,281 additions
and
24 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 |
---|---|---|
|
@@ -4,3 +4,4 @@ dist | |
TODOs.md | ||
playground | ||
*.log | ||
test/temp |
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,3 @@ | ||
<template> | ||
<div class="child">This is child</div> | ||
</template> |
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,17 @@ | ||
<template> | ||
<button @click="count++">{{ count }}</button> | ||
<Child/> | ||
</template> | ||
|
||
<script> | ||
import Child from './Child.vue' | ||
export default { | ||
components: { Child }, | ||
setup() { | ||
return { | ||
count: 0 | ||
} | ||
} | ||
} | ||
</script> |
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,2 @@ | ||
<div id="app"></div> | ||
<script type="module" src="/main.js"></script> |
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 { createApp } from 'vue' | ||
import Comp from './Comp.vue' | ||
|
||
createApp(Comp).mount('#app') |
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,78 @@ | ||
const fs = require('fs').promises | ||
const path = require('path') | ||
const execa = require('execa') | ||
const puppeteer = require('puppeteer') | ||
|
||
const timeout = (n) => new Promise((r) => setTimeout(r, n)) | ||
|
||
const fixtureDir = path.join(__dirname, 'fixtures') | ||
const tempDir = path.join(__dirname, 'temp') | ||
let server | ||
let browser | ||
|
||
jest.setTimeout(100000) | ||
|
||
beforeAll(async () => { | ||
await fs.rmdir(tempDir, { recursive: true }) | ||
await fs.mkdir(tempDir) | ||
for (const file of await fs.readdir(fixtureDir)) { | ||
await fs.copyFile( | ||
path.join(__dirname, 'fixtures', file), | ||
path.join(tempDir, file) | ||
) | ||
} | ||
}) | ||
|
||
afterAll(async () => { | ||
await browser.close() | ||
await fs.rmdir(tempDir, { recursive: true }) | ||
server.kill('SIGTERM', { | ||
forceKillAfterTimeout: 2000 | ||
}) | ||
}) | ||
|
||
test('test', async () => { | ||
server = execa(path.resolve(__dirname, '../bin/vds.js'), { | ||
cwd: tempDir | ||
}) | ||
await new Promise((resolve) => { | ||
server.stdout.on('data', (data) => { | ||
if (data.toString().match('Running')) { | ||
resolve() | ||
} | ||
}) | ||
}) | ||
|
||
browser = await puppeteer.launch() | ||
|
||
const page = await browser.newPage() | ||
await page.goto('http://localhost:3000') | ||
|
||
// test nested components rendering | ||
const button = await page.$('button') | ||
expect(await button.evaluate((b) => b.textContent)).toBe('0') | ||
const child = await page.$('.child') | ||
expect(await child.evaluate((e) => e.textContent)).toBe('This is child') | ||
|
||
// test interaction | ||
await button.click() | ||
expect(await button.evaluate((b) => b.textContent)).toBe('1') | ||
|
||
// test HMR | ||
const compPath = path.join(tempDir, 'Comp.vue') | ||
const content = await fs.readFile(compPath, 'utf-8') | ||
await fs.writeFile( | ||
compPath, | ||
content.replace('{{ count }}', 'count is {{ count }}') | ||
) | ||
// poll until it updates | ||
const maxTries = 10 | ||
for (let tries = 0; tries < maxTries; tries++) { | ||
const text = await button.evaluate((b) => b.textContent) | ||
if (text === 'count is 1' || tries === maxTries - 1) { | ||
expect(text).toBe('count is 1') | ||
} else { | ||
await timeout(200) | ||
} | ||
} | ||
}) |
Oops, something went wrong.