Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const typescriptTemplate = {
main: 'app.ts',
scripts: {
clean: 'node -e "require(\'fs\').rmSync(\'dist\', {recursive: true, force: true})"',
test: 'npm run build:ts && tsc -p test/tsconfig.json && c8 node --test -r ts-node/register "test/**/*.ts"',
test: 'tsc -p test/tsconfig.json && c8 node --test -r ts-node/register "test/**/*.ts"',
start: 'npm run build:ts && fastify start -l info dist/app.js',
'build:ts': 'npm run clean && tsc',
'watch:ts': 'tsc -w',
Expand Down
8 changes: 7 additions & 1 deletion templates/app-ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ For production mode

### `npm run test`

Run the test cases.
Type check the application source and tests, then run the test cases directly
against the TypeScript source without generating production files in `dist`.

### `npm run build:ts`

Compile the application source to `dist`. This production build runs independently
of the tests and is also run by `npm start`.

## Learn More

Expand Down
2 changes: 1 addition & 1 deletion templates/app-ts/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"rootDir": "..",
"noEmit": true
},
"include": ["../src/**/*.ts", "**/*.ts"]
Expand Down
2 changes: 2 additions & 0 deletions templates/app-ts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"extends": "fastify-tsconfig",
"compilerOptions": {
"types": ["node"],
"rootDir": "src",
"outDir": "dist",
"sourceMap": true
},
Expand Down
8 changes: 5 additions & 3 deletions test/generate-typescript.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function define (t) {
})

test('should finish successfully with typescript template', async (t) => {
t.plan(26 + Object.keys(expected).length)
t.plan(28 + Object.keys(expected).length)
try {
await generate(workdir, typescriptTemplate)
await verifyPkg(t)
Expand All @@ -128,7 +128,7 @@ function define (t) {
// by default this will be ISC but since we have a MIT licensed pkg file in upper dir, npm will set the license to MIT in this case
// so for local tests we need to accept MIT as well
t.assert.ok(pkg.license === 'ISC' || pkg.license === 'MIT')
t.assert.strictEqual(pkg.scripts.test, 'npm run build:ts && tsc -p test/tsconfig.json && c8 node --test -r ts-node/register "test/**/*.ts"')
t.assert.strictEqual(pkg.scripts.test, 'tsc -p test/tsconfig.json && c8 node --test -r ts-node/register "test/**/*.ts"')
t.assert.strictEqual(pkg.scripts.start, 'npm run build:ts && fastify start -l info dist/app.js')
t.assert.strictEqual(pkg.scripts.clean, 'node -e "require(\'fs\').rmSync(\'dist\', {recursive: true, force: true})"')
t.assert.strictEqual(pkg.scripts['build:ts'], 'npm run clean && tsc')
Expand All @@ -146,7 +146,7 @@ function define (t) {
t.assert.strictEqual(pkg.devDependencies.concurrently, cliPkg.devDependencies.concurrently)
t.assert.strictEqual(pkg.devDependencies.typescript, cliPkg.devDependencies.typescript)

const testGlob = pkg.scripts.test.split(' ', 14)[13].replaceAll('"', '')
const testGlob = pkg.scripts.test.split(' ').at(-1).replaceAll('"', '')

t.assert.strictEqual(minimatch.match(['test/routes/plugins/more/test/here/ok.test.ts'], testGlob).length, 1, 'should match glob')
resolve()
Expand All @@ -162,6 +162,8 @@ function define (t) {
const tsConfig = JSON.parse(data)

t.assert.strictEqual(tsConfig.extends, 'fastify-tsconfig')
t.assert.deepStrictEqual(tsConfig.compilerOptions.types, ['node'])
t.assert.strictEqual(tsConfig.compilerOptions.rootDir, 'src')
t.assert.strictEqual(tsConfig.compilerOptions.outDir, 'dist')
t.assert.deepStrictEqual(tsConfig.include, ['src/**/*.ts'])
})
Expand Down
Loading