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: Module graph in workspace of UI package #3636

Closed
wants to merge 14 commits into from

Conversation

g4rry420
Copy link
Contributor

@g4rry420 g4rry420 commented Jun 21, 2023

fix: #3470

Screenshot 2023-06-30 225652

@stackblitz
Copy link

stackblitz bot commented Jun 21, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link
Member

@sheremet-va sheremet-va left a comment

Choose a reason for hiding this comment

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

I don't think this is a good solution. Module Graph should show module from the same workspace as the test file, not a random one

@g4rry420
Copy link
Contributor Author

@sheremet-va Please, correct me if I am wrong, but isn't this code will show module from the same workspace as the test file, as I am showing the module based on the id of the file.
Or is there a specific scenario that I am missing related to workspaces ? Please, let me know :)

const workspaceModules = workspaceProject?.ctx.getModuleProjects(id)
let workspaceMod: ModuleNode | undefined
if (workspaceModules && workspaceModules.length === 1) {
    const { server, browser } = workspaceModules[0]
    const mod = server.moduleGraph.getModuleById(id) || browser?.moduleGraph.getModuleById(id)
    workspaceMod = mod
}

@sheremet-va
Copy link
Member

sheremet-va commented Jun 26, 2023

@sheremet-va Please, correct me if I am wrong, but isn't this code will show module from the same workspace as the test file, as I am showing the module based on the id of the file. Or is there a specific scenario that I am missing related to workspaces ? Please, let me know :)

const workspaceModules = workspaceProject?.ctx.getModuleProjects(id)
let workspaceMod: ModuleNode | undefined
if (workspaceModules && workspaceModules.length === 1) {
    const { server, browser } = workspaceModules[0]
    const mod = server.moduleGraph.getModuleById(id) || browser?.moduleGraph.getModuleById(id)
    workspaceMod = mod
}

It's possible to have the same test file in different workspace projects and process them differently. There is an example in test/workspaces with space_shared.

.getModuleProjects returns you an array for a reason.

@g4rry420
Copy link
Contributor Author

Ah okay, Thanks, Do you have suggestions about how this should be resolved then ?

@sheremet-va
Copy link
Member

Ah okay, Thanks, Do you have suggestions about how this should be resolved then ?

Show a button with all workspaces (if there are more than one) to choose from on the module graph page.

@sheremet-va
Copy link
Member

Ah okay, Thanks, Do you have suggestions about how this should be resolved then ?

Show a button with all workspaces (if there are more than one) to choose from on the module graph page.

Or! Which is probably better for now - display workspace name near the test file in the spec list. I think test files are now duplicated without the name there.

Then you can just pass workspace name to the module graph

…e workspace module fetch logic as per Vladimir suggestions

Signed-off-by: GurkiranSingh <[email protected]>
@netlify
Copy link

netlify bot commented Jul 1, 2023

Deploy Preview for fastidious-cascaron-4ded94 canceled.

Name Link
🔨 Latest commit 11bb99d
🔍 Latest deploy log https://app.netlify.com/sites/fastidious-cascaron-4ded94/deploys/653d3d33d32b030008d36220

@g4rry420 g4rry420 requested a review from sheremet-va July 1, 2023 03:58
@@ -23,7 +23,7 @@ const duration = computed(() => {
>
<StatusIcon :task="task" mr-2 />
<div flex items-end gap-2 :text="task?.result?.state === 'fail' ? 'red-500' : ''">
<span text-sm truncate font-light>{{ task.name }}</span>
<span text-sm truncate font-light>{{ `${(task.type === "suite" && task.projectName) ? `${task.projectName}/` : ''}${task.name}` }}</span>
Copy link
Member

Choose a reason for hiding this comment

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

I don't like how it's shown. In CLI it's marked as [${name}] and has a color

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sheremet-va Like this ?
Screenshot 2023-07-04 204747

Copy link
Member

Choose a reason for hiding this comment

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

yes

Copy link
Member

@sheremet-va sheremet-va Jul 11, 2023

Choose a reason for hiding this comment

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

Yellow/green/blue colors are unreadable in light theme:

Screenshot 2023-07-11 at 09 40 45

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sheremet-va How about we if use a bit of blackish-shade with yellow - #7c7c05, green - #025402 and blue - rgb(2 2 131) color ?
Screenshot 2023-07-24 214457

Copy link
Member

Choose a reason for hiding this comment

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

happy-dom still looks unreadable to me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sheremet-va How's this ?
Screenshot 2023-07-25 215100

Copy link
Member

Choose a reason for hiding this comment

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

Looks readable. Is it only for light mode? Won't be readable in dark mode

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@g4rry420 g4rry420 Jul 26, 2023

Choose a reason for hiding this comment

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

Yes, the colors in this image will only be for light mode - #3636 (comment)

@g4rry420 g4rry420 requested a review from sheremet-va July 5, 2023 00:56
workspaceMod = mod
}

await get(ctx.server.moduleGraph.getModuleById(id) || workspaceMod)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't you fallback to ctx.server.moduleGraph only if you didn't find the workspaceMod? This line looks suspicious to me


const workspaceProject = ctx.projects.find(project => project.getName() === workspaceName)
const workspaceModules = workspaceProject?.ctx.getModuleProjects(id)
const selectedModule = workspaceModules?.find(module => module.getName() === workspaceName)
Copy link
Member

Choose a reason for hiding this comment

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

You do the same thing you did on #L33. Why?

You need to find the project by name and fallback to ctx.getCoreWorkspaceProject().server || ctx.server

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sheremet-va getCoreWorkspaceProject() is coming as null for test/workspaces folder.
Screenshot 2023-08-08 213513

Upon investigating, I have found that the conditons that executes the createCoreWorkspace function in packages\vitest\src\node\core.ts aren't satisfying

Screenshot 2023-08-08 213414

You do the same thing you did on #L33. Why?

This might be hacky, but I have found only this way where we get the workspaceMod

Copy link
Member

@sheremet-va sheremet-va Aug 16, 2023

Choose a reason for hiding this comment

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

getCoreWorkspaceProject() is coming as null for test/workspaces folder.

Yes, it will be null if there is no core project. This is why I added || ctx.server. Core project is not created if main config file is not used by a workspace (so, when there is a global config and project configs and workspace specifies only project configs without manually using core project)

Core workspace project should be used AS THE LAST RESORT. Regular projects should be used if they are found by name.

This might be hacky, but I have found only this way where we get the workspaceMod

Then you must be doing something wrong?

Copy link
Member

Choose a reason for hiding this comment

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

Workspace project is just a project with the same name. If there is no such projects, just fallback to context which is always defined

await get(ctx.server.moduleGraph.getModuleById(id))

const workspaceProject = ctx.projects.find(project => project.getName() === workspaceName)
const workspaceModules = workspaceProject?.ctx.getModuleProjects(id)
Copy link
Member

@sheremet-va sheremet-va Aug 16, 2023

Choose a reason for hiding this comment

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

This code can be removed, you already have access to ctx

@TECH7Fox
Copy link

TECH7Fox commented Oct 3, 2023

Any update on this? I would be happy to create another PR to get this fix merged.

@sheremet-va
Copy link
Member

Any update on this? I would be happy to create another PR to get this fix merged.

Feel free to open a separate PR.

@sheremet-va
Copy link
Member

This is fixed in main.

@sheremet-va sheremet-va closed this Jul 1, 2024
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.

Module graph not working in workspace
4 participants