chore: cover test files in default tsconfig#58
Merged
Conversation
VS Code's TS server walks up from a test file to the default-named tsconfig.json, which was the build config (include: ["src"]). Test files fell outside that include and landed in an inferred project with no @types/node and wrong module settings, so the editor flagged spurious errors on test files (e.g. Cannot find name 'node:assert/strict'). typecheck was clean only because it passed -p tsconfig.test.json, which the editor never auto-discovers. Flip the defaults so the auto-discovered config covers both src and test: - tsconfig.json is now the editor/typecheck config: standalone, include ["src", "test"], noEmit, rootDir ".", types ["node"]. - tsconfig.build.json emits dist from src only (extends tsconfig.json, overrides noEmit/rootDir/outDir/declaration). Replaces the build options that used to live in tsconfig.json. - Drop tsconfig.test.json (folded into tsconfig.json). - build -> tsc -p tsconfig.build.json; typecheck -> tsc. Emitted dist is byte-identical to before. Verified: npm run build (same four dist files, no test files emitted), npm run typecheck (passes, now lists test/index.test.ts), npm test, npm run test:pack.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What this does
Makes the auto-discovered
tsconfig.jsoncover bothsrcandtest, so the VS Code TS language server type-checks test files correctly.The editor walks up from a test file and resolves the default-named
tsconfig.json. That was the build config (include: ["src"]), so test files fell outside the include and landed in an inferred project with no@types/nodeand wrong module settings, producing spurious errors on test files (e.g.Cannot find name 'node:assert/strict').npm run typecheckwas clean only because it explicitly passed-p tsconfig.test.json, which the editor never auto-discovers.This flips which config is the default:
tsconfig.jsonbecomes the editor/typecheck config coveringsrcandtest, and a newtsconfig.build.jsonemits dist fromsrconly. The published package is byte-identical.Changes
tsconfig.jsonis now standalone (noextends):include: ["src", "test"],noEmit,rootDir: ".",types: ["node"]. Inlines the compiler options the test config used to inherit; emit-only options moved to the build config.tsconfig.build.json:extends: "./tsconfig.json",include: ["src"], overridesnoEmit: false,rootDir: "src",outDir: "dist",declaration: true. Emits exactly what the oldtsconfig.jsondid.tsconfig.test.json(folded intotsconfig.json).package.jsonscripts:build->tsc -p tsconfig.build.json;typecheck->tsc.Verification
npm run build-> same four dist files as before (index/factory,.js+.d.ts), all byte-identical, no test files emitted.npm run typecheck-> passes;tsc -p tsconfig.json --listFilesOnlynow includestest/index.test.ts.npm test-> 13 passing.npm run test:pack-> runtime import + type resolution ok.