Skip to content

Commit

Permalink
Upgrade runner for type-tests wip
Browse files Browse the repository at this point in the history
  • Loading branch information
SleeplessByte committed Jul 31, 2024
1 parent bb05b2a commit 10237a8
Show file tree
Hide file tree
Showing 14 changed files with 435 additions and 90 deletions.
391 changes: 301 additions & 90 deletions bin/run.sh

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"core-js": "^3.37.1",
"jest": "^29.7.0",
"shelljs": "^0.8.5",
"tstyche": "^2.1.1",
"typescript": "~5.5.4"
},
"devDependencies": {
Expand Down
20 changes: 20 additions & 0 deletions test/fixtures/tstyche/documentation/__typetests__/docs.tst.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { expect, test } from "tstyche";

function firstItem<T>(target: Array<T>): T | undefined {
return target[0];
}

test("first item requires a parameter", () => {
expect(firstItem(["a", "b", "c"])).type.toBe<string | undefined>();

// @ts-expect-error
expect(firstItem()).type.toRaiseError("Expected 1 argument");
});

function secondItem<T>(target: Array<T>): T | undefined {
return target[1];
}

test("handles numbers", () => {
expect(secondItem([1, 2, 3])).type.toBe<number | undefined>();
});
10 changes: 10 additions & 0 deletions test/fixtures/tstyche/documentation/__typetests__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"noEmit": true,
"strict": true,
"types": []
},
"include": ["./"],
"exclude": []
}
10 changes: 10 additions & 0 deletions test/fixtures/tstyche/documentation/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
},
"exclude": ["./__typetests__"]
}
14 changes: 14 additions & 0 deletions test/fixtures/tstyche/fire/__typetests__/fire.tst.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { test, expect, describe } from 'tstyche'
import type { MethodLikeKeys } from '../fire.js'

interface Sample {
description: string
getLength: () => number
getWidth?: () => number
}

describe('fire', () => {
test('all method keys are found', () => {
expect<MethodLikeKeys<Sample>>().type.toBe<'getLength' | 'getWidth'>()
})
})
10 changes: 10 additions & 0 deletions test/fixtures/tstyche/fire/__typetests__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"noEmit": true,
"strict": true,
"types": []
},
"include": ["./"],
"exclude": []
}
5 changes: 5 additions & 0 deletions test/fixtures/tstyche/fire/fire.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type MethodLike = (...args: any) => any;

export type MethodLikeKeys<T> = keyof {
[K in keyof T as T[K] extends MethodLike ? K : never]: T[K];
};
10 changes: 10 additions & 0 deletions test/fixtures/tstyche/fire/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
},
"exclude": ["./__typetests__"]
}
14 changes: 14 additions & 0 deletions test/fixtures/tstyche/firefought/__typetests__/fire.tst.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { describe, test, expect } from "tstyche";
import type { MethodLikeKeys } from "../fire.js";

interface Sample {
description: string;
getLength: () => number;
getWidth?: () => number;
}

describe('fire', () => {
test('all method keys are found', () => {
expect<MethodLikeKeys<Sample>>().type.toBe<"getLength" | "getWidth">();
})
})
10 changes: 10 additions & 0 deletions test/fixtures/tstyche/firefought/__typetests__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"noEmit": true,
"strict": true,
"types": []
},
"include": ["./"],
"exclude": []
}
5 changes: 5 additions & 0 deletions test/fixtures/tstyche/firefought/fire.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type MethodLike = (...args: any) => any;

export type MethodLikeKeys<T> = keyof {
[K in keyof T as Required<T>[K] extends MethodLike ? K : never]: T[K];
};
10 changes: 10 additions & 0 deletions test/fixtures/tstyche/firefought/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
},
"exclude": ["./__typetests__"]
}
15 changes: 15 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,7 @@ __metadata:
prettier: "npm:^3.3.3"
rimraf: "npm:^6.0.1"
shelljs: "npm:^0.8.5"
tstyche: "npm:^2.1.1"
typescript: "npm:~5.5.4"
bin:
typescript-test-runner: bin/run.sh
Expand Down Expand Up @@ -6274,6 +6275,20 @@ __metadata:
languageName: node
linkType: hard

"tstyche@npm:^2.1.1":
version: 2.1.1
resolution: "tstyche@npm:2.1.1"
peerDependencies:
typescript: 4.x || 5.x
peerDependenciesMeta:
typescript:
optional: true
bin:
tstyche: ./build/bin.js
checksum: 10/f30e7d782e51c262528ededf383c9daf39af8dea063d483667e3ff9f4800434891589c294c4b4f69802dd06daf8fb1d2a10553316d2f4631ba1413d3e48dab81
languageName: node
linkType: hard

"type-check@npm:^0.4.0, type-check@npm:~0.4.0":
version: 0.4.0
resolution: "type-check@npm:0.4.0"
Expand Down

0 comments on commit 10237a8

Please sign in to comment.