Skip to content

Commit 309b522

Browse files
committed
test(experimental): add some tests for the inventory
Addressed minor output issue Trialed writing tests using mocks on mongoose or using an actual db
1 parent 3296303 commit 309b522

File tree

18 files changed

+7665
-4022
lines changed

18 files changed

+7665
-4022
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: CI - experimental - inventory
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- experimental/license-inventory/**
8+
pull_request:
9+
branches: [main]
10+
paths:
11+
- experimental/license-inventory/**
12+
13+
permissions:
14+
pull-requests: write
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
20+
strategy:
21+
matrix:
22+
node-version: [18.x]
23+
mongodb-version: [4.4]
24+
25+
steps:
26+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
27+
with:
28+
fetch-depth: 0
29+
30+
- name: Use Node.js ${{ matrix.node-version }}
31+
uses: actions/setup-node@v4
32+
with:
33+
node-version: ${{ matrix.node-version }}
34+
35+
- name: Start MongoDB
36+
uses: supercharge/[email protected]
37+
with:
38+
mongodb-version: ${{ matrix.mongodb-version }}
39+
40+
- name: Install dependencies
41+
working-directory: ./experimental/license-inventory
42+
run: npm ci
43+
44+
- name: Test
45+
working-directory: ./experimental/license-inventory
46+
run: |
47+
MONGO_URI="mongodb://localhost:27017/inventory" npm run test
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
dist

experimental/license-inventory/docker-compose.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ services:
2222
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
2323
OTEL_SERVICE_NAME: license-inventory
2424
OTEL_RESOURCE_ATTRIBUTES: service.version=0.0.0
25-
NODE_OPTIONS: --require @opentelemetry/auto-instrumentations-node/register
2625
ports:
2726
- 3000:3000
2827
working_dir: /usr/src/app
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import globals from "globals";
2-
import pluginJs from "@eslint/js";
3-
import tseslint from "typescript-eslint";
4-
1+
import globals from 'globals';
2+
import pluginJs from '@eslint/js';
3+
import tseslint from 'typescript-eslint';
54

65
/** @type {import('eslint').Linter.Config[]} */
76
export default [
8-
{files: ["**/*.{js,mjs,cjs,ts}"]},
9-
{languageOptions: { globals: globals.node }},
7+
{ files: ['**/*.{js,mjs,cjs,ts}'] },
8+
{ languageOptions: { globals: globals.node } },
109
pluginJs.configs.recommended,
1110
...tseslint.configs.recommended,
12-
];
11+
];
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { pathsToModuleNameMapper } from 'ts-jest';
2+
import { compilerOptions } from './tsconfig.json';
3+
import type { JestConfigWithTsJest } from 'ts-jest';
4+
5+
const jestConfig: JestConfigWithTsJest = {
6+
roots: ['<rootDir>/src'],
7+
modulePaths: [compilerOptions.baseUrl],
8+
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths),
9+
preset: 'ts-jest',
10+
testEnvironment: 'node',
11+
globalSetup: '<rootDir>/src/test/globalSetup.ts',
12+
globalTeardown: '<rootDir>/src/test/globalTeardown.ts',
13+
setupFilesAfterEnv: ['<rootDir>/src/test/setupFile.ts'],
14+
};
15+
16+
export default jestConfig;

experimental/license-inventory/nodemon.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"watch": ["src", ".env"],
33
"ext": "js,ts,json",
44
"ignore": ["src/**/*.{spec,test}.ts"],
5-
"exec": "ts-node -r tsconfig-paths/register --transpile-only src/server.ts | pino-pretty"
5+
"exec": "ts-node -r tsconfig-paths/register -r @opentelemetry/auto-instrumentations-node/register --transpile-only src/server.ts | pino-pretty"
66
}

0 commit comments

Comments
 (0)