mirror of
https://github.com/vitest-dev/vitest.git
synced 2026-02-01 17:36:51 +00:00
fix: don't ignore properties, when put on a default function in CJS context (#2325)
* fix: don't ignore "default" key, when put on a function in CJS context * test: test case for default.default
This commit is contained in:
parent
30c59f50c0
commit
aa8e66250e
@ -273,7 +273,7 @@ export class ViteNodeRunner {
|
||||
|
||||
// returns undefined, when accessing named exports, if default is not an object
|
||||
// but is still present inside hasOwnKeys, this is Node behaviour for CJS
|
||||
if (exports.default === null || typeof exports.default !== 'object') {
|
||||
if (isPrimitive(exports.default)) {
|
||||
defineExport(exports, p, () => undefined)
|
||||
return true
|
||||
}
|
||||
|
||||
8
test/cjs/src/default-function.cjs
Normal file
8
test/cjs/src/default-function.cjs
Normal file
@ -0,0 +1,8 @@
|
||||
'use strict'
|
||||
|
||||
function format() {
|
||||
return ''
|
||||
}
|
||||
|
||||
module.exports = format
|
||||
module.exports.default = format
|
||||
3
test/cjs/src/default-function.d.cts
Normal file
3
test/cjs/src/default-function.d.cts
Normal file
@ -0,0 +1,3 @@
|
||||
declare function format(): string
|
||||
|
||||
export default format
|
||||
13
test/cjs/test/function-default.test.ts
Normal file
13
test/cjs/test/function-default.test.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import format from '../src/default-function.cjs'
|
||||
|
||||
describe('correctly puts default on default', () => {
|
||||
it('works on default function', () => {
|
||||
expect(format()).toBe('')
|
||||
})
|
||||
|
||||
it('works on nested default function', () => {
|
||||
// @ts-expect-error types defined only default
|
||||
expect(format.default()).toBe('')
|
||||
})
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user