From 321e65014e063e0f79b7476a8a155bddefc48efb Mon Sep 17 00:00:00 2001 From: Ricardo Arturo Cabral Mejia Date: Fri, 28 Oct 2022 20:51:09 -0400 Subject: [PATCH] chore(ci): add intg tests coverage --- .dockerignore | 7 +++--- .eslintignore | 2 ++ .github/workflows/checks.yml | 36 +++++++++++++++++------------ .gitignore | 2 +- .mocharc.js | 3 +-- .nycrc.json | 1 - cucumber.js | 9 +++++++- package.json | 22 ++++++++++++------ test/integration/docker-compose.yml | 4 ++-- 9 files changed, 54 insertions(+), 32 deletions(-) diff --git a/.dockerignore b/.dockerignore index 6611697..9f71eb5 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,7 @@ dist node_modules -.test-report +.github +.test-reports .coverage seeds test @@ -8,8 +9,8 @@ test .eslint* .mocha* .nvmrc -.nycrc* +.nyc_output docker-compose.yml Dockerfile *.env -*.md +*.md \ No newline at end of file diff --git a/.eslintignore b/.eslintignore index f06235c..f6d18c9 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,4 @@ node_modules dist +.test-reports +.coverage diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index aaabb6d..ae777ac 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -10,8 +10,6 @@ jobs: lint: name: Lint runs-on: ubuntu-latest - container: - image: node:18-alpine3.16 steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 @@ -22,11 +20,9 @@ jobs: run: npm ci - name: Run ESLint run: npm run lint - build: - name: Build + build-check: + name: Build check runs-on: ubuntu-latest - container: - image: node:18-alpine3.16 steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 @@ -36,12 +32,10 @@ jobs: - name: Install package dependencies run: npm ci - name: Run ESLint - run: npm run build - test-and-cover: - name: Unit Tests + run: npm run build:check + test-units-and-cover: + name: Unit Tests And Coverage runs-on: ubuntu-latest - container: - image: node:18-alpine3.16 steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 @@ -53,16 +47,20 @@ jobs: - name: Run unit tests run: npm run test:unit - name: Run coverage for unit tests - run: npm run cover + run: npm run cover:unit - name: Coveralls uses: coverallsapp/github-action@master with: - path-to-lcov: ./.coverage/lcov.info + path-to-lcov: ./.coverage/unit/lcov.info flag-name: Unit github-token: ${{ secrets.GITHUB_TOKEN }} - test-integration: - name: Integration Tests + test-integrations-and-cover: + name: Integration Tests and Coverage runs-on: ubuntu-latest + needs: + - lint + - build-check + - test-units-and-cover steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 @@ -70,3 +68,11 @@ jobs: node-version-file: .nvmrc - name: Run integration tests run: npm run docker:test:integration + - name: Run coverage for integration tests + run: npm run docker:cover:integration + - name: Coveralls + uses: coverallsapp/github-action@master + with: + path-to-lcov: ./.coverage/integration/lcov.info + flag-name: Integration + github-token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6e2a82f..1c5f07a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ npm-debug.log* # Coverage .nyc_output -.test-report +.test-reports .coverage # Dependency directories diff --git a/.mocharc.js b/.mocharc.js index 63dde7c..15255de 100644 --- a/.mocharc.js +++ b/.mocharc.js @@ -3,11 +3,10 @@ module.exports = { require: ['ts-node/register'], reporter: 'mochawesome', slow: 75, - sorted: true, 'inline-diff': true, diff: true, 'reporter-option': [ - 'reportDir=.test-report', + 'reportDir=.test-reports/unit', 'reportFilename=index', 'quiet=true', 'json=false', diff --git a/.nycrc.json b/.nycrc.json index e00d03c..9d500f3 100644 --- a/.nycrc.json +++ b/.nycrc.json @@ -23,7 +23,6 @@ 95 ] }, - "report-dir": ".coverage", "extension": [ ".ts" ], diff --git a/cucumber.js b/cucumber.js index f411b26..e1fa469 100644 --- a/cucumber.js +++ b/cucumber.js @@ -1,12 +1,19 @@ -const config = [ +const base = [ 'test/integration/features/**/*.feature', '--require-module ts-node/register', '--require test/integration/features/**/*.ts', '--require test/integration/features/*.ts', +].join(' ') + +const config = [ + base, '--format @cucumber/pretty-formatter', + '--format html:.test-reports/integration/report.html', + '--format json:.test-reports/integration/report.json', '--publish', ].join(' ') module.exports = { default: config, + cover: base, } diff --git a/package.json b/package.json index 91404c1..79a6397 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "main": "src/index.ts", "scripts": { "dev": "node -r ts-node/register src/index.ts", - "clean": "rimraf ./dist", + "clean": "rimraf ./{dist,.nyc_output,.test-reports,.coverage}", "build": "tsc --project tsconfig.build.json", "prestart": "npm run build", "start": "cd dist && node src/index.js", @@ -27,16 +27,24 @@ "db:migrate": "knex migrate:latest", "db:migrate:rollback": "knex migrate:rollback", "db:seed": "knex seed:run", + "pretest:unit": "mkdir -p .test-reports/unit", "test:unit": "mocha 'test/**/*.spec.ts'", + "pretest:integration": "mkdir -p .test-reports/integration", "test:integration": "cucumber-js", + "cover:integration": "nyc --report-dir .coverage/integration npm run --ignore-scripts test:integration", "test:unit:watch": "npm run test:unit -- --min --watch --watch-files src/**/*,test/**/*", - "cover": "nyc npm run test:unit", + "cover:unit": "nyc --report-dir .coverage/unit npm run --ignore-scripts test:unit -- --reporter=false", "docker:build": "docker build -t nostr-ts-relay .", "predocker:compose:up": "[ -d \"$HOME/.nostr\" ] || mkdir -p $HOME/.nostr", - "docker:compose:up": "docker compose up --build", - "docker:compose:down": "docker compose down", - "docker:compose:rm": "docker compose rm", - "docker:test:integration": "docker compose -f ./test/integration/docker-compose.yml up tests --build --exit-code-from tests" + "docker:compose:start": "docker compose up --build", + "docker:compose:stop": "docker compose down", + "docker:compose:clean": "docker compose rm", + "predocker:test:integration": "docker compose -f ./test/integration/docker-compose.yml up -d --quiet-pull --build", + "docker:test:integration": "docker compose -f ./test/integration/docker-compose.yml run tests npm run test:integration", + "postdocker:test:integration": "docker compose -f ./test/integration/docker-compose.yml down", + "predocker:cover:integration": "docker compose -f ./test/integration/docker-compose.yml up -d --quiet-pull --build", + "docker:cover:integration": "docker compose -f ./test/integration/docker-compose.yml run tests npm run cover:integration", + "postdocker:cover:integration": "docker compose -f ./test/integration/docker-compose.yml down" }, "repository": { "type": "git", @@ -83,7 +91,7 @@ "dependencies": { "@noble/secp256k1": "1.7.0", "joi": "17.6.1", - "knex": "2.3.0", + "knex": "^2.3.0", "pg": "8.8.0", "pg-query-stream": "4.2.3", "ramda": "0.28.0", diff --git a/test/integration/docker-compose.yml b/test/integration/docker-compose.yml index 7168217..174fd4a 100644 --- a/test/integration/docker-compose.yml +++ b/test/integration/docker-compose.yml @@ -15,11 +15,11 @@ services: volumes: - ../../src:/code/src - ../../test:/code/test + - ../../.coverage:/code/.coverage + - ../../.test-reports:/code/.test-reports working_dir: /code ports: - "8008:8008" - command: - ["npm", "run", "test:integration"] depends_on: db-test: condition: service_healthy