Skip to content

Commit

Permalink
updated config files
Browse files Browse the repository at this point in the history
  • Loading branch information
nichlaes committed Oct 2, 2024
1 parent 344150c commit ae93e55
Show file tree
Hide file tree
Showing 17 changed files with 69 additions and 35 deletions.
2 changes: 1 addition & 1 deletion servers/lib/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ export default [
'src/types.ts',
],
},
];
];
39 changes: 31 additions & 8 deletions servers/lib/jest.config.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
{
"preset": "ts-jest",
"preset": "ts-jest/presets/default-esm",
"testEnvironment": "node",
"transform": {
"^.+\\.tsx?$": "ts-jest"
"(src|test)/^.+\\.(t|j)sx?$": [
"ts-jest",
{
"useESM": true
}
]
},
"transformIgnorePatterns": ["/node_modules/(?![d3-shape|recharts]).+\\.js$"],
"collectCoverage": true,
"coverageReporters": ["text", "cobertura", "clover", "lcov", "json"],
"collectCoverageFrom": ["src/**/*.{ts,js}"],
"coveragePathIgnorePatterns": [
"node_modules",
"./dist",
"../src/app.module.ts",
"../src/main.ts",
"../src/bootstrap.ts"
"../src/main.ts"
],
"modulePathIgnorePatterns": ["config"],
"extensionsToTreatAsEsm": [".ts"],
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"modulePathIgnorePatterns": [],
"coverageDirectory": "<rootDir>/coverage/",
"coverageThreshold": {
"global": {
Expand All @@ -27,5 +36,19 @@
},
"verbose": true,
"testRegex": "./test/.*\\.spec.tsx?$",
"modulePaths": ["<rootDir>/src/"]
}
"modulePaths": ["<rootDir>", "<rootDir>/src/", "<rootDir>/test/"],
"moduleDirectories": [
"node_modules",
"src",
"test"
],
"rootDir": "./",
"roots": [
"<rootDir>",
"src/",
"test/"
],
"moduleNameMapper": {
"^(\\.\\/.+)\\.js$": "$1"
}
}
15 changes: 8 additions & 7 deletions servers/lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,26 @@
],
"private": false,
"license": "SEE LICENSE IN <LICENSE.md>",
"type": "module",
"scripts": {
"build": "tsc",
"clean": "npx rimraf build node_modules coverage dist src.svg test.svg",
"format": "prettier --ignore-path ../.gitignore --write \"**/*.{ts,tsx,css,scss}\"",
"graph": "npx madge --image src.svg src && npx madge --image test.svg test",
"start": "node dist/src/main.js",
"start:pm2": "pm2 start pm2.config.js",
"start": "tsc & node dist/src/main.js",
"start:pm2": "pm2 start pm2.config.cjs",
"stop:pm2": "pm2 delete libms",
"syntax": "eslint . --fix",
"pretest": "npx shx cp test/data/user2/tools/README.md ../../files/user2/tools/README.md",
"posttest": "npx rimraf ../../files/user2/tools/README.md",
"test:all": "npx cross-env LOCAL_PATH=test/data jest --testPathIgnorePatterns=cloudcmd --coverage",
"test:e2e": "npx cross-env LOCAL_PATH=test/data jest --config ./test/jest-e2e.json --coverage",
"test:all": "npx cross-env NODE_OPTIONS=--experimental-vm-modules LOCAL_PATH=test/data jest --testPathIgnorePatterns=cloudcmd --coverage",
"test:e2e": "npx cross-env NODE_OPTIONS=--experimental-vm-modules LOCAL_PATH=test/data jest --config ./test/jest-e2e.json --coverage",
"test:http": "yarn build && pm2 start -f --name libms-test dist/src/main.js -- -c .env -H ./config/http.json && jest test/cloudcmd --coverage --coverageThreshold=\"{}\" && pm2 delete libms-test",
"test:http-nocov": "yarn build && pm2 start -f --name libms-test dist/src/main.js -- -c .env -H ./config/http.json && jest test/cloudcmd --coverage=false && pm2 delete libms-test",
"test:http-github": "jest test/cloudcmd --coverage --coverageThreshold=\"{}\"",
"test:int": "npx cross-env LOCAL_PATH=test/data jest ../test/integration --coverage",
"test:int": "npx cross-env NODE_OPTIONS=--experimental-vm-modules LOCAL_PATH=test/data jest ../test/integration --coverage",
"test:nocov": "yarn test:http-nocov && npx cross-env LOCAL_PATH=test/data jest --testPathIgnorePatterns=cloudcmd --coverage=false",
"test:unit": "npx cross-env LOCAL_PATH=test/data jest ../test/unit --coverage"
"test:unit": "npx cross-env NODE_OPTIONS=--experimental-vm-modules LOCAL_PATH=test/data jest ../test/unit --coverage"
},
"bin": "./dist/src/main.js",
"dependencies": {
Expand Down Expand Up @@ -72,7 +73,7 @@
"eslint-plugin-jest": "^28.8.3",
"eslint-plugin-prettier": "^5.2.1",
"graphql-scalars": "^1.23.0",
"jest": "29.7.0",
"jest": "^29.7.0",
"prettier": "^3.3.3",
"react": "^18.3.1",
"supertest": "^7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion servers/lib/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import { ApolloDriver } from '@nestjs/apollo';
import { join } from 'path';
import FilesModule from './files/files.module';
import FilesModule from './files/files.module.js';

@Module({
imports: [
Expand Down
4 changes: 2 additions & 2 deletions servers/lib/src/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { NestFactory } from '@nestjs/core';
import { ConfigService } from '@nestjs/config';
import * as dotenv from 'dotenv';
import AppModule from './app.module';
import cloudCMD from './cloudcmd/cloudcmd';
import AppModule from './app.module.js';
import cloudCMD from './cloudcmd/cloudcmd.js';

type BootstrapOptions = {
config?: string;
Expand Down
6 changes: 3 additions & 3 deletions servers/lib/src/files/files.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Module } from '@nestjs/common';
import FilesResolver from './resolvers/files.resolver';
import FilesServiceFactory from './services/files-service.factory';
import LocalFilesService from './services/local-files.service';
import FilesResolver from './resolvers/files.resolver.js';
import FilesServiceFactory from './services/files-service.factory.js';
import LocalFilesService from './services/local-files.service.js';

@Module({
providers: [FilesResolver, LocalFilesService, FilesServiceFactory],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Project } from 'src/types';
import { Project } from 'src/types.js';

// FileService interface
export interface IFilesService {
Expand Down
6 changes: 3 additions & 3 deletions servers/lib/src/files/resolvers/files.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Resolver, Query, Args } from '@nestjs/graphql';
import { IFilesService } from '../interfaces/files.service.interface';
import FilesServiceFactory from '../services/files-service.factory';
import { Project } from '../../types';
import { IFilesService } from '../interfaces/files.service.interface.js';
import FilesServiceFactory from '../services/files-service.factory.js';
import { Project } from '../../types.js';

@Resolver()
export default class FilesResolver {
Expand Down
4 changes: 2 additions & 2 deletions servers/lib/src/files/services/files-service.factory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable, Inject } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { IFilesService } from '../interfaces/files.service.interface';
import LocalFilesService from './local-files.service';
import { IFilesService } from '../interfaces/files.service.interface.js';
import LocalFilesService from './local-files.service.js';

@Injectable()
export default class FilesServiceFactory {
Expand Down
4 changes: 2 additions & 2 deletions servers/lib/src/files/services/local-files.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Injectable, InternalServerErrorException } from '@nestjs/common';
import * as fs from 'fs';
import { join } from 'path';
import { ConfigService } from '@nestjs/config';
import { Project } from 'src/types';
import { IFilesService } from '../interfaces/files.service.interface';
import { Project } from 'src/types.js';
import { IFilesService } from '../interfaces/files.service.interface.js';

@Injectable()
export default class LocalFilesService implements IFilesService {
Expand Down
2 changes: 1 addition & 1 deletion servers/lib/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
import { Command } from 'commander';
import bootstrap from './bootstrap';
import bootstrap from './bootstrap.js';

type ProgramOptions = {
config?: string;
Expand Down
3 changes: 2 additions & 1 deletion servers/lib/test/e2e/app.e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, it, expect } from '@jest/globals';
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import request from 'supertest';
import fetch from 'cross-fetch';
import {
ApolloClient,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect, jest } from '@jest/globals';
import { Test, TestingModule } from '@nestjs/testing';
import { ConfigService } from '@nestjs/config';
import FilesResolver from '../../src/files/resolvers/files.resolver';
Expand Down
1 change: 1 addition & 0 deletions servers/lib/test/unit/files-service.factory.unit.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// files-service.factory.spec.ts
import { describe, it, expect, jest } from '@jest/globals';
import { Test, TestingModule } from '@nestjs/testing';
import { ConfigService } from '@nestjs/config';
import FilesServiceFactory from '../../src/files/services/files-service.factory';
Expand Down
6 changes: 4 additions & 2 deletions servers/lib/test/unit/files.resolver.unit.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect, jest } from '@jest/globals';
import { Test, TestingModule } from '@nestjs/testing';
import FilesResolver from '../../src/files/resolvers/files.resolver';
import {
Expand All @@ -8,15 +9,16 @@ import {
} from '../testUtil';
import { IFilesService } from '../../src/files/interfaces/files.service.interface';
import FilesServiceFactory from '../../src/files/services/files-service.factory';
import { Project } from 'src/types';

describe('Unit tests for FilesResolver', () => {
let filesResolver: FilesResolver;
let filesService: IFilesService;

beforeEach(async () => {
const mockFilesService: IFilesService = {
listDirectory: jest.fn().mockImplementation(() => testDirectory),
readFile: jest.fn().mockImplementation(() => testFileContent),
listDirectory: jest.fn<() => Promise<Project>>().mockResolvedValue(testDirectory),
readFile: jest.fn<() => Promise<Project>>().mockImplementation(() => Promise.resolve(testFileContent)),
};

const module: TestingModule = await Test.createTestingModule({
Expand Down
4 changes: 3 additions & 1 deletion servers/lib/test/unit/local-files.service.unit.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, it, expect, jest } from '@jest/globals';
import { Test, TestingModule } from '@nestjs/testing';
import { ConfigService } from '@nestjs/config';
import * as fs from 'fs';
Expand All @@ -11,6 +12,7 @@ import {
MockConfigService,
testFileName,
} from '../testUtil';
import { Dirent } from 'fs';

jest.mock('fs', () => ({
promises: {
Expand Down Expand Up @@ -56,7 +58,7 @@ describe('LocalFilesService', () => {

jest
.spyOn(fs.promises, 'readdir')
.mockResolvedValue(testFileArray as unknown as Promise<[]>);
.mockResolvedValue(testFileArray as unknown as Dirent[]);

jest.spyOn(fs.promises, 'lstat').mockImplementation((pathToDirectory) => {
if (typeof pathToDirectory === 'string') {
Expand Down
3 changes: 3 additions & 0 deletions servers/lib/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"experimentalDecorators": true, //allow experimental decorators for es7
"forceConsistentCasingInFileNames": false,
"incremental": true,
"lib": [
"ES2022"
],
"module": "ES2022", //use node module system
"moduleResolution": "node", //use node module resolution strategy node
"noImplicitReturns": true, //raise error on implicit returns
Expand Down

0 comments on commit ae93e55

Please sign in to comment.