Skip to content
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

Add exercises with type-tests #1520

Merged
merged 13 commits into from
Aug 1, 2024
  •  
  •  
  •  
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