Skip to content

Commit

Permalink
test(experimental): add some tests for the inventory
Browse files Browse the repository at this point in the history
Addressed minor output issue
Trialed writing tests using mocks on mongoose or using an actual db
  • Loading branch information
06kellyjac committed Dec 6, 2024
1 parent 3296303 commit 309b522
Show file tree
Hide file tree
Showing 18 changed files with 7,665 additions and 4,022 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/ci-experimental-inventory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: CI - experimental - inventory

on:
push:
branches: [main]
paths:
- experimental/license-inventory/**
pull_request:
branches: [main]
paths:
- experimental/license-inventory/**

permissions:
pull-requests: write

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x]
mongodb-version: [4.4]

steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
fetch-depth: 0

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Start MongoDB
uses: supercharge/mongodb-github-action@1.11.0
with:
mongodb-version: ${{ matrix.mongodb-version }}

- name: Install dependencies
working-directory: ./experimental/license-inventory
run: npm ci

- name: Test
working-directory: ./experimental/license-inventory
run: |
MONGO_URI="mongodb://localhost:27017/inventory" npm run test
1 change: 1 addition & 0 deletions experimental/license-inventory/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
dist
1 change: 0 additions & 1 deletion experimental/license-inventory/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ services:
OTEL_EXPORTER_OTLP_PROTOCOL: http/protobuf
OTEL_SERVICE_NAME: license-inventory
OTEL_RESOURCE_ATTRIBUTES: service.version=0.0.0
NODE_OPTIONS: --require @opentelemetry/auto-instrumentations-node/register
ports:
- 3000:3000
working_dir: /usr/src/app
Expand Down
13 changes: 6 additions & 7 deletions experimental/license-inventory/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";

import globals from 'globals';
import pluginJs from '@eslint/js';
import tseslint from 'typescript-eslint';

/** @type {import('eslint').Linter.Config[]} */
export default [
{files: ["**/*.{js,mjs,cjs,ts}"]},
{languageOptions: { globals: globals.node }},
{ files: ['**/*.{js,mjs,cjs,ts}'] },
{ languageOptions: { globals: globals.node } },
pluginJs.configs.recommended,
...tseslint.configs.recommended,
];
];
16 changes: 16 additions & 0 deletions experimental/license-inventory/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { pathsToModuleNameMapper } from 'ts-jest';
import { compilerOptions } from './tsconfig.json';
import type { JestConfigWithTsJest } from 'ts-jest';

const jestConfig: JestConfigWithTsJest = {
roots: ['<rootDir>/src'],
modulePaths: [compilerOptions.baseUrl],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths),
preset: 'ts-jest',
testEnvironment: 'node',
globalSetup: '<rootDir>/src/test/globalSetup.ts',
globalTeardown: '<rootDir>/src/test/globalTeardown.ts',
setupFilesAfterEnv: ['<rootDir>/src/test/setupFile.ts'],
};

export default jestConfig;
2 changes: 1 addition & 1 deletion experimental/license-inventory/nodemon.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"watch": ["src", ".env"],
"ext": "js,ts,json",
"ignore": ["src/**/*.{spec,test}.ts"],
"exec": "ts-node -r tsconfig-paths/register --transpile-only src/server.ts | pino-pretty"
"exec": "ts-node -r tsconfig-paths/register -r @opentelemetry/auto-instrumentations-node/register --transpile-only src/server.ts | pino-pretty"
}
Loading

0 comments on commit 309b522

Please sign in to comment.