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

feat!: improve interchangeability with cjs #1944

Merged
merged 5 commits into from
Sep 4, 2022

Conversation

sheremet-va
Copy link
Member

Fixes #1939

@sheremet-va sheremet-va requested a review from antfu August 31, 2022 11:54
@sheremet-va sheremet-va marked this pull request as draft September 3, 2022 07:30
@sheremet-va sheremet-va marked this pull request as ready for review September 3, 2022 08:06
@sheremet-va
Copy link
Member Author

sheremet-va commented Sep 3, 2022

@antfu made some changes - noticed that new behaviour also triggers for ESM, which is incorrect

Also added usecase, where default is not an object - Node finds named exports, but returnes them as undefined (because tries to access it on default): https://stackblitz.com/edit/node-kyzwfi?file=cjs.js,index.js

Also removed ability to put all instance properties on exports:

// class-cjs.js
class SomeClass {
  variable = 1
}
module.exports = new SomeClas() 

// test.js
import * as cjs from './class-cjs.js'
expect(cjs).not.toHaveProperty('variable')

@sheremet-va sheremet-va changed the title fix: allow accessing named cjs exports on default feat: improve interchangeability for cjs Sep 3, 2022
@sheremet-va sheremet-va changed the title feat: improve interchangeability for cjs feat: improve interchangeability with cjs Sep 3, 2022
@sheremet-va sheremet-va changed the title feat: improve interchangeability with cjs feat!: improve interchangeability with cjs Sep 4, 2022
@sheremet-va sheremet-va merged commit 4131a52 into vitest-dev:main Sep 4, 2022
@sheremet-va sheremet-va deleted the fix/cjs-default branch September 4, 2022 07:54
antfu pushed a commit to poyoho/vitest that referenced this pull request Sep 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dynamic import of TS files from inside node_modules
2 participants