Skip to content
Closed
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
Prev Previous commit
Next Next commit
chore: disable mocker for now
  • Loading branch information
sheremet-va committed Jan 17, 2025
commit c1346f81f7ef650478a7349f5b480c45a4f6a64b
1 change: 0 additions & 1 deletion packages/vitest/src/node/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ export interface InlineConfig {

/**
* Handling for dependencies inlining or externalizing
*
*/
deps?: DepsOptions

Expand Down
32 changes: 28 additions & 4 deletions packages/vitest/src/runtime/native-executor.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import type { WorkerGlobalState } from '../types/worker'
import type { ExecuteOptions } from './execute'
import { resolve } from 'node:path'
import { pathToFileURL } from 'node:url'
import { ModuleCacheMap } from 'vite-node/client'
import { VitestMocker } from './mocker'

export class NativeExecutor {
public mocker: VitestMocker
public moduleCache = new ModuleCacheMap()

public options: ExecuteOptions

Expand All @@ -17,10 +20,11 @@ export class NativeExecutor {
},
}
this.mocker = new VitestMocker(this as any)
Object.defineProperty(globalThis, '__vitest_mocker__', {
value: this.mocker,
configurable: true,
})
// TODO: don't support mocker for now
// Object.defineProperty(globalThis, '__vitest_mocker__', {
// value: this.mocker,
// configurable: true,
// })
}

executeId(id: string) {
Expand All @@ -31,6 +35,26 @@ export class NativeExecutor {
return import(resolve(this.state.config.root, id))
}

cachedRequest(id: string) {
return import(id)
}

// used by vi.importActual
async originalResolveUrl(id: string, importer?: string) {
try {
const path = import.meta.resolve(id, importer ? pathToFileURL(importer) : undefined)
return [path, path]
}
catch (error: any) {
if (error.code === 'ERR_MODULE_NOT_FOUND') {
Object.defineProperty(error, Symbol.for('vitest.error.not_found.data'), {
value: { id },
})
}
throw error
}
}

get state(): WorkerGlobalState {
// @ts-expect-error injected untyped global
return globalThis.__vitest_worker__ || this.options.state
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/runtime/workers/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export async function runBaseTests(method: 'run' | 'collect', state: WorkerGloba

async function resolveExecutor(state: WorkerGlobalState): Promise<VitestExecutor> {
if (state.config.experimentalNativeImport) {
return new NativeExecutor(state) as VitestExecutor
return new NativeExecutor(state) as unknown as VitestExecutor
}
return startViteNode({ state, requestStubs: getDefaultRequestStubs() })
}
3 changes: 0 additions & 3 deletions test/core/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,5 @@ export default defineConfig({
return false
}
},
experimental: {
nativeImport: true,
},
},
})
Loading