From 9b32855570b08d8a7c6e5424ca27a96e1e46675b Mon Sep 17 00:00:00 2001 From: guido Date: Tue, 23 Apr 2024 17:55:33 +0200 Subject: [PATCH] Correctly configure linting tool for testing --- .github/workflows/js-qa.yml | 7 ++++-- .vscode/settings.json | 3 ++- package.json | 7 ++++-- tests/.eslintrc.js | 9 ++++++++ jest.config.ts => tests/jest.config.ts | 6 ++--- tests/tsconfig.json | 14 ++++++++++++ tsconfig.json | 31 ++++++-------------------- 7 files changed, 45 insertions(+), 32 deletions(-) create mode 100644 tests/.eslintrc.js rename jest.config.ts => tests/jest.config.ts (58%) create mode 100644 tests/tsconfig.json diff --git a/.github/workflows/js-qa.yml b/.github/workflows/js-qa.yml index f5c5b3e..9690809 100644 --- a/.github/workflows/js-qa.yml +++ b/.github/workflows/js-qa.yml @@ -28,8 +28,11 @@ jobs: - name: Install run: yarn install - - name: Linting JavaScript + - name: Lint Source Code run: yarn lint - - name: Testing JavaScript + - name: Lint Tests + run: yarn lint:test + + - name: Execute Tests run: yarn test diff --git a/.vscode/settings.json b/.vscode/settings.json index 7621b0a..9c90bd8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "jest.jestCommandLine": "yarn jest", "jest.rootPath": "src", - "favorites.resources": [] + "favorites.resources": [], + "typescript.tsdk": "node_modules/typescript/lib" } diff --git a/package.json b/package.json index c459135..af4b098 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,10 @@ "scripts": { "build": "tsc --outDir build && ncc build -o dist ./index.ts", "prettify": "prettier --write src/**/*.ts index.ts", - "lint": "eslint . --ext .ts", - "prepare": "husky" + "lint": "eslint ./src --ext .ts", + "lint:test": "eslint --config ./tests/.eslintrc.js ./tests --ext .ts", + "prepare": "husky", + "test": "jest --config ./tests/jest.config.ts", + "qa": "yarn lint && yarn lint:test && yarn test" } } diff --git a/tests/.eslintrc.js b/tests/.eslintrc.js new file mode 100644 index 0000000..e8a6407 --- /dev/null +++ b/tests/.eslintrc.js @@ -0,0 +1,9 @@ +const path = require('path'); + +module.exports = { + extends: path.resolve(__dirname, '../.eslintrc.json'), + parserOptions: { + project: './tsconfig.json', + tsconfigRootDir: __dirname, + }, +}; diff --git a/jest.config.ts b/tests/jest.config.ts similarity index 58% rename from jest.config.ts rename to tests/jest.config.ts index 9f73f75..4c3d25d 100644 --- a/jest.config.ts +++ b/tests/jest.config.ts @@ -4,9 +4,9 @@ module.exports = { preset: 'ts-jest', moduleDirectories: ['node_modules'], moduleNameMapper: { - '^@/(.*)$': '/src/$1', - '^@model/(.*)$': '/src/model/$1', + '^@/(.*)$': '/../src/$1', + '^@model/(.*)$': '/../src/model/$1', }, - setupFilesAfterEnv: ['/tests/setup-tests.ts'], + setupFilesAfterEnv: ['/setup-tests.ts'], maxWorkers: 8, }; diff --git a/tests/tsconfig.json b/tests/tsconfig.json new file mode 100644 index 0000000..f1ede9f --- /dev/null +++ b/tests/tsconfig.json @@ -0,0 +1,14 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "baseUrl": "./", + "typeRoots": ["../node_modules/@types"], + "paths": { + "@/*": ["../src/*"], + "@model/*": ["../src/model/*"] + }, + "rootDir": "./" + }, + "include": ["../src/**/*.ts", "./unit/**/*.ts", "jest.config.ts", "setup-tests.ts"], + "exclude": ["../node_modules"] +} diff --git a/tsconfig.json b/tsconfig.json index 81f8f2e..4906ced 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -24,32 +24,15 @@ "baseUrl": "./", "module": "nodeNext", "moduleResolution": "NodeNext", - "typeRoots": [ - "./node_modules/@types" - ], + "typeRoots": ["./node_modules/@types"], "paths": { - "@/*": [ - "./src/*" - ], - "@model/*": [ - "./src/model/*" - ], - "*": [ - "node_modules/*", - "types/*" - ] + "@/*": ["./src/*"], + "@model/*": ["./src/model/*"], + "*": ["node_modules/*", "types/*"] }, "rootDir": "./" }, - "files": [ - "./index.ts" - ], - "include": [ - "./src/**/*.ts", - "./tests/**/*.ts", - "jest.config.ts" - ], - "exclude": [ - "node_modules" - ] + "files": ["./index.ts"], + "include": ["./src/**/*.ts"], + "exclude": ["node_modules", "tests"] }