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

revert!: don't rely on environment for interopDefault #2682

Merged
merged 2 commits into from Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 0 additions & 6 deletions packages/vitest/src/runtime/execute.ts
Expand Up @@ -71,10 +71,4 @@ export class VitestRunner extends ViteNodeRunner {
__vitest_mocker__: this.mocker,
})
}

shouldInterop(path: string, mod: any) {
if (this.options.interopDefault === false)
return false
return (this.options.interopDefault || getCurrentEnvironment() !== 'node') && super.shouldInterop(path, mod)
}
}
33 changes: 0 additions & 33 deletions test/core/test/module-dom.test.ts

This file was deleted.

16 changes: 10 additions & 6 deletions test/core/test/module.test.ts
Expand Up @@ -30,17 +30,21 @@ describe('validating nested defaults in isolation', () => {
it.each([
nestedDefaultCjs,
nestedDefaultExternalCjs,
])('nested default should stay, because environment is node', (mod) => {
])('nested default should be resolved', (mod) => {
expect(mod).toHaveProperty('default')
expect(mod.default).toHaveProperty('default')
expect(mod.default.default.a).toBe('a')
expect(mod.default.default.b).toBe('b')
expect(mod.default).not.toHaveProperty('default')
expect(mod.default.a).toBe('a')
expect(mod.default.b).toBe('b')
expect(mod.a).toBe('a')
expect(mod.b).toBe('b')
})

it('don\'t interop external module.exports, because environment is node', () => {
it('externalized "module.exports" CJS module interops default', () => {
expect(moduleDefaultCjs).toHaveProperty('default')
expect(moduleDefaultCjs.default).toHaveProperty('a')
expect(moduleDefaultCjs).not.toHaveProperty('a')
expect(moduleDefaultCjs.default.a).toBe('a')
expect(moduleDefaultCjs).toHaveProperty('a')
expect(moduleDefaultCjs.a).toBe('a')
})
})

Expand Down