From 66e5d3b4a93ea30179dc986b98928aaa29586a15 Mon Sep 17 00:00:00 2001 From: Manuel Ruck Date: Thu, 30 May 2024 15:24:42 +0200 Subject: [PATCH] test: fix tests Signed-off-by: Manuel Ruck --- .github/workflows/test.yaml | 21 +++++++++++++ package.json | 1 + services/cron-jobs/crawler/jest.config.ts | 2 +- services/cron-jobs/crawler/package.json | 1 - .../import-procedures.spec.ts | 30 ------------------- services/scrapers/scapacra/package.json | 3 +- turbo.json | 3 ++ 7 files changed, 27 insertions(+), 34 deletions(-) create mode 100644 .github/workflows/test.yaml delete mode 100644 services/cron-jobs/crawler/src/import-procedures/import-procedures.spec.ts diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 000000000..3274c3d13 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,21 @@ +name: ๐Ÿงช Test + +on: + pull_request: + branches: + - 'master' + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: โฌ‡๏ธ Checkout + uses: actions/checkout@v4 + - name: ๐Ÿ‘จโ€๐Ÿ”ง Setup node + uses: actions/setup-node@v4 + with: + node-version-file: '.node-version' + - name: ๐Ÿ‘จโ€๐Ÿ”ง Setup package manager + run: corepack enable + - name: ๐Ÿงช Test + run: pnpm test diff --git a/package.json b/package.json index a2cfd0713..c34965715 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "scripts": { "build": "turbo run build", "lint": "turbo run lint", + "test": "turbo run test", "dev": "turbo run dev", "infra:setup": "sh infra/minikube/setup.sh || bash infra/minikube/setup.sh || cmd.exe /C infra\\minikube\\setup.sh", "infra:start": "minikube start -p mk-democracy" diff --git a/services/cron-jobs/crawler/jest.config.ts b/services/cron-jobs/crawler/jest.config.ts index dfc4de272..78950735e 100644 --- a/services/cron-jobs/crawler/jest.config.ts +++ b/services/cron-jobs/crawler/jest.config.ts @@ -114,7 +114,7 @@ export default { // restoreMocks: false, // The root directory that Jest should scan for tests and modules within - // rootDir: undefined, + rootDir: 'src', // A list of paths to directories that Jest should use to search for files in // roots: [ diff --git a/services/cron-jobs/crawler/package.json b/services/cron-jobs/crawler/package.json index b0df1004b..90bd57cb6 100644 --- a/services/cron-jobs/crawler/package.json +++ b/services/cron-jobs/crawler/package.json @@ -10,7 +10,6 @@ "dev": "dotenv -e .env -e .env.local -- tsup src/import-procedures --watch --onSuccess 'node build/index.js'", "build": "tsup-node", "lint": "eslint .", - "test": "jest", "start": "node ./build/index.js" }, "dependencies": { diff --git a/services/cron-jobs/crawler/src/import-procedures/import-procedures.spec.ts b/services/cron-jobs/crawler/src/import-procedures/import-procedures.spec.ts deleted file mode 100644 index 3d47cb582..000000000 --- a/services/cron-jobs/crawler/src/import-procedures/import-procedures.spec.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { CONFIG } from '../config'; -import importProcedures from './import-procedures'; -import { ProcedureModel } from '@democracy-deutschland/bundestagio-common'; - -jest.mock('@democracy-deutschland/bundestagio-common', () => ({ - ProcedureModel: { - bulkWrite: jest.fn(), - }, -})); - -jest.mock('graphql-request', () => ({ - ...jest.requireActual('graphql-request'), - request: jest.fn().mockResolvedValue({ - procedures: { - edges: [], - pageInfo: { endcursor: 'abcde', hasNextPage: false }, - }, - }), -})); - -describe('importProcedures', () => { - it('returns undefined once done', async () => { - await expect(importProcedures(CONFIG)).resolves.toBe(undefined); - }); - - it('calls `ProcedureModel.bulkWrite`', async () => { - await importProcedures(CONFIG); - expect(ProcedureModel.bulkWrite).toHaveBeenCalled(); - }); -}); diff --git a/services/scrapers/scapacra/package.json b/services/scrapers/scapacra/package.json index 48a2d82c5..cadabdbee 100644 --- a/services/scrapers/scapacra/package.json +++ b/services/scrapers/scapacra/package.json @@ -17,8 +17,7 @@ "build": "tsc", "dev": "nodemon ./src/Example.ts", "lint": "tslint --project tsconfig.json && pnpm typecheck", - "typecheck": "tsc --noEmit", - "test": "mocha -r ts-node/register test/**/*.test.ts" + "typecheck": "tsc --noEmit" }, "bugs": { "url": "https://github.com/demokratie-live/scapacra/issues" diff --git a/turbo.json b/turbo.json index 7a3f97703..6b6ea04eb 100644 --- a/turbo.json +++ b/turbo.json @@ -12,6 +12,9 @@ "lint": { "dependsOn": ["^build"] }, + "test": { + "dependsOn": ["^build", "^test"] + }, "release:version": {} } }