Skip to content

Commit b61a5bb

Browse files
committed
Add a specific test for disabling process
1 parent 4d1aabd commit b61a5bb

File tree

13 files changed

+215
-43
lines changed

13 files changed

+215
-43
lines changed

examples/vanilla/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-console */
22
import { Buffer } from 'node:buffer'
33
import { resolve } from 'node:path'
4-
import * as process from 'node:process'
4+
import process from 'node:process'
55
import fs, { readFileSync } from 'node:fs'
66
import { cloneDeep } from 'lodash-es'
77
import { fetch } from 'ohmyfetch'

examples/vanilla/test/e2e/main.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ test('logs the correct values', async ({ page }) => {
2929
'{Volume: , vol: Volume, createFsFromVolume: , fs: Object, memfs: }',
3030
'function fetch() { [native code] }',
3131
'/',
32-
'Module',
32+
'{nextTick: , title: browser, browser: true, env: Object, argv: Array(0)}',
3333
'{}',
3434
'function Array() { [native code] }',
3535
'4294967295',

examples/vanilla/vite.config.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ export default defineConfig({
99
},
1010
plugins: [
1111
nodePolyfills({
12-
globals: {
13-
process: 'build',
14-
},
1512
overrides: {
1613
fs: 'memfs',
1714
},

pnpm-lock.yaml

Lines changed: 81 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Example (Vanilla)</title>
7+
</head>
8+
<body>
9+
<script type="module" src="/src/main.ts"></script>
10+
</body>
11+
</html>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"type": "module",
3+
"private": true,
4+
"scripts": {
5+
"build": "vite build",
6+
"dev": "vite",
7+
"test:e2e": "CI=true run-p test:e2e:*",
8+
"test:e2e:build": "VITE_COMMAND=build WEB_SERVER_COMMAND='vite build && vite preview --port 15178' WEB_SERVER_URL='http://localhost:15178' playwright test",
9+
"test:e2e:dev": "VITE_COMMAND=dev WEB_SERVER_COMMAND='vite dev --port 15177' WEB_SERVER_URL='http://localhost:15177' playwright test",
10+
"typecheck": "tsc"
11+
},
12+
"devDependencies": {
13+
"@types/lodash-es": "^4.17.12",
14+
"@types/node": "^18.18.8",
15+
"lodash-es": "^4.17.21",
16+
"memfs": "^4.6.0",
17+
"npm-run-all": "^4.1.5",
18+
"ohmyfetch": "^0.4.21",
19+
"typescript": "^5.2.2",
20+
"vite": "^4.5.0",
21+
"vite-plugin-node-polyfills": "workspace:*"
22+
}
23+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { defineConfig, devices } from '@playwright/test'
2+
3+
const webServerCommand = process.env.WEB_SERVER_COMMAND || 'pnpm dev'
4+
const webServerUrl = process.env.WEB_SERVER_URL || 'http://localhost:5173'
5+
6+
// https://playwright.dev/docs/test-configuration
7+
export default defineConfig({
8+
forbidOnly: !!process.env.CI,
9+
fullyParallel: true,
10+
projects: [
11+
{
12+
name: 'chromium',
13+
use: { ...devices['Desktop Chrome'] },
14+
},
15+
],
16+
reporter: 'html',
17+
retries: process.env.CI ? 2 : 0,
18+
testDir: './test/e2e',
19+
use: {
20+
baseURL: webServerUrl,
21+
trace: 'on-first-retry',
22+
},
23+
webServer: {
24+
command: webServerCommand,
25+
stdout: 'ignore',
26+
url: webServerUrl,
27+
},
28+
workers: process.env.CI ? 1 : undefined,
29+
})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="vite/client" />
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* eslint-disable no-console */
2+
console.log(process)
3+
console.log(process.env)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { expect, test } from '@playwright/test'
2+
3+
test('sets the page title', async ({ page }) => {
4+
await page.goto('/')
5+
6+
await expect(page).toHaveTitle('Example (Vanilla)')
7+
})
8+
9+
test('logs the correct values', async ({ page }) => {
10+
const errors = []
11+
const logs = []
12+
13+
page.on('console', (message) => {
14+
if (/^\[vite\]/.test(message.text())) {
15+
return
16+
}
17+
18+
logs.push(message.text())
19+
})
20+
21+
page.on('pageerror', (error) => {
22+
errors.push(error.message)
23+
})
24+
25+
await page.goto('/')
26+
27+
expect(errors).toEqual([
28+
'process is not defined',
29+
])
30+
31+
expect(logs).toEqual([])
32+
})

0 commit comments

Comments
 (0)