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

Make debug work with yarn 3 workspaces #83

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@
],
"outFiles": ["${workspaceFolder}/out/**/*.js"]
},
{
"name": "Run Extension Multi-Root Workspace No Root Sample",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"${workspaceFolder}/samples/multi-root-workspace-no-root/sample.code-workspace"
],
"outFiles": ["${workspaceFolder}/out/**/*.js"]
},
{
"name": "Run Extension Monorepo Sample",
"type": "extensionHost",
Expand Down
8 changes: 8 additions & 0 deletions samples/multi-root-workspace-no-root/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# yarn
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
783 changes: 783 additions & 0 deletions samples/multi-root-workspace-no-root/.yarn/releases/yarn-3.2.3.cjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions samples/multi-root-workspace-no-root/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-3.2.3.cjs
15 changes: 15 additions & 0 deletions samples/multi-root-workspace-no-root/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "monorepo",
"version": "1.0.1",
"description": "",
"main": "index.js",
"workspaces": [
"packages/*"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"packageManager": "[email protected]"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, { useState } from 'react'

const STATUS = {
HOVERED: 'hovered',
NORMAL: 'normal',
}

const Link = ({ page, children }: any) => {
const [status, setStatus] = useState(STATUS.NORMAL)

const onMouseEnter = () => {
setStatus(STATUS.HOVERED)
}

const onMouseLeave = () => {
setStatus(STATUS.NORMAL)
}

return (
<a
className={status}
href={page || '#'}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
>
{children}
</a>
)
}

export default Link
25 changes: 25 additions & 0 deletions samples/multi-root-workspace-no-root/packages/react/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@vitest/test-react",
"private": true,
"scripts": {
"coverage": "vitest run --coverage",
"test": "vitest",
"test:ui": "vitest --ui"
},
"dependencies": {
"react": "^17.0.2"
},
"devDependencies": {
"@types/react": "^17.0.41",
"@types/react-test-renderer": "^17.0.1",
"@vitejs/plugin-react": "1.2.0",
"@vitest/ui": "latest",
"happy-dom": "^2.49.0",
"jsdom": "latest",
"react-test-renderer": "17.0.2",
"vitest": "^0.18.0"
},
"stackblitz": {
"startCommand": "npm run test:ui"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Vitest Snapshot v1

exports[`Link changes the class when hovered 1`] = `
<a
className="normal"
href="http://antfu.me"
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
Anthony Fu
</a>
`;

exports[`Link changes the class when hovered 2`] = `
<a
className="hovered"
href="http://antfu.me"
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
Anthony Fu
</a>
`;

exports[`Link changes the class when hovered 3`] = `
<a
className="normal"
href="http://antfu.me"
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
Anthony Fu
</a>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Vitest Snapshot v1

exports[`Link changes the class when hovered 1`] = `
<a
className="normal"
href="http://antfu.me"
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
Anthony Fu
</a>
`;

exports[`Link changes the class when hovered 2`] = `
<a
className="hovered"
href="http://antfu.me"
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
Anthony Fu
</a>
`;

exports[`Link changes the class when hovered 3`] = `
<a
className="normal"
href="http://antfu.me"
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
Anthony Fu
</a>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Vitest Snapshot v1

exports[`Link changes the class when hovered 1`] = `
<a
className="normal"
href="http://antfu.me"
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
Anthony Fu
</a>
`;

exports[`Link changes the class when hovered 2`] = `
<a
className="hovered"
href="http://antfu.me"
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
Anthony Fu
</a>
`;

exports[`Link changes the class when hovered 3`] = `
<a
className="normal"
href="http://antfu.me"
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
Anthony Fu
</a>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react'
import renderer from 'react-test-renderer'
import Link from '../components/Link'

function toJson(component: renderer.ReactTestRenderer) {
const result = component.toJSON()
expect(result).toBeDefined()
expect(result).not.toBeInstanceOf(Array)
return result as renderer.ReactTestRendererJSON
}

test('Link changes the class when hovered', () => {
const component = renderer.create(
<Link page="http://antfu.me">Anthony Fu</Link>,
)
let tree = toJson(component)
expect(tree).toMatchSnapshot()

// manually trigger the callback
tree.props.onMouseEnter()

// re-rendering
tree = toJson(component)
expect(tree).toMatchSnapshot()

// manually trigger the callback
tree.props.onMouseLeave()
// re-rendering
tree = toJson(component)
expect(tree).toMatchSnapshot()
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"jsx": "react"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/// <reference types="vitest" />

import { defineConfig } from 'vite'

export default defineConfig({
test: {
globals: true,
environment: 'happy-dom',
},
})
25 changes: 25 additions & 0 deletions samples/multi-root-workspace-no-root/sample.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"folders": [
{
"name": "react",
"path": "./packages/react"
},
{
"name": "root",
"path": "."
},
],
"settings": {
"vitest.disabledWorkspaceFolders": ["root"],
"vitest.commandLine": "yarn vitest",
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true,
"packages": true
}
}
}