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

fix: resolve dynamicly imported modules to be the same as statically #911

Merged
merged 4 commits into from Mar 9, 2022

Conversation

sheremet-va
Copy link
Member

Fixes #813

@netlify
Copy link

netlify bot commented Mar 8, 2022

✔️ Deploy Preview for vitest-dev ready!

🔨 Explore the source changes: 44b2e4d

🔍 Inspect the deploy log: https://app.netlify.com/sites/vitest-dev/deploys/622850286555850008d86da2

😎 Browse the preview: https://deploy-preview-911--vitest-dev.netlify.app

@@ -57,7 +57,7 @@ export class ViteNodeRunner {
// and wasn't transformed by Vite
if (this.shouldResolveId(dep)) {
const resolvedDep = await this.options.resolveId(dep, id)
dep = resolvedDep?.id || dep
dep = resolvedDep?.id?.replace(this.root, '') || dep
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May not contain root, and I didn't want to make another if for .slice(this.root.length)

@sheremet-va sheremet-va requested a review from antfu March 8, 2022 15:47
@@ -1,30 +1,30 @@
import { expect, test } from 'vitest'

test('dynamic relative import works', async() => {
const { timeout } = await import('./../src/timeout')
Copy link
Member

@antfu antfu Mar 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it a named export? I am not sure if I understand why we can do this - or are you checking the module reference to be the same?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this exactly what i am doing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about name the variables module so it could be less confusing? like

literalImportedMod and stringImportedMod - but you call it :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@antfu antfu merged commit 094d23e into main Mar 9, 2022
@antfu antfu deleted the sheremet-va/fix-dynamic-imports branch March 9, 2022 07:21
chaii3 pushed a commit to chaii3/vitest that referenced this pull request May 13, 2022
Co-authored-by: Jelf <haichao.liang@parameters.cn>
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
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.

import() fails when you have a variable string importing a Vue component
2 participants