Skip to content

Commit

Permalink
revert!: don't rely on environment for interopDefault (#2682)
Browse files Browse the repository at this point in the history
Closes #2610
  • Loading branch information
sheremet-va authored Jan 23, 2023
1 parent a5ec633 commit 3f20cf5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 45 deletions.
6 changes: 0 additions & 6 deletions packages/vitest/src/runtime/execute.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 3f20cf5

Please sign in to comment.