-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: conditionally activate extension
- Loading branch information
Showing
7 changed files
with
70 additions
and
32 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { execSync } from "child_process"; | ||
import { existsSync } from "fs"; | ||
import { readFile } from "fs-extra"; | ||
import path = require("path"); | ||
import { getVitestPath } from "./runner"; | ||
|
||
export async function isVitestEnv(projectRoot: string) { | ||
if (getVitestPath(projectRoot)) { | ||
return true; | ||
} | ||
|
||
const pkgPath = path.join(projectRoot, "package.json") as string; | ||
const pkg = JSON.parse(await readFile(pkgPath, "utf-8")) as any; | ||
if (existsSync(pkg)) { | ||
if (pkg.devDependencies && pkg.devDependencies["vitest"]) { | ||
return true; | ||
} | ||
if (pkg.devDependencies && pkg.devDependencies["jest"]) { | ||
return false; | ||
} | ||
} | ||
|
||
return ( | ||
execSync(path.join(projectRoot, "vite.config.js")) || | ||
execSync(path.join(projectRoot, "vite.config.ts")) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as vscode from "vscode"; | ||
import { getVitestPath as getVitestPath, TestRunner } from "./pure/runner"; | ||
import { runTest } from "./runTest"; | ||
|
||
export async function runHandler( | ||
ctrl: vscode.TestController, | ||
request: vscode.TestRunRequest, | ||
cancellation: vscode.CancellationToken | ||
) { | ||
if (vscode.workspace.workspaceFolders === undefined) { | ||
return; | ||
} | ||
|
||
const runner = new TestRunner( | ||
vscode.workspace.workspaceFolders[0].uri.path, | ||
getVitestPath(vscode.workspace.workspaceFolders[0].uri.path) | ||
); | ||
|
||
const tests = request.include ?? gatherTestItems(ctrl.items); | ||
const run = ctrl.createTestRun(request); | ||
await Promise.all(tests.map((test) => runTest(runner, run, test))); | ||
} | ||
function gatherTestItems(collection: vscode.TestItemCollection) { | ||
const items: vscode.TestItem[] = []; | ||
collection.forEach((item) => items.push(item)); | ||
return items; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters