mirror of
https://github.com/kou029w/_.git
synced 2025-01-30 22:08:02 +00:00
use stdout-stderr
This commit is contained in:
parent
3e29baac96
commit
15a69ddc1e
7 changed files with 35 additions and 31 deletions
|
@ -25,6 +25,7 @@
|
||||||
"esbuild-register": "^3.3.2",
|
"esbuild-register": "^3.3.2",
|
||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
"oclif": "^3.0.0",
|
"oclif": "^3.0.0",
|
||||||
|
"stdout-stderr": "^0.1.13",
|
||||||
"tsup": "^5.12.5",
|
"tsup": "^5.12.5",
|
||||||
"typescript": "^4.6.3",
|
"typescript": "^4.6.3",
|
||||||
"vitest": "^0.9.3"
|
"vitest": "^0.9.3"
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { test, expect } from "vitest";
|
import { test, expect } from "vitest";
|
||||||
import run from "../../run";
|
import { stdout } from "stdout-stderr";
|
||||||
import Hello from "../../../src/commands/hello/index";
|
import Hello from "../../../src/commands/hello/index";
|
||||||
|
|
||||||
test("hello", async () => {
|
test("hello", async () => {
|
||||||
const res = await run(() => Hello.run(["friend", "--from=oclif"]));
|
await Hello.run(["friend", "--from=oclif"]);
|
||||||
expect(res).toContain("hello friend from oclif!");
|
expect(stdout.output).toContain("hello friend from oclif!");
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,13 +1,8 @@
|
||||||
import { test, expect } from "vitest";
|
import { test, expect } from "vitest";
|
||||||
import run from "../../run";
|
import { stdout } from "stdout-stderr";
|
||||||
import World from "../../../src/commands/hello/world";
|
import World from "../../../src/commands/hello/world";
|
||||||
|
|
||||||
test("hello world", async () => {
|
test("hello world", async () => {
|
||||||
const res = await run(() => World.run());
|
await World.run();
|
||||||
expect(res).toContain("hello world!");
|
expect(stdout.output).toContain("hello world!");
|
||||||
});
|
|
||||||
|
|
||||||
test("hello world", async () => {
|
|
||||||
const res = await run(() => World.run());
|
|
||||||
expect(res).toContain("hello world!");
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
import { vi } from "vitest";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 標準出力のテストのためのヘルパー
|
|
||||||
* @param proc 実行する関数
|
|
||||||
* @return 標準出力の結果
|
|
||||||
*/
|
|
||||||
async function run(proc: () => PromiseLike<void>): Promise<string> {
|
|
||||||
const out: string[] = [];
|
|
||||||
const stdout = vi.spyOn(process.stdout, "write").mockImplementation((val) => {
|
|
||||||
out.push(val as string);
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
await proc();
|
|
||||||
stdout.mockRestore();
|
|
||||||
return out.join("");
|
|
||||||
}
|
|
||||||
|
|
||||||
export default run;
|
|
12
oclif/tests/setup.ts
Normal file
12
oclif/tests/setup.ts
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
import { afterEach, beforeEach } from "vitest";
|
||||||
|
import { stdout, stderr } from "stdout-stderr";
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
stdout.start();
|
||||||
|
stderr.start();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
stdout.stop();
|
||||||
|
stderr.stop();
|
||||||
|
});
|
7
oclif/vitest.config.ts
Normal file
7
oclif/vitest.config.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import { defineConfig } from "vite";
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
test: {
|
||||||
|
setupFiles: "tests/setup.ts",
|
||||||
|
},
|
||||||
|
});
|
|
@ -3615,6 +3615,14 @@ ssri@^9.0.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
minipass "^3.1.1"
|
minipass "^3.1.1"
|
||||||
|
|
||||||
|
stdout-stderr@^0.1.13:
|
||||||
|
version "0.1.13"
|
||||||
|
resolved "https://registry.yarnpkg.com/stdout-stderr/-/stdout-stderr-0.1.13.tgz#54e3450f3d4c54086a49c0c7f8786a44d1844b6f"
|
||||||
|
integrity sha512-Xnt9/HHHYfjZ7NeQLvuQDyL1LnbsbddgMFKCuaQKwGCdJm8LnstZIXop+uOY36UR1UXXoHXfMbC1KlVdVd2JLA==
|
||||||
|
dependencies:
|
||||||
|
debug "^4.1.1"
|
||||||
|
strip-ansi "^6.0.0"
|
||||||
|
|
||||||
string-width@^1.0.1:
|
string-width@^1.0.1:
|
||||||
version "1.0.2"
|
version "1.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/string-width/-/string-width-1.0.2.tgz#118bdf5b8cdc51a2a7e70d211e07e2b0b9b107d3"
|
resolved "https://registry.yarnpkg.com/string-width/-/string-width-1.0.2.tgz#118bdf5b8cdc51a2a7e70d211e07e2b0b9b107d3"
|
||||||
|
|
Loading…
Add table
Reference in a new issue