-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
Description
Describe the bug
If you import a variable with the symbolic name "Object" in the test file, an error will occur.
// 1.test.js
import { Object } from "zod3"
test("1", ()=>{ Object })Error:
TypeError: Object.defineProperty is not a functionAfter tracing, I found that in the code finally executed by vitest, code using Object.defineProperty was injected into the user code space.
I think vitest needs to use protective variable names here
// vite-node/dist/client.mjs
// const code = `${codeDefinition}${transformed}
// code :
'use strict';async (__vite_ssr_import__,__vite_ssr_dynamic_import__,__vite_ssr_exports__,__vite_ssr_exportAll__,__vite_ssr_import_meta__,require,exports,module,__filename,__dirname)=>
{{const Object = {}};
Object.defineProperty(__vite_ssr_exports__, "Object",
{ enumerable: true,
configurable: true,
get(){ return Object }
}
);Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-xdxnxc?file=test%2Fbasic.test.ts
System Info
System:
OS: macOS 12.7
CPU: (8) x64 Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
Memory: 66.71 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 18.18.0 - /usr/local/bin/node
Yarn: 1.22.19 - ~/.npm-global/bin/yarn
npm: 9.8.1 - /usr/local/bin/npm
pnpm: 8.8.0 - ~/.npm-global/bin/pnpm
bun: 1.0.18 - ~/.bun/bin/bun
Browsers:
Chrome: 120.0.6099.129
Chrome Canary: 119.0.6030.0
Edge: 120.0.2210.91
npmPackages:
@vitejs/plugin-legacy: 5.2.0 => 5.2.0
@vitejs/plugin-vue2: 2.3.1 => 2.3.1
vite: 5.0.10 => 5.0.10
vitest: 1.1.0 => 1.1.0Used Package Manager
pnpm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.