-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Upgrade runner for type-tests wip * Make .ts import work again * Fix fallback check, fix tsconfig unlinking * Clean-up formatting * Implement tstyche support * Use tsconfig.solutions.json * Update expected results * Inline the config files * Support for skipping only when the exercise allows it * Add flags to todos
- Loading branch information
1 parent
bb05b2a
commit bb4d160
Showing
26 changed files
with
640 additions
and
103 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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,14 @@ | ||
{ | ||
"authors": [ | ||
"SleeplessByte" | ||
], | ||
"files": { | ||
"solution": [ | ||
], | ||
"test": [ | ||
"__typetests__/docs.tst.ts" | ||
], | ||
"example": [ | ||
] | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
test/fixtures/tstyche/documentation/__typetests__/docs.tst.ts
This file contains 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,19 @@ | ||
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>(); | ||
|
||
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
10
test/fixtures/tstyche/documentation/__typetests__/tsconfig.json
This file contains 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,10 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"noEmit": true, | ||
"strict": true, | ||
"types": [] | ||
}, | ||
"include": ["./"], | ||
"exclude": [] | ||
} |
This file contains 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 @@ | ||
export {} |
This file contains 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,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2016", | ||
"module": "commonjs", | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true | ||
}, | ||
"exclude": ["./__typetests__"] | ||
} |
This file contains 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,15 @@ | ||
{ | ||
"authors": [ | ||
"SleeplessByte" | ||
], | ||
"files": { | ||
"solution": [ | ||
"fire.ts" | ||
], | ||
"test": [ | ||
"__typetests__/fire.tst.ts" | ||
], | ||
"example": [ | ||
] | ||
} | ||
} |
This file contains 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,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'>() | ||
}) | ||
}) |
This file contains 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,10 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"noEmit": true, | ||
"strict": true, | ||
"types": [] | ||
}, | ||
"include": ["./"], | ||
"exclude": [] | ||
} |
This file contains 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,5 @@ | ||
type MethodLike = (...args: any) => any; | ||
|
||
export type MethodLikeKeys<T> = keyof { | ||
[K in keyof T as T[K] extends MethodLike ? K : never]: T[K]; | ||
}; |
This file contains 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,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2016", | ||
"module": "commonjs", | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true | ||
}, | ||
"exclude": ["./__typetests__"] | ||
} |
This file contains 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,15 @@ | ||
{ | ||
"authors": [ | ||
"SleeplessByte" | ||
], | ||
"files": { | ||
"solution": [ | ||
"fire.ts" | ||
], | ||
"test": [ | ||
"__typetests__/fire.tst.ts" | ||
], | ||
"example": [ | ||
] | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
test/fixtures/tstyche/firefought/__typetests__/fire.tst.ts
This file contains 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,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
10
test/fixtures/tstyche/firefought/__typetests__/tsconfig.json
This file contains 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,10 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"noEmit": true, | ||
"strict": true, | ||
"types": [] | ||
}, | ||
"include": ["./"], | ||
"exclude": [] | ||
} |
This file contains 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,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]; | ||
}; |
This file contains 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,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2016", | ||
"module": "commonjs", | ||
"forceConsistentCasingInFileNames": true, | ||
"strict": true, | ||
"skipLibCheck": true | ||
}, | ||
"exclude": ["./__typetests__"] | ||
} |
This file contains 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 +1 @@ | ||
{ "version": 1, "status": "error", "message": "The submitted code didn't compile. We have collected the errors encountered during compilation. At this moment the error messages are not very read-friendly, but it's a start. We are working on a more helpful output.\n-------------------------------\ntwo-fer.ts(1,14): error TS1389: 'const' is not allowed as a variable declaration name.\ntwo-fer.ts(1,20): error TS1134: Variable declaration expected.\ntwo-fer.ts(1,29): error TS1109: Expression expected.\ntwo-fer.ts(2,1): error TS1005: ')' expected." } | ||
{ "version": 1, "status": "error", "message": "The submitted code didn't compile. We have collected the errors encountered during compilation. At this moment the error messages are not very read-friendly, but it's a start. We are working on a more helpful output.\n-------------------------------\ntwo-fer.ts(1,14): error TS1389: 'const' is not allowed as a variable declaration name.\ntwo-fer.ts(1,20): error TS1134: Variable declaration expected.\ntwo-fer.ts(1,29): error TS1109: Expression expected.\ntwo-fer.ts(2,1): error TS1005: ')' expected.\n" } |
This file contains 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 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,13 @@ | ||
import { join } from 'node:path' | ||
import shelljs from 'shelljs' | ||
import { assertError, assertPass } from './asserts.mjs' | ||
import { fixtures } from './paths.mjs' | ||
|
||
shelljs.echo('type tests (only) > documentation solution (smoke test)') | ||
assertPass('tstyche', join(fixtures, 'tstyche', 'documentation')) | ||
|
||
shelljs.echo('type tests (only) > failing solution') | ||
assertError('tstyche', join(fixtures, 'tstyche', 'fire')) | ||
|
||
shelljs.echo('type tests (only) > passing solution') | ||
assertPass('tstyche', join(fixtures, 'tstyche', 'firefought')) |
This file contains 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,31 @@ | ||
{ | ||
"extends": "@tsconfig/node20/tsconfig.json", | ||
"compilerOptions": { | ||
// Allows you to use the newest syntax, and have access to console.log | ||
// https://www.typescriptlang.org/tsconfig#lib | ||
"lib": ["ES2020", "dom"], | ||
// Make sure typescript is configured to output ESM | ||
// https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#how-can-i-make-my-typescript-project-output-esm | ||
"module": "Node16", | ||
// Since this project is using babel, TypeScript may target something very | ||
// high, and babel will make sure it runs on your local Node version. | ||
// https://babeljs.io/docs/en/ | ||
"target": "ES2020", // ESLint doesn't support this yet: "es2022", | ||
|
||
"strict": true, | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true, | ||
|
||
// Because jest-resolve isn't like node resolve, the absolute path must be .ts | ||
"allowImportingTsExtensions": true, | ||
"noEmit": true, | ||
|
||
// Because we'll be using babel: ensure that Babel can safely transpile | ||
// files in the TypeScript project. | ||
// | ||
// https://babeljs.io/docs/en/babel-plugin-transform-typescript/#caveats | ||
"isolatedModules": true | ||
}, | ||
"exclude": [".meta/*", "__typetests__/*", "*.test.ts", "*.tst.ts"] | ||
} |
This file contains 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