-
Notifications
You must be signed in to change notification settings - Fork 0
chore(test): カバレッジ計測の母数を整備する (#1038) #1047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,9 +1,14 @@ | ||
| import { defineConfig } from "vitest/config"; | ||
| import { createCoverageConfig } from "../../vitest.coverage.shared"; | ||
|
|
||
| export default defineConfig({ | ||
| root: import.meta.dirname, | ||
| test: { | ||
| environment: "node", | ||
| include: ["src/**/*.test.ts"], | ||
| coverage: createCoverageConfig({ | ||
| include: ["src/**/*.ts"], | ||
| exclude: ["src/index.ts"], | ||
| }), | ||
| }, | ||
| }); |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,9 +1,13 @@ | ||
| import { defineConfig } from "vitest/config"; | ||
| import { createCoverageConfig } from "../../vitest.coverage.shared"; | ||
|
|
||
| export default defineConfig({ | ||
| root: import.meta.dirname, | ||
| test: { | ||
| environment: "node", | ||
| include: ["src/**/*.test.ts"], | ||
| coverage: createCoverageConfig({ | ||
| include: ["src/**/*.ts"], | ||
| }), | ||
| }, | ||
| }); |
This file contains hidden or 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 hidden or 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,104 @@ | ||
| #!/usr/bin/env node | ||
| /** | ||
| * Run Vitest with coverage for every workspace that participates in the | ||
| * monorepo test matrix. Exits non-zero if any workspace fails. | ||
| * | ||
| * モノレポのテスト対象ワークスペースすべてで Vitest coverage を実行する。 | ||
| * いずれかが失敗したら非ゼロで終了する。 | ||
| */ | ||
| import { spawnSync } from "node:child_process"; | ||
| import path from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
|
|
||
| const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); | ||
|
|
||
| /** @type {Array<{ name: string; cwd?: string; args: string[]; preInstall?: boolean }>} */ | ||
| const workspaces = [ | ||
| { name: "src/ (frontend)", args: ["vitest", "run", "--coverage"] }, | ||
| { | ||
| name: "admin", | ||
| args: ["vitest", "run", "--coverage", "--config", "admin/vitest.config.ts"], | ||
| }, | ||
| { | ||
| name: "@zedi/shared", | ||
| args: ["vitest", "run", "--coverage", "--config", "packages/shared/vitest.config.ts"], | ||
| }, | ||
| { | ||
| name: "@zedi/ui", | ||
| args: ["vitest", "run", "--coverage", "--config", "packages/ui/vitest.config.ts"], | ||
| }, | ||
| { | ||
| name: "@zedi/claude-sidecar", | ||
| args: ["vitest", "run", "--coverage", "--config", "packages/claude-sidecar/vitest.config.ts"], | ||
| }, | ||
| ]; | ||
|
|
||
| const serverWorkspaces = [ | ||
| { | ||
| name: "server/hocuspocus", | ||
| cwd: "server/hocuspocus", | ||
| preInstall: true, | ||
| args: ["vitest", "run", "--coverage", "--config", "vitest.config.ts"], | ||
| }, | ||
| { | ||
| name: "server/mcp", | ||
| cwd: "server/mcp", | ||
| preInstall: true, | ||
| args: ["vitest", "run", "--coverage", "--config", "vitest.config.ts"], | ||
| }, | ||
| { | ||
| name: "server/api", | ||
| cwd: "server/api", | ||
| preInstall: true, | ||
| args: ["vitest", "run", "--coverage"], | ||
| }, | ||
| ]; | ||
|
|
||
| const includeServers = process.argv.includes("--with-servers"); | ||
| const targets = includeServers ? [...workspaces, ...serverWorkspaces] : workspaces; | ||
|
|
||
| const spawnShell = process.platform === "win32"; | ||
|
|
||
| /** | ||
| * @param {import("node:child_process").SpawnSyncReturns<Buffer | string>} result | ||
| */ | ||
| function exitOnSpawnFailure(result) { | ||
| if (result.error) { | ||
| console.error(result.error); | ||
| process.exit(1); | ||
| } | ||
| if (result.status !== 0) { | ||
| process.exit(result.status ?? 1); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @param {string} label | ||
| * @param {string[]} command | ||
| * @param {string} cwd | ||
| */ | ||
| function run(label, command, cwd) { | ||
| console.log(`\n=== Coverage: ${label} ===\n`); | ||
| const result = spawnSync("bunx", command, { | ||
| cwd, | ||
| stdio: "inherit", | ||
| env: process.env, | ||
| shell: spawnShell, | ||
| }); | ||
| exitOnSpawnFailure(result); | ||
| } | ||
|
|
||
| for (const workspace of targets) { | ||
| const cwd = path.join(repoRoot, workspace.cwd ?? "."); | ||
| if (workspace.preInstall) { | ||
| console.log(`\n--- Installing dependencies for ${workspace.name} ---\n`); | ||
| const install = spawnSync("bun", ["install", "--frozen-lockfile"], { | ||
| cwd, | ||
| stdio: "inherit", | ||
| env: process.env, | ||
| shell: spawnShell, | ||
| }); | ||
| exitOnSpawnFailure(install); | ||
| } | ||
|
Comment on lines
+93
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 依存関係のインストール処理( if (workspace.preInstall) {
console.log("\\n--- Installing dependencies for \${workspace.name} ---\\n");
const install = spawnSync("bun", ["install", "--frozen-lockfile"], {
cwd,
stdio: "inherit",
env: process.env,
shell: process.platform === "win32",
});
if (install.error) {
console.error(install.error);
process.exit(1);
}
if (install.status !== 0) {
process.exit(install.status ?? 1);
}
} |
||
| run(workspace.name, workspace.args, cwd); | ||
| } | ||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,9 +1,14 @@ | ||
| import { defineConfig } from "vitest/config"; | ||
| import { createCoverageConfig } from "../../vitest.coverage.shared"; | ||
|
|
||
| export default defineConfig({ | ||
| test: { | ||
| globals: true, | ||
| environment: "node", | ||
| include: ["src/**/*.{test,spec}.{ts,tsx}", "scripts/**/*.{test,spec}.{ts,tsx}"], | ||
| coverage: createCoverageConfig({ | ||
| include: ["src/**/*.ts", "scripts/**/*.ts"], | ||
| exclude: ["src/types/**", "src/index.ts"], | ||
| }), | ||
| }, | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Windows環境において、
bunやbunxなどのコマンドをspawnSyncで直接実行すると、シェル経由でないためにENOENTエラーが発生して実行に失敗することがあります。また、コマンドの起動自体に失敗した場合(result.errorが存在する場合)、エラー内容がコンソールに出力されず、終了コード1でサイレントに終了してしまいます。\n\nこれを防ぐために、Windows環境ではshell: trueを有効にし、result.errorが存在する場合はエラー内容を出力するように改善することを推奨します。