Skip to content

Commit

Permalink
feat: forward output
Browse files Browse the repository at this point in the history
  • Loading branch information
zxch3n committed Mar 22, 2022
1 parent 547a565 commit 98b0820
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 79 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"dependencies": {
"@babel/parser": "^7.17.3",
"@babel/types": "^7.17.0",
"execa": "^5.1.0",
"@rauschma/stringio": "^1.4.0",
"fs-extra": "^10.0.1",
"mighty-promise": "^0.0.8"
}
Expand Down
1 change: 1 addition & 0 deletions samples/basic/test/add.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expect, describe, it } from "vitest";

describe("addition", () => {
it("run", () => {
console.log("run");
expect(1 + 1).toBe(2);
});

Expand Down
30 changes: 21 additions & 9 deletions src/pure/runner.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { spawn } from "child_process";
import { existsSync, readFile } from "fs-extra";
import * as path from "path";
import { tmpdir } from "os";
import { TaskQueue } from "mighty-promise";
import execa = require("execa");
import { tmpdir } from "os";
import * as path from "path";

import { chunksToLinesAsync } from "@rauschma/stringio";

export function getVitestPath(projectRoot: string): string | undefined {
const node_modules = path.resolve(projectRoot, "node_modules");
Expand Down Expand Up @@ -67,36 +69,46 @@ export class TestRunner {
private workspacePath: string,
private vitePath: string | undefined
) {}

async scheduleRun(
testFile: string | undefined,
testNamePattern: string | undefined
testFile: string[] | undefined,
testNamePattern: string | undefined,
log: (msg: string) => void = () => {}
): Promise<AggregatedResult> {
return this.queue.push(async () => {
const path = getTempPath();
const args = [
"--reporter=json",
"--reporter=verbose",
"--outputFile",
path,
"--run",
] as string[];
if (testFile) {
args.push(testFile);
args.push(...testFile);
}
if (testNamePattern) {
args.push("-t", testNamePattern);
}

try {
let child;
if (this.vitePath) {
const { stderr, stdout } = await execa(this.vitePath, args, {
windowsHide: false,
child = spawn(this.vitePath, args, {
cwd: this.workspacePath,
stdio: ["ignore", "pipe", "pipe"],
});
} else {
await execa("npx", ["vitest"].concat(args), {
child = spawn("npx", ["vitest"].concat(args), {
cwd: this.workspacePath,
stdio: ["ignore", "pipe", "pipe"],
});
}

for await (const line of chunksToLinesAsync(child.stdout)) {
log(line + "\r\n");
console.log("LINE", line);
}
} catch (e) {
console.error(e);
}
Expand Down
5 changes: 3 additions & 2 deletions src/runHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,9 @@ async function runTest(
try {
const data = WEAKMAP_TEST_DATA.get(item)!;
const out = await runner.scheduleRun(
item.uri!.fsPath,
data.getFullPattern()
[item.uri!.fsPath],
data.getFullPattern(),
(msg) => run.appendOutput(msg, undefined, item)
);
if (out.testResults.length !== 0) {
out.testResults.forEach((result, index) => {
Expand Down
82 changes: 15 additions & 67 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@
"@nodelib/fs.scandir" "2.1.5"
fastq "^1.6.0"

"@rauschma/stringio@^1.4.0":
version "1.4.0"
resolved "https://registry.npmmirror.com/@rauschma/stringio/-/stringio-1.4.0.tgz#0b667bea726652a10a48dfc1dadc89e0ec51e269"
integrity sha512-3uor2f/MXZkmX5RJf8r+OC3WvZVzpSme0yyL0rQDPEnatE02qRcqwEwnsgpgriEck0S/n4vWtUd6tTtrJwk45Q==
dependencies:
"@types/node" "^10.0.3"

"@tootallnate/once@1":
version "1.1.2"
resolved "https://registry.npmmirror.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82"
Expand Down Expand Up @@ -127,7 +134,12 @@
resolved "https://registry.npmmirror.com/@types/node/-/node-14.18.12.tgz#0d4557fd3b94497d793efd4e7d92df2f83b4ef24"
integrity sha512-q4jlIR71hUpWTnGhXWcakgkZeHa3CCjcQcnuzU8M891BAWA2jHiziiWEPEkdS5pFsz7H9HJiy8BrK7tBRNrY7A==

"@types/vscode@^1.65.0":
"@types/node@^10.0.3":
version "10.17.60"
resolved "https://registry.npmmirror.com/@types/node/-/node-10.17.60.tgz#35f3d6213daed95da7f0f73e75bcc6980e90597b"
integrity sha512-F0KIgDJfy2nA3zMLmWGKxcH2ZVEtCZXHHdOQs2gSaQ27+lNeEfGxzkIw90aXswATX7AZ33tahPbzy6KAfUreVw==

"@types/vscode@^1.59.0":
version "1.65.0"
resolved "https://registry.npmmirror.com/@types/vscode/-/vscode-1.65.0.tgz#042dd8d93c32ac62cb826cd0fa12376069d1f448"
integrity sha512-wQhExnh2nEzpjDMSKhUvnNmz3ucpd3E+R7wJkOhBNK3No6fG3VUdmVmMOKD0A8NDZDDDiQcLNxe3oGmX5SjJ5w==
Expand Down Expand Up @@ -441,7 +453,7 @@ core-util-is@~1.0.0:
resolved "https://registry.npmmirror.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85"
integrity sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==

cross-spawn@^7.0.2, cross-spawn@^7.0.3:
cross-spawn@^7.0.2:
version "7.0.3"
resolved "https://registry.npmmirror.com/cross-spawn/-/cross-spawn-7.0.3.tgz#f73a85b9d5d41d045551c177e2882d4ac85728a6"
integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==
Expand Down Expand Up @@ -753,21 +765,6 @@ esutils@^2.0.2:
resolved "https://registry.npmmirror.com/esutils/-/esutils-2.0.3.tgz#74d2eb4de0b8da1293711910d50775b9b710ef64"
integrity sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==

execa@^5.1.0:
version "5.1.1"
resolved "https://registry.npmmirror.com/execa/-/execa-5.1.1.tgz#f80ad9cbf4298f7bd1d4c9555c21e93741c411dd"
integrity sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==
dependencies:
cross-spawn "^7.0.3"
get-stream "^6.0.0"
human-signals "^2.1.0"
is-stream "^2.0.0"
merge-stream "^2.0.0"
npm-run-path "^4.0.1"
onetime "^5.1.2"
signal-exit "^3.0.3"
strip-final-newline "^2.0.0"

fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3:
version "3.1.3"
resolved "https://registry.npmmirror.com/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525"
Expand Down Expand Up @@ -890,11 +887,6 @@ get-func-name@^2.0.0:
resolved "https://registry.npmmirror.com/get-func-name/-/get-func-name-2.0.0.tgz#ead774abee72e20409433a066366023dd6887a41"
integrity sha512-Hm0ixYtaSZ/V7C8FJrtZIuBBI+iSgL+1Aq82zSu8VQNB4S3Gk8e7Qs3VwBDJAhmRZcFqkl3tQu36g/Foh5I5ig==

get-stream@^6.0.0:
version "6.0.1"
resolved "https://registry.npmmirror.com/get-stream/-/get-stream-6.0.1.tgz#a262d8eef67aced57c2852ad6167526a43cbf7b7"
integrity sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==

glob-parent@^5.1.2, glob-parent@~5.1.2:
version "5.1.2"
resolved "https://registry.npmmirror.com/glob-parent/-/glob-parent-5.1.2.tgz#869832c58034fe68a4093c17dc15e8340d8401c4"
Expand Down Expand Up @@ -984,11 +976,6 @@ https-proxy-agent@^5.0.0:
agent-base "6"
debug "4"

human-signals@^2.1.0:
version "2.1.0"
resolved "https://registry.npmmirror.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0"
integrity sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==

ignore@^5.1.8, ignore@^5.2.0:
version "5.2.0"
resolved "https://registry.npmmirror.com/ignore/-/ignore-5.2.0.tgz#6d3bac8fa7fe0d45d9f9be7bac2fc279577e345a"
Expand Down Expand Up @@ -1061,11 +1048,6 @@ is-plain-obj@^2.1.0:
resolved "https://registry.npmmirror.com/is-plain-obj/-/is-plain-obj-2.1.0.tgz#45e42e37fccf1f40da8e5f76ee21515840c09287"
integrity sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==

is-stream@^2.0.0:
version "2.0.1"
resolved "https://registry.npmmirror.com/is-stream/-/is-stream-2.0.1.tgz#fac1e3d53b97ad5a9d0ae9cef2389f5810a5c077"
integrity sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==

is-unicode-supported@^0.1.0:
version "0.1.0"
resolved "https://registry.npmmirror.com/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz#3f26c76a809593b52bfa2ecb5710ed2779b522a7"
Expand Down Expand Up @@ -1159,11 +1141,6 @@ lru-cache@^6.0.0:
dependencies:
yallist "^4.0.0"

merge-stream@^2.0.0:
version "2.0.0"
resolved "https://registry.npmmirror.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"
integrity sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==

merge2@^1.3.0, merge2@^1.4.1:
version "1.4.1"
resolved "https://registry.npmmirror.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae"
Expand All @@ -1182,11 +1159,6 @@ mighty-promise@^0.0.8:
resolved "https://registry.npmmirror.com/mighty-promise/-/mighty-promise-0.0.8.tgz#c7f051d3b8f7c467667b70e947f824aeffd76d11"
integrity sha512-csmKICeF0uMMa82JzHe9i9Ajws2S2uras4OyBAkvCQBcIJ6o9gI9ktY2iyElw92kO7xOFFYU4UkKdTH5nHN0Lg==

mimic-fn@^2.1.0:
version "2.1.0"
resolved "https://registry.npmmirror.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b"
integrity sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==

minimatch@4.2.1:
version "4.2.1"
resolved "https://registry.npmmirror.com/minimatch/-/minimatch-4.2.1.tgz#40d9d511a46bdc4e563c22c3080cde9c0d8299b4"
Expand Down Expand Up @@ -1268,27 +1240,13 @@ normalize-path@^3.0.0, normalize-path@~3.0.0:
resolved "https://registry.npmmirror.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
integrity sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==

npm-run-path@^4.0.1:
version "4.0.1"
resolved "https://registry.npmmirror.com/npm-run-path/-/npm-run-path-4.0.1.tgz#b7ecd1e5ed53da8e37a55e1c2269e0b97ed748ea"
integrity sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==
dependencies:
path-key "^3.0.0"

once@^1.3.0:
version "1.4.0"
resolved "https://registry.npmmirror.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
integrity sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==
dependencies:
wrappy "1"

onetime@^5.1.2:
version "5.1.2"
resolved "https://registry.npmmirror.com/onetime/-/onetime-5.1.2.tgz#d0e96ebb56b07476df1dd9c4806e5237985ca45e"
integrity sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==
dependencies:
mimic-fn "^2.1.0"

optionator@^0.9.1:
version "0.9.1"
resolved "https://registry.npmmirror.com/optionator/-/optionator-0.9.1.tgz#4f236a6373dae0566a6d43e1326674f50c291499"
Expand Down Expand Up @@ -1332,7 +1290,7 @@ path-is-absolute@^1.0.0:
resolved "https://registry.npmmirror.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
integrity sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==

path-key@^3.0.0, path-key@^3.1.0:
path-key@^3.1.0:
version "3.1.1"
resolved "https://registry.npmmirror.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375"
integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==
Expand Down Expand Up @@ -1521,11 +1479,6 @@ shebang-regex@^3.0.0:
resolved "https://registry.npmmirror.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==

signal-exit@^3.0.3:
version "3.0.7"
resolved "https://registry.npmmirror.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9"
integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==

slash@^3.0.0:
version "3.0.0"
resolved "https://registry.npmmirror.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634"
Expand Down Expand Up @@ -1559,11 +1512,6 @@ strip-ansi@^6.0.0, strip-ansi@^6.0.1:
dependencies:
ansi-regex "^5.0.1"

strip-final-newline@^2.0.0:
version "2.0.0"
resolved "https://registry.npmmirror.com/strip-final-newline/-/strip-final-newline-2.0.0.tgz#89b852fb2fcbe936f6f4b3187afb0a12c1ab58ad"
integrity sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==

strip-json-comments@3.1.1, strip-json-comments@^3.1.0, strip-json-comments@^3.1.1:
version "3.1.1"
resolved "https://registry.npmmirror.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006"
Expand Down

0 comments on commit 98b0820

Please sign in to comment.