-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use vite-node to load globalSetup (#624)
- Loading branch information
Showing
8 changed files
with
59 additions
and
37 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true |
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 @@ | ||
* text=auto eol=lf |
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 @@ | ||
Hello Vitest |
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,16 @@ | ||
import { createServer } from 'vite' | ||
import { resolve } from 'pathe' | ||
|
||
export async function setup() { | ||
const server = await createServer({ | ||
root: resolve(__dirname, '..'), | ||
server: { | ||
port: 9988, | ||
}, | ||
}) | ||
|
||
await server.listen(9988) | ||
return async() => { | ||
await server.close() | ||
} | ||
} |
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,16 +1,12 @@ | ||
import http from 'http' | ||
|
||
async function sendRequest(host: string, port: number) { | ||
return new Promise<string>((resolve) => { | ||
http.request({ host, port }, (res) => { | ||
let data = '' | ||
res.on('data', d => data += d) | ||
res.on('end', () => resolve(data)) | ||
}).end() | ||
}) | ||
} | ||
import fetch from 'node-fetch' | ||
|
||
test('server running', async() => { | ||
const res = await sendRequest('127.0.0.1', 9876) | ||
const res = await (await fetch('http://localhost:9876')).text() | ||
expect(res).toBe('Hello Vitest\n') | ||
}) | ||
|
||
test('vite instance running', async() => { | ||
const res = await (await fetch('http://localhost:9988')).text() | ||
expect(res).toContain('<script type="module" src="/@vite/client">') | ||
expect(res).toContain('Hello Vitest\n') | ||
}) |
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