Skip to content

Commit 85b97fe

Browse files
authored
test: add typecheck test (#85)
1 parent 19b0ab9 commit 85b97fe

File tree

6 files changed

+331
-236
lines changed

6 files changed

+331
-236
lines changed

.github/workflows/ci.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
# https://github.com/vitejs/vite/blob/main/.github/workflows/ci.yml
12+
env:
13+
# 7 GiB by default on GitHub, setting to 6 GiB
14+
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
15+
NODE_OPTIONS: --max-old-space-size=6144
16+
17+
# Remove default permissions of GITHUB_TOKEN for security
18+
# https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs
19+
permissions: {}
20+
21+
jobs:
22+
typecheck:
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
27+
- run: corepack enable
28+
- uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
29+
with:
30+
node-version: 20
31+
cache: "pnpm"
32+
33+
- name: Install dependencies
34+
run: pnpm install
35+
36+
- name: Typecheck
37+
run: pnpm typecheck

.scripts/typecheck.mjs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { basename } from 'node:path'
2+
import { globby } from 'globby'
3+
import { exec } from 'tinyexec'
4+
import {consola} from 'consola'
5+
6+
const packages = await globby([
7+
'shared/**/package.json',
8+
'examples/**/package.json',
9+
'!**/node_modules',
10+
'!**/.nitro',
11+
'!**/.vercel',
12+
'!**/.output',
13+
], { absolute: true })
14+
15+
for (const pkg of packages) {
16+
const cwd = pkg.replace('/package.json', '')
17+
const options = { nodeOptions: { cwd } }
18+
19+
await exec('nuxi', ['prepare'], options)
20+
const res = await exec('tsc', ['--noEmit'], options)
21+
const output = (res.stderr).trim()
22+
if (output) {
23+
consola.withTag(basename(cwd)).error(output)
24+
process.exit(1)
25+
} else {
26+
consola.success('type checked', basename(cwd))
27+
}
28+
}

examples/advanced/jsx/components/MyComponent.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ export default defineComponent({
22
props: {
33
message: String
44
},
5-
render: (props) => {
5+
// @ts-expect-error investigate why this is not typed
6+
render(props) {
67
return (
78
<div>
89
{ props.message }

examples/hello-world/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "./.nuxt/tsconfig.json"
3+
}

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@
44
"version": "1.0.0",
55
"license": "MIT",
66
"scripts": {
7-
"build": "turbo run build && node .scripts/build.mjs"
7+
"build": "turbo run build && node .scripts/build.mjs",
8+
"typecheck": "node .scripts/typecheck.mjs"
89
},
910
"devDependencies": {
1011
"@nuxt/kit": "3.12.2",
1112
"@types/node": "^20.11.30",
13+
"consola": "^3.2.3",
1214
"globby": "^14.0.1",
1315
"pathe": "^1.1.2",
1416
"pkg-types": "^1.0.3",
15-
"turbo": "^2.1.2"
17+
"tinyexec": "^0.3.0",
18+
"turbo": "^2.1.2",
19+
"typescript": "^5.6.2"
1620
},
1721
"resolutions": {
1822
"@nuxt/kit": "3.12.2",

0 commit comments

Comments
 (0)