プレイグラウンド、サンドボックス、使い捨てスクリプト置き場
0

Configure Feed

Select the types of activity you want to include in your feed.

use stdout-stderr

Kohei Watanabe (Apr 15, 2022, 4:52 PM +0900) 15a69ddc 3e29baac

+35 -31
+1
oclif/package.json
··· 25 25 "esbuild-register": "^3.3.2", 26 26 "npm-run-all": "^4.1.5", 27 27 "oclif": "^3.0.0", 28 + "stdout-stderr": "^0.1.13", 28 29 "tsup": "^5.12.5", 29 30 "typescript": "^4.6.3", 30 31 "vitest": "^0.9.3"
+3 -3
oclif/tests/commands/hello/index.test.ts
··· 1 1 import { test, expect } from "vitest"; 2 - import run from "../../run"; 2 + import { stdout } from "stdout-stderr"; 3 3 import Hello from "../../../src/commands/hello/index"; 4 4 5 5 test("hello", async () => { 6 - const res = await run(() => Hello.run(["friend", "--from=oclif"])); 7 - expect(res).toContain("hello friend from oclif!"); 6 + await Hello.run(["friend", "--from=oclif"]); 7 + expect(stdout.output).toContain("hello friend from oclif!"); 8 8 });
+4 -9
oclif/tests/commands/hello/world.test.ts
··· 1 - import { test, expect } from "vitest"; 2 - import run from "../../run"; 1 + import { test, expect } from "vitest"; 2 + import { stdout } from "stdout-stderr"; 3 3 import World from "../../../src/commands/hello/world"; 4 4 5 5 test("hello world", async () => { 6 - const res = await run(() => World.run()); 7 - expect(res).toContain("hello world!"); 8 - }); 9 - 10 - test("hello world", async () => { 11 - const res = await run(() => World.run()); 12 - expect(res).toContain("hello world!"); 6 + await World.run(); 7 + expect(stdout.output).toContain("hello world!"); 13 8 });
-19
oclif/tests/run.ts
··· 1 - import { vi } from "vitest"; 2 - 3 - /** 4 - * 標準出力のテストのためのヘルパー 5 - * @param proc 実行する関数 6 - * @return 標準出力の結果 7 - */ 8 - async function run(proc: () => PromiseLike<void>): Promise<string> { 9 - const out: string[] = []; 10 - const stdout = vi.spyOn(process.stdout, "write").mockImplementation((val) => { 11 - out.push(val as string); 12 - return true; 13 - }); 14 - await proc(); 15 - stdout.mockRestore(); 16 - return out.join(""); 17 - } 18 - 19 - export default run;
+12
oclif/tests/setup.ts
··· 1 + import { afterEach, beforeEach } from "vitest"; 2 + import { stdout, stderr } from "stdout-stderr"; 3 + 4 + beforeEach(() => { 5 + stdout.start(); 6 + stderr.start(); 7 + }); 8 + 9 + afterEach(() => { 10 + stdout.stop(); 11 + stderr.stop(); 12 + });
+7
oclif/vitest.config.ts
··· 1 + import { defineConfig } from "vite"; 2 + 3 + export default defineConfig({ 4 + test: { 5 + setupFiles: "tests/setup.ts", 6 + }, 7 + });
+8
oclif/yarn.lock
··· 3615 3615 dependencies: 3616 3616 minipass "^3.1.1" 3617 3617 3618 + stdout-stderr@^0.1.13: 3619 + version "0.1.13" 3620 + resolved "https://registry.yarnpkg.com/stdout-stderr/-/stdout-stderr-0.1.13.tgz#54e3450f3d4c54086a49c0c7f8786a44d1844b6f" 3621 + integrity sha512-Xnt9/HHHYfjZ7NeQLvuQDyL1LnbsbddgMFKCuaQKwGCdJm8LnstZIXop+uOY36UR1UXXoHXfMbC1KlVdVd2JLA== 3622 + dependencies: 3623 + debug "^4.1.1" 3624 + strip-ansi "^6.0.0" 3625 + 3618 3626 string-width@^1.0.1: 3619 3627 version "1.0.2" 3620 3628 resolved "https://registry.yarnpkg.com/string-width/-/string-width-1.0.2.tgz#118bdf5b8cdc51a2a7e70d211e07e2b0b9b107d3"