Skip to content

Commit

Permalink
Add exercises with type-tests (#1520)
Browse files Browse the repository at this point in the history
* Bump packages

* Sync

* Add mini test runner

* Add basics exericse

* Fix author field

* Add exercise to config.json

* Format files

* Regenerate locks

* Seed with content from JavaScript

* Fix package name

* Add TypeScript specific content

* They see me wip, they see me nae nae

* Use admonitions
  • Loading branch information
SleeplessByte authored Aug 1, 2024
1 parent 475ea7f commit bd55d5c
Show file tree
Hide file tree
Showing 326 changed files with 9,605 additions and 2,472 deletions.
54 changes: 54 additions & 0 deletions common/.meta/test-runner.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { execSync } from 'node:child_process'
// Experimental: import config from './config.json' with { type: 'json' }

import { readFileSync } from 'node:fs'
import { exit } from 'node:process'

/** @type {import('./config.json') } */
const config = JSON.parse(
readFileSync(new URL('./config.json', import.meta.url))
)

const jest = !config.custom || config.custom['flag.tests.jest']
const tstyche = config.custom?.['flag.tests.tstyche']

console.log(
`[tests] tsc: ✅, tstyche: ${tstyche ? '✅' : '❌'}, jest: ${jest ? '✅' : '❌'}, `
)

console.log('[tests] tsc (compile)')

try {
execSync('corepack yarn lint:types', {
stdio: 'inherit',
cwd: process.cwd(),
})
} catch {
exit(-1)
}

if (tstyche) {
console.log('[tests] tstyche (type tests)')

try {
execSync('corepack yarn test:types', {
stdio: 'inherit',
cwd: process.cwd(),
})
} catch {
exit(-2)
}
}

if (jest) {
console.log('[tests] tstyche (implementation tests)')

try {
execSync('corepack yarn test:implementation', {
stdio: 'inherit',
cwd: process.cwd(),
})
} catch {
exit(-3)
}
}
11 changes: 7 additions & 4 deletions common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,23 @@
},
"devDependencies": {
"@exercism/babel-preset-typescript": "^0.5.0",
"@exercism/eslint-config-typescript": "^0.7.0",
"@exercism/eslint-config-typescript": "^0.7.1",
"@jest/globals": "^29.7.0",
"@types/node": "~22.0.0",
"@types/node": "~22.0.2",
"babel-jest": "^29.7.0",
"core-js": "~3.37.1",
"eslint": "^9.8.0",
"expect": "^29.7.0",
"jest": "^29.7.0",
"prettier": "^3.3.3",
"tstyche": "^2.1.1",
"typescript": "~5.5.4",
"typescript-eslint": "^7.17.0"
"typescript-eslint": "^7.18.0"
},
"scripts": {
"test": "corepack yarn lint:types && jest --no-cache",
"test": "corepack yarn node .meta/test-runner.mjs",
"test:types": "corepack yarn tstyche",
"test:implementation": "corepack yarn jest --no-cache --passWithNoTests",
"lint": "corepack yarn lint:types && corepack yarn lint:ci",
"lint:types": "corepack yarn tsc --noEmit -p .",
"lint:ci": "corepack yarn eslint . --ext .tsx,.ts"
Expand Down
8 changes: 7 additions & 1 deletion common/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
// https://babeljs.io/docs/en/babel-plugin-transform-typescript/#caveats
"isolatedModules": true
},
"include": ["*.ts", "*.tsx", ".meta/*.ts", ".meta/*.tsx"],
"include": [
"*.ts",
"*.tsx",
".meta/*.ts",
".meta/*.tsx",
"__typetests__/*.tst.ts"
],
"exclude": ["node_modules"]
}
Loading

0 comments on commit bd55d5c

Please sign in to comment.