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

First test #24

Merged
merged 6 commits into from
Oct 28, 2023
Merged
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: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI

on:
push:
branches: ['main']
branches: [main]
pull_request:
types: [opened, synchronize]
workflow_dispatch:
Expand All @@ -26,7 +26,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: 20.x
cache: 'pnpm'
cache: pnpm

- name: Get pnpm store directory
shell: bash
Expand All @@ -51,3 +51,6 @@ jobs:

- name: 💼 Type Check
run: pnpm build:type-check

# - name: 🧪 Test
# run: pnpm test
8 changes: 8 additions & 0 deletions apps/core/.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"exit": true,
"timeout": 5000,
"extension": ["ts"],
"spec": ["test/**/*.spec.ts"],
"node-option": ["import=tsx,env-file=.env"],
"reporter": "spec"
}
9 changes: 7 additions & 2 deletions apps/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"start:watch": "node --env-file=.env.production --watch dist/server.js",
"test": "NODE_ENV=test mocha",
"test:watch": "NODE_ENV=test mocha --watch",
"test:coverage": "c8 --check-coverage=true mocha",
"test:coverage": "NODE_ENV=test c8 --reporter cobertura --reporter lcov --reporter text-summary mocha",
"lint": "eslint .",
"lint:fix": "pnpm run lint --fix"
},
Expand All @@ -39,13 +39,18 @@
"@next/tsconfig": "workspace:^",
"@next/types": "workspace:^",
"@total-typescript/ts-reset": "^0.5.1",
"@types/mocha": "^10.0.3",
"@types/node": "^20.8.7",
"@types/sinon": "^10.0.20",
"c8": "^8.0.1",
"esbuild": "^0.19.5",
"esbuild-plugin-pino": "^2.0.2",
"mocha": "^10.2.0",
"pino-pretty": "^10.2.3",
"rimraf": "^5.0.5",
"sinon": "^17.0.0",
"tsx": "^3.14.0",
"typescript": "^5.2.2"
"typescript": "^5.2.2",
"vitest": "^0.34.6"
}
}
2 changes: 2 additions & 0 deletions apps/core/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ async function start() {
if (err) {
app.log.fatal({ err }, 'error starting app');
}

app.log.info({ signal }, 'Gracefully exiting app');
await app.close();
process.exit(1);
});
}

Expand Down
28 changes: 28 additions & 0 deletions apps/core/test/server.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import assert from 'node:assert/strict';
import { buildApp } from '@/app.js';
import type { FastifyInstance } from 'fastify';

describe('Server', () => {
let app: FastifyInstance;
before(async () => {
app = await buildApp();
});

after(async () => {
await app.close();
});

it('should start', async () => {
app.get('/test', () => ({ msg: 'welcome' }));
await app.listen();
const [address] = app.addresses();
const response = await fetch(`http://localhost:${address?.port}/test`);

assert.deepEqual(response.status, 200);
assert.deepEqual(
response.headers.get('content-type'),
'application/json; charset=utf-8',
);
assert.deepStrictEqual(await response.json(), { msg: 'welcome' });
});
});
8 changes: 7 additions & 1 deletion apps/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
"@/*": ["./src/*"]
}
},
"include": ["src/**/*.ts", "**.config.ts", "esbuild.ts"],
"include": [
"src/**/*.ts",
"**.config.ts",
"esbuild.ts",
"test/**/*.spec.ts",
"test/**/*.ts"
],
"exclude": ["node_modules/**/*"]
}
2 changes: 1 addition & 1 deletion apps/queue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"import": "./dist/index.js"
},
"scripts": {
"build": "tsup-node --config tsup.config.ts",
"build": "tsup-node",
"build:type-check": "tsc",
"lint": "eslint .",
"lint:fix": "pnpm run lint --fix"
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"lint": "turbo run lint --parallel",
"lint:fix": "turbo run lint:fix --parallel",
"test": "turbo run test",
"test:watch": "turbo run test:watch",
"test:coverage": "turbo run test:coverage",
"prepare": "simple-git-hooks"
},
"devDependencies": {
Expand Down
Loading