Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: disable isolate for unit test #17448

Merged
merged 4 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: disable isolate for unit test
  • Loading branch information
bluwy committed Jun 12, 2024
commit bbb741fdd3b68dbfe50db75c3822db707353cbdf
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import '../config-deps/foo.js'

export default defineConfig({
envDir: '../custom-env',
publicDir: '../custom-public',
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"private": true,
"type": "module"
}
76 changes: 21 additions & 55 deletions packages/vite/src/node/server/__tests__/watcher.spec.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,22 @@
import { resolve } from 'node:path'
import {
type MockInstance,
afterEach,
beforeEach,
describe,
expect,
it,
vi,
} from 'vitest'
import chokidar from 'chokidar'
import { createServer } from '../index'
import { fileURLToPath } from 'node:url'
import { afterEach, describe, expect, it } from 'vitest'
import { type ViteDevServer, createServer } from '../index'

const stubGetWatchedCode = /getWatched\(\) \{.+?return \{\};.+?\}/s

let watchSpy: MockInstance<
Parameters<typeof chokidar.watch>,
ReturnType<typeof chokidar.watch>
>

vi.mock('../../config', async () => {
const config: typeof import('../../config') =
await vi.importActual('../../config')
const resolveConfig = config.resolveConfig
vi.spyOn(config, 'resolveConfig').mockImplementation(async (...args) => {
const resolved: Awaited<ReturnType<typeof resolveConfig>> =
await resolveConfig.call(config, ...args)
resolved.configFileDependencies.push(
resolve('fake/config/dependency.js').replace(/\\/g, '/'),
)
return resolved
})
return config
})

describe('watcher configuration', () => {
beforeEach(() => {
watchSpy = vi.spyOn(chokidar, 'watch')
})
let server: ViteDevServer | undefined

afterEach(() => {
watchSpy.mockRestore()
afterEach(async () => {
if (server) {
await server.close()
server = undefined
}
})

it('when watcher is disabled, return noop watcher', async () => {
const server = await createServer({
server = await createServer({
server: {
watch: null,
},
Expand All @@ -52,7 +25,7 @@
})

it('when watcher is not disabled, return chokidar watcher', async () => {
const server = await createServer({
server = await createServer({
server: {
watch: {},
},
Expand All @@ -61,25 +34,18 @@
})

it('should watch the root directory, config file dependencies, dotenv files, and the public directory', async () => {
await createServer({
server: {
watch: {},
},
publicDir: '__test_public__',
})
expect(watchSpy).toHaveBeenLastCalledWith(
const root = fileURLToPath(
new URL('./fixtures/watcher/nested-root', import.meta.url),
)
server = await createServer({ root })
await new Promise((resolve) => server!.watcher.on('ready', resolve))
const watchedDirs = Object.keys(server.watcher.getWatched())
expect(watchedDirs).toEqual(

Check failure on line 43 in packages/vite/src/node/server/__tests__/watcher.spec.ts

View workflow job for this annotation

GitHub Actions / Build&Test: node-18, ubuntu-latest

packages/vite/src/node/server/__tests__/watcher.spec.ts > watcher configuration > should watch the root directory, config file dependencies, dotenv files, and the public directory

AssertionError: expected [ …(3) ] to deeply equal ArrayContaining{…} - Expected + Received - ArrayContaining [ - "/home/runner/work/vite/vite/packages/vite/src/node/server/__tests__/fixtures/watcher/nested-root", + Array [ "/home/runner/work/vite/vite/packages/vite/src/node/server/__tests__/fixtures/watcher/config-deps", + "/home/runner/work/vite/vite/packages/vite/src/node/server/__tests__/fixtures/watcher/nested-root", "/home/runner/work/vite/vite/packages/vite/src/node/server/__tests__/fixtures/watcher/custom-env", - "/home/runner/work/vite/vite/packages/vite/src/node/server/__tests__/fixtures/watcher/custom-public", ] ❯ packages/vite/src/node/server/__tests__/watcher.spec.ts:43:25

Check failure on line 43 in packages/vite/src/node/server/__tests__/watcher.spec.ts

View workflow job for this annotation

GitHub Actions / Build&Test: node-20, ubuntu-latest

packages/vite/src/node/server/__tests__/watcher.spec.ts > watcher configuration > should watch the root directory, config file dependencies, dotenv files, and the public directory

AssertionError: expected [ …(3) ] to deeply equal ArrayContaining{…} - Expected + Received - ArrayContaining [ - "/home/runner/work/vite/vite/packages/vite/src/node/server/__tests__/fixtures/watcher/nested-root", + Array [ "/home/runner/work/vite/vite/packages/vite/src/node/server/__tests__/fixtures/watcher/config-deps", + "/home/runner/work/vite/vite/packages/vite/src/node/server/__tests__/fixtures/watcher/nested-root", "/home/runner/work/vite/vite/packages/vite/src/node/server/__tests__/fixtures/watcher/custom-env", - "/home/runner/work/vite/vite/packages/vite/src/node/server/__tests__/fixtures/watcher/custom-public", ] ❯ packages/vite/src/node/server/__tests__/watcher.spec.ts:43:25

Check failure on line 43 in packages/vite/src/node/server/__tests__/watcher.spec.ts

View workflow job for this annotation

GitHub Actions / Build&Test: node-22, ubuntu-latest

packages/vite/src/node/server/__tests__/watcher.spec.ts > watcher configuration > should watch the root directory, config file dependencies, dotenv files, and the public directory

AssertionError: expected [ …(3) ] to deeply equal ArrayContaining{…} - Expected + Received - ArrayContaining [ - "/home/runner/work/vite/vite/packages/vite/src/node/server/__tests__/fixtures/watcher/nested-root", + Array [ "/home/runner/work/vite/vite/packages/vite/src/node/server/__tests__/fixtures/watcher/config-deps", + "/home/runner/work/vite/vite/packages/vite/src/node/server/__tests__/fixtures/watcher/nested-root", "/home/runner/work/vite/vite/packages/vite/src/node/server/__tests__/fixtures/watcher/custom-env", - "/home/runner/work/vite/vite/packages/vite/src/node/server/__tests__/fixtures/watcher/custom-public", ] ❯ packages/vite/src/node/server/__tests__/watcher.spec.ts:43:25

Check failure on line 43 in packages/vite/src/node/server/__tests__/watcher.spec.ts

View workflow job for this annotation

GitHub Actions / Build&Test: node-20.13.1, windows-latest

packages/vite/src/node/server/__tests__/watcher.spec.ts > watcher configuration > should watch the root directory, config file dependencies, dotenv files, and the public directory

AssertionError: expected [ …(3) ] to deeply equal ArrayContaining{…} - Expected + Received - ArrayContaining [ - "D:/a/vite/vite/packages/vite/src/node/server/__tests__/fixtures/watcher/nested-root", - "D:/a/vite/vite/packages/vite/src/node/server/__tests__/fixtures/watcher/config-deps", - "D:/a/vite/vite/packages/vite/src/node/server/__tests__/fixtures/watcher/custom-env", - "D:/a/vite/vite/packages/vite/src/node/server/__tests__/fixtures/watcher/custom-public", + Array [ + "D:\\a\\vite\\vite\\packages\\vite\\src\\node\\server\\__tests__\\fixtures\\watcher\\config-deps", + "D:\\a\\vite\\vite\\packages\\vite\\src\\node\\server\\__tests__\\fixtures\\watcher\\nested-root", + "D:\\a\\vite\\vite\\packages\\vite\\src\\node\\server\\__tests__\\fixtures\\watcher\\custom-env", ] ❯ packages/vite/src/node/server/__tests__/watcher.spec.ts:43:25
expect.arrayContaining(
[
process.cwd(),
resolve('fake/config/dependency.js'),
resolve('.env'),
resolve('.env.local'),
resolve('.env.development'),
resolve('.env.development.local'),
resolve('__test_public__'),
].map((file) => file.replace(/\\/g, '/')),
['.', '../config-deps', '../custom-env', '../custom-public'].map(
(dir) => resolve(root, dir).replace(/\\/g, '/'),
),
),
expect.anything(),
)
})
})
4 changes: 1 addition & 3 deletions packages/vite/src/node/ssr/runtime/__tests__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ export async function createViteRuntimeTester(
server: {
middlewareMode: true,
watch: null,
hmr: {
port: 9609,
},
ws: false,
},
ssr: {
external: ['@vitejs/cjs-external', '@vitejs/esm-external'],
Expand Down
1 change: 1 addition & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default defineConfig({
'./playground-temp/**/*.*',
],
testTimeout: 20000,
isolate: false,
},
esbuild: {
target: 'node18',
Expand Down
Loading