Skip to content
Draft
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
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
"test": "test"
},
"scripts": {
"test": "yarn build:test && FASTIFY_AUTOLOAD_TYPESCRIPT=1 node --test --experimental-test-coverage 'dist/test/**/*.js'",
"build": "tsc",
"build:test": "yarn build && node scripts/copy-test-assets.js && tsc -p test/tsconfig.json",
"test": "FASTIFY_AUTOLOAD_TYPESCRIPT=1 tsx --test --experimental-test-coverage test/**/*.test.ts",
"build": "node scripts/build.js",
"watch": "tsc -w",
"start": "fastify start -l info dist/src/app.js --options",
"dev": "yarn run build && concurrently -k -p '[{name}]' -n TypeScript,App -c yellow.bold,cyan.bold yarn:watch yarn:dev:start",
Expand Down Expand Up @@ -52,6 +51,7 @@
"@types/jsonwebtoken": "^9.0.10",
"@types/node": "^24.10.1",
"concurrently": "^9.2.1",
"esbuild": "^0.27.3",
"eslint": "^9.39.1",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-prettier": "^5.5.4",
Expand All @@ -60,6 +60,7 @@
"husky": "^9.1.7",
"prettier": "^3.7.4",
"prettier-plugin-jsdoc": "^1.7.0",
"tsx": "^4.21.0",
"typescript": "^5.9.3",
"typescript-eslint": "^8.48.1"
},
Expand Down
28 changes: 28 additions & 0 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { build } from "esbuild";
import { copyFile, glob, rm } from "node:fs/promises";
import path from "node:path";

const distDir = path.resolve("dist");

try {
await rm(distDir, { recursive: true, force: true });

const entryPoints = [];
for await (const file of glob("src/**/*.ts")) {
entryPoints.push(file);
}

await build({
entryPoints,
outdir: distDir,
outbase: ".",
platform: "node",
format: "esm",
sourcemap: true,
});
Comment on lines 15 to 22
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/app.ts imports ../package.json (relative to dist/src/app.js at runtime this becomes dist/package.json). The build script writes to dist/src but does not copy package.json into dist/, so yarn start / the Docker runner stage will fail with a missing JSON module at runtime. Consider copying package.json to dist/package.json as part of the build (or otherwise adjusting how app metadata is loaded so it resolves correctly after build).

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build script now copies package.json into dist after building so the runtime JSON import resolves (35e50c8).


await copyFile("package.json", path.join(distDir, "package.json"));
} catch (error) {
console.error(error);
process.exitCode = 1;
}
25 changes: 0 additions & 25 deletions scripts/copy-test-assets.js

This file was deleted.

27 changes: 10 additions & 17 deletions test/helper.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
// This file contains code that we reuse between our tests.
import { AppOptions } from "../src/app.js";
import helper from "fastify-cli/helper.js";
import app, { AppOptions, options } from "../src/app.js";
import Fastify from "fastify";
import * as test from "node:test";
import * as path from "path";
import { fileURLToPath } from "url";

export type TestContext = {
after: typeof test.after;
};

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const AppPath = path.join(__dirname, "..", "src", "app.js");

// Fill in this config with all the configurations
// needed for testing the application
async function config(): Promise<AppOptions> {
Expand All @@ -26,18 +20,17 @@ async function config(): Promise<AppOptions> {

// Automatically build and tear down our instance
async function build(t: TestContext) {
// you can set all the options supported by the fastify CLI command
const argv = [AppPath];

// fastify-plugin ensures that all decorators
// are exposed for testing purposes, this is
// different from the production setup
const app = await helper.build(argv, await config(), await config());
const fastify = Fastify({ pluginTimeout: options.pluginTimeout });
const appConfig = await config();
await fastify.register(app, appConfig);
await fastify.ready();

// Tear down our app after we are done
t.after(() => void app.close());
t.after(async () => {
await fastify.close();
});

return app;
return fastify;
}

export { config, build };
Loading
Loading