Skip to content

Commit

Permalink
feat: support yarn pnp (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Aug 20, 2024
1 parent c5b3a47 commit ed8f947
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 23 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@
},
"pnpm": {
"patchedDependencies": {
"[email protected]": "patches/[email protected]"
"[email protected]": "patches/[email protected]",
"@vitest/[email protected]": "patches/@[email protected]"
}
},
"lint-staged": {
Expand Down
34 changes: 34 additions & 0 deletions patches/@[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
diff --git a/dist/chunk-tasks.js b/dist/chunk-tasks.js
index 8d5d39d8ecfa64017593b50327215c95b600467a..8fb7f0add58b4aa6f173a8b1655498bf401ab0a8 100644
--- a/dist/chunk-tasks.js
+++ b/dist/chunk-tasks.js
@@ -1,4 +1,3 @@
-import { processError } from '@vitest/utils/error';
import { relative } from 'pathe';
import { toArray } from '@vitest/utils';

@@ -103,14 +102,18 @@ function checkAllowOnly(task, allowOnly) {
if (allowOnly) {
return;
}
- const error = processError(
- new Error(
- "[Vitest] Unexpected .only modifier. Remove it or pass --allowOnly argument to bypass this error"
- )
- );
+ const error = new Error(
+ "[Vitest] Unexpected .only modifier. Remove it or pass --allowOnly argument to bypass this error"
+ )
task.result = {
state: "fail",
- errors: [error]
+ errors: [
+ {
+ name: error.name,
+ stack: error.stack,
+ message: error.message
+ }
+ ]
};
}
function generateHash(str) {
10 changes: 7 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/api/pkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ function resolveVitestConfig(showWarning: boolean, configOrWorkspaceFile: vscode
const prefix = `${basename(dirname(id))}:${basename(id)}`

if (vitest.pnp) {
// TODO: try to load vitest package version from pnp
return {
folder,
id,
Expand Down
10 changes: 2 additions & 8 deletions src/api/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export function resolveVitestPackage(cwd: string, folder: vscode.WorkspaceFolder
if (!pnp)
return null
return {
vitestNodePath: resolveVitestNodePath(pnp.vitestPath),
vitestPackageJsonPath: pnp.vitestPath,
vitestNodePath: 'vitest/node',
vitestPackageJsonPath: 'vitest/package.json',
pnp: {
loaderPath: pnp.pnpLoader,
pnpPath: pnp.pnpPath,
Expand All @@ -55,16 +55,10 @@ export function resolveVitestPnpPackagePath(cwd: string) {
const pnpPath = require.resolve('./.pnp.cjs', {
paths: [cwd],
})
const pnp = _require(pnpPath)
const vitestPath = pnp.resolveToUnqualified(
'vitest/package.json',
cwd,
) as string
return {
pnpLoader: require.resolve('./.pnp.loader.mjs', {
paths: [cwd],
}),
vitestPath,
pnpPath,
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/api/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import v8 from 'node:v8'
import { type BirpcReturn, createBirpc } from 'birpc'
import type { File, TaskResultPack, UserConsoleLog } from 'vitest'
import type { RunnerTestFile, TaskResultPack, UserConsoleLog } from 'vitest'

export interface VitestMethods {
getFiles: () => Promise<[project: string, file: string][]>
Expand All @@ -21,9 +21,9 @@ export interface VitestMethods {
export interface VitestEvents {
onConsoleLog: (log: UserConsoleLog) => void
onTaskUpdate: (task: TaskResultPack[]) => void
onFinished: (files: File[], unhandledError: string, collecting?: boolean) => void
onCollected: (files?: File[], collecting?: boolean) => void
onWatcherStart: (files?: File[], errors?: unknown[], collecting?: boolean) => void
onFinished: (files: RunnerTestFile[], unhandledError: string, collecting?: boolean) => void
onCollected: (files?: RunnerTestFile[], collecting?: boolean) => void
onWatcherStart: (files?: RunnerTestFile[], errors?: unknown[], collecting?: boolean) => void
onWatcherRerun: (files: string[], trigger?: string, collecting?: boolean) => void
}

Expand Down
12 changes: 6 additions & 6 deletions src/worker/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export async function astCollectTests(
const file: ParsedFile = {
filepath,
type: 'suite',
id: generateHash(`${testFilepath}${ctx.config.name || ''}`),
id: /* @__PURE__ */ generateHash(`${testFilepath}${ctx.config.name || ''}`),
name: testFilepath,
mode: 'run',
tasks: [],
Expand Down Expand Up @@ -193,7 +193,7 @@ export async function astCollectTests(
},
})
const indexMap = createIndexMap(request.code)
const map = request.map && new TraceMap(request.map as any)
const map = /* @__PURE__ */ request.map && new TraceMap(request.map as any)
let lastSuite: ParsedSuite = file
const updateLatestSuite = (index: number) => {
while (lastSuite.suite && lastSuite.end < index) {
Expand All @@ -213,7 +213,7 @@ export async function astCollectTests(
const processedLocation = indexMap.get(definition.start)
let ___location: { line: number; column: number } | undefined
if (map && processedLocation) {
const originalLocation = originalPositionFor(map, {
const originalLocation = /* @__PURE__ */ originalPositionFor(map, {
line: processedLocation.line,
column: processedLocation.column,
})
Expand Down Expand Up @@ -272,9 +272,9 @@ export async function astCollectTests(
definition.task = task
latestSuite.tasks.push(task)
})
calculateSuiteHash(file)
const hasOnly = someTasksAreOnly(file)
interpretTaskModes(
/* @__PURE__ */ calculateSuiteHash(file)
const hasOnly = /* @__PURE__ */ someTasksAreOnly(file)
/* @__PURE__ */ interpretTaskModes(
file,
ctx.config.testNamePattern,
hasOnly,
Expand Down

0 comments on commit ed8f947

Please sign in to comment.