Repository navigation
fix: compile existing type assertions in normal test commands (CORE-01) #16
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
Draft
YLfjuk
wants to merge
3
commits into
main
Choose a base branch
from
fix/core-01-type-assertion-discovery
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+155
−12
Draft
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
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,7 @@ | ||
| { | ||
| "extends": "./tsconfig.json", | ||
| "compilerOptions": { | ||
| "noEmit": true | ||
| }, | ||
| "include": ["src", "tests"] | ||
| } |
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,12 +1,24 @@ | ||
| import { describe, expectTypeOf, it } from "vitest"; | ||
|
|
||
| import type { IsDisjointUnion } from "../src/is-disjoint-union"; | ||
| import type { LastOfUnion } from "../src/last-of-union"; | ||
|
|
||
| describe("LastOfUnion", () => { | ||
| it("should extract the last element in a union", () => { | ||
| type Actual = LastOfUnion<1 | 2 | 3 | 4 | 5 | "bob" | 6>; | ||
| type Expected = 6; | ||
| it("should extract one member from a union", () => { | ||
| type Members = 1 | 2 | 3 | 4 | 5 | "bob" | 6; | ||
| type Actual = LastOfUnion<Members>; | ||
|
|
||
| expectTypeOf<Actual>().toEqualTypeOf<Expected>(); | ||
| // Union ordering is not guaranteed by TypeScript. | ||
| expectTypeOf<Actual>().toExtend<Members>(); | ||
| expectTypeOf<Actual>().not.toBeNever(); | ||
| expectTypeOf<IsDisjointUnion<Actual>>().toEqualTypeOf<false>(); | ||
| }); | ||
|
|
||
| it("should preserve a single member", () => { | ||
| expectTypeOf<LastOfUnion<"bob">>().toEqualTypeOf<"bob">(); | ||
| }); | ||
|
|
||
| it("should return never for an empty union", () => { | ||
| expectTypeOf<LastOfUnion<never>>().toBeNever(); | ||
| }); | ||
| }); | ||
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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "extends": "./tsconfig.json", | ||
| "compilerOptions": { | ||
| "noEmit": true | ||
| }, | ||
| "include": ["src", "__tests__"] | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "extends": "./tsconfig.json", | ||
| "compilerOptions": { | ||
| "noEmit": true | ||
| }, | ||
| "include": ["src", "__tests__"] | ||
| } |
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,69 @@ | ||
| import assert from "node:assert/strict"; | ||
| import { spawnSync } from "node:child_process"; | ||
| import { randomUUID } from "node:crypto"; | ||
| import { unlinkSync, writeFileSync } from "node:fs"; | ||
| import { fileURLToPath } from "node:url"; | ||
|
|
||
| const root = fileURLToPath(new URL("../", import.meta.url)); | ||
| const npmExecPath = process.env.npm_execpath; | ||
| assert.ok(npmExecPath, "Run this check via `pnpm run test:discovery` (npm_execpath is unset)."); | ||
| const [command, ...prefixArgs] = /\.[cm]?js$/i.test(npmExecPath) | ||
| ? [process.execPath, npmExecPath] | ||
| : [npmExecPath]; | ||
| const fixtures = []; | ||
|
|
||
| function pnpm(...args) { | ||
| const result = spawnSync(command, [...prefixArgs, ...args], { | ||
| cwd: root, | ||
| encoding: "utf8", | ||
| timeout: 60_000, | ||
| env: { ...process.env, NO_COLOR: "1", FORCE_COLOR: "0" }, | ||
| }); | ||
| assert.ifError(result.error); | ||
| assert.equal(result.status, 1, result.stdout + result.stderr); | ||
| return result.stdout + result.stderr; | ||
| } | ||
|
|
||
| try { | ||
| for (const [name, directory] of [ | ||
| ["types", "__tests__"], | ||
| ["utils", "__tests__"], | ||
| ["core", "tests"], | ||
| ]) { | ||
| const filename = `${name}-typecheck-discovery-${randomUUID()}.spec.ts`; | ||
| const path = new URL(`../packages/${name}/${directory}/${filename}`, import.meta.url); | ||
| writeFileSync( | ||
| path, | ||
| 'import { expectTypeOf, it } from "vitest";\nit("typecheck discovery", () => {\nexpectTypeOf<number>().toEqualTypeOf<string>();\n});\n', | ||
| { flag: "wx" }, | ||
| ); | ||
| fixtures.push({ filename, path }); | ||
| const output = pnpm("--dir", `packages/${name}`, "run", "test:types"); | ||
| assert.ok(output.includes(`${filename}(3,`) && output.includes("error TS2344"), output); | ||
| console.log(`${name}: test:types rejected the invalid assertion`); | ||
| } | ||
|
|
||
| const output = pnpm("exec", "vitest", "run", ...fixtures.map(({ filename }) => filename)); | ||
| for (const { filename } of fixtures) { | ||
| assert.match( | ||
| output, | ||
| new RegExp(`FAIL[^\n]*${filename.replaceAll(".", "\\.")}[^\n]*\r?\nTypeCheckError:`), | ||
| ); | ||
| } | ||
| console.log("Root Vitest rejected the invalid assertion in all three projects"); | ||
| } finally { | ||
| const errors = []; | ||
| for (const { path } of fixtures) { | ||
| try { | ||
| unlinkSync(path); | ||
| } catch (error) { | ||
| errors.push(error); | ||
| } | ||
| } | ||
| if (errors.length) { | ||
| console.error( | ||
| new AggregateError(errors, "Could not remove all typecheck discovery fixtures"), | ||
| ); | ||
| process.exitCode = 1; | ||
| } | ||
| } |
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.
then this type is kind of useless