Skip to content

Commit bb4d160

Browse files
Upgrade runner for type-tests (#73)
* 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
1 parent bb05b2a commit bb4d160

File tree

26 files changed

+640
-103
lines changed

26 files changed

+640
-103
lines changed

bin/run.sh

Lines changed: 392 additions & 95 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"prepublish": "corepack yarn test:bare && corepack yarn lint",
2525
"lint": "corepack yarn eslint src -c eslint.config.mjs && corepack yarn eslint test -c eslint.config.mjs",
2626
"test": "corepack yarn build && corepack yarn test:bare",
27-
"test:bare": "corepack yarn node test/smoke.test.mjs && corepack yarn node test/skip.test.mjs && corepack yarn node test/import.test.mjs"
27+
"test:bare": "corepack yarn node test/smoke.test.mjs && corepack yarn node test/skip.test.mjs && corepack yarn node test/import.test.mjs && corepack yarn node test/types.test.mjs"
2828
},
2929
"dependencies": {
3030
"@exercism/babel-preset-typescript": "^0.5.0",
@@ -40,6 +40,7 @@
4040
"core-js": "^3.37.1",
4141
"jest": "^29.7.0",
4242
"shelljs": "^0.8.5",
43+
"tstyche": "^2.1.1",
4344
"typescript": "~5.5.4"
4445
},
4546
"devDependencies": {

src/output.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ type ExerciseConfig = {
3131
'flag.tests.task-per-describe': boolean
3232
'flag.tests.may-run-long': boolean
3333
'flag.tests.includes-optional': boolean
34+
'flag.tests.jest'?: boolean
35+
'flag.tests.tstyche'?: boolean
3436
}
3537
}
3638

@@ -66,11 +68,9 @@ export class Output {
6668
this.results.status =
6769
aggregatedResults.numRuntimeErrorTestSuites === 0 &&
6870
aggregatedResults.numFailedTestSuites === 0 &&
69-
// Pending tests are skipped tests. test.skip tests are fine in our
70-
// reporter and should not be forced to have ran here. So the next
71-
// line is commented out.
71+
// Pending tests are skipped tests. test.skip tests are fine if the
72+
// exercise reports that there are optional tests.
7273
//
73-
// aggregatedResults.numPendingTests === 0 &&
7474
aggregatedResults.numFailedTests === 0
7575
? 'pass'
7676
: 'fail'
@@ -88,6 +88,24 @@ export class Output {
8888
'an issue if the problem persists.'
8989
)
9090
}
91+
92+
if (
93+
this.results.status === 'pass' &&
94+
(aggregatedResults.numPendingTests !== 0 ||
95+
aggregatedResults.numPendingTestSuites !== 0)
96+
) {
97+
if (
98+
!this.configFlag('flag.tests.includes-optional') &&
99+
this.config?.custom
100+
) {
101+
this.results.status = 'fail'
102+
this.error(
103+
'Expected to see 0 skipped tests and 0 skipped test suites. ' +
104+
'None of the tests in this exercise are optional. The skipped ' +
105+
'tests will not show up, but were found during the last run.'
106+
)
107+
}
108+
}
91109
}
92110

93111
const parsedSources: Record<
File renamed without changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"authors": [
3+
"SleeplessByte"
4+
],
5+
"files": {
6+
"solution": [
7+
],
8+
"test": [
9+
"__typetests__/docs.tst.ts"
10+
],
11+
"example": [
12+
]
13+
}
14+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { expect, test } from "tstyche";
2+
3+
function firstItem<T>(target: Array<T>): T | undefined {
4+
return target[0];
5+
}
6+
7+
test("first item requires a parameter", () => {
8+
expect(firstItem(["a", "b", "c"])).type.toBe<string | undefined>();
9+
10+
expect(firstItem()).type.toRaiseError("Expected 1 argument");
11+
});
12+
13+
function secondItem<T>(target: Array<T>): T | undefined {
14+
return target[1];
15+
}
16+
17+
test("handles numbers", () => {
18+
expect(secondItem([1, 2, 3])).type.toBe<number | undefined>();
19+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"noEmit": true,
5+
"strict": true,
6+
"types": []
7+
},
8+
"include": ["./"],
9+
"exclude": []
10+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {}

0 commit comments

Comments
 (0)