Skip to content

Commit

Permalink
Switch to mocha
Browse files Browse the repository at this point in the history
  • Loading branch information
myrotvorets-team committed Sep 16, 2023
1 parent 4568681 commit c2cde65
Show file tree
Hide file tree
Showing 30 changed files with 1,959 additions and 3,976 deletions.
4 changes: 4 additions & 0 deletions .c8rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extension": [".mts"],
"reporter": ["text", "lcov"]
}
9 changes: 5 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"parserOptions": {
"ecmaVersion": 2020,
"project": ["./tsconfig.json"]
"project": ["./tsconfig.json"],
"sourceType": "module"
},
"extends": [
"@myrotvorets/myrotvorets-ts"
],
"env": {
"node": true,
"jest": true
"es2022": true,
"mocha": true,
"node": true
}
}
46 changes: 40 additions & 6 deletions .github/workflows/sonarscan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ on:
- master
workflow_dispatch:

permissions:
contents: read
env:
SONARSCANNER: "true"

jobs:
build:
name: SonarCloud Scan
runs-on: ubuntu-latest
if: github.event_name == 'push' && !contains(github.event.head_commit.message, '[ci skip]')
if: |
github.event_name == 'workflow_dispatch' ||
github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name && github.event.sender.login != 'dependabot[bot]' ||
github.event_name == 'push' && !contains(github.event.head_commit.message, '[ci skip]')
permissions:
contents: read
packages: read
Expand All @@ -27,12 +30,43 @@ jobs:
fetch-depth: 0
submodules: true

- name: Run SonarCloud analysis
uses: myrotvorets/composite-actions/node-sonarscan@master
- name: Set up Node.js environment
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3.8.1
with:
sonar-token: ${{ secrets.SONAR_TOKEN }}
node-version: lts/*
registry-url: https://npm.pkg.github.com

- name: Install dependencies
run: npm ci --ignore-scripts
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Run postinstall scripts
run: npm rebuild && npm run prepare --if-present

- name: Run tests
run: npm run test:coverage

- name: Retrieve information from package.json
uses: myrotvorets/info-from-package-json-action@6a4b12839126aa2b858a12d89577fb7c5011e8f9 # 2.0.0
id: ver

- name: Fix paths in test-report.xml
run: sed -i "s@$(pwd)@/github/workspace@g" test-report.xml

- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@c25d2e7e3def96d0d1781000d3c429da22cd6252 # v2.0.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
with:
args: >
-Dsonar.projectName=${{ steps.ver.outputs.packageName }}
-Dsonar.projectVersion=${{ steps.ver.outputs.packageVersion }}
-Dsonar.links.homepage=${{ steps.ver.outputs.packageHomepage }}
-Dsonar.links.issue=${{ steps.ver.outputs.packageBugsUrl }}
-Dsonar.links.scm=${{ steps.ver.outputs.packageScmUrl }}
- name: Install codecov
run: npm i -g codecov

Expand Down
13 changes: 13 additions & 0 deletions .mocharc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/** @type {import('mocha').MochaOptions} */
module.exports = {
recursive: true,
spec: ['test/**/*.test.mts'],
'node-option': ['loader=ts-node/esm', 'no-warnings'],
require: 'mocha.setup.mjs',
reporter: 'mocha-multi',
'reporter-option': [
'spec=-',
process.env.GITHUB_ACTIONS === 'true' ? 'mocha-reporter-gha=-' : null,
process.env.SONARSCANNER === 'true' ? 'mocha-reporter-sonarqube=test-report.xml' : null,
].filter(Boolean),
}
6 changes: 2 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ COPY --chown=nobody:nobody ./package.json ./package-lock.json ./tsconfig.json .n
RUN \
npm r --package-lock-only \
@myrotvorets/eslint-config-myrotvorets-ts eslint-formatter-gha \
@types/jest jest ts-jest jest-sonar-reporter jest-github-actions-reporter \
supertest @types/supertest \
ts-node \
nodemon && \
mocha @types/mocha chai @types/chai chai-as-promised @types/chai-as-promised supertest @types/supertest testdouble c8 mocha-multi mocha-reporter-gha mocha-reporter-sonarqube \
ts-node nodemon && \
npm ci --ignore-scripts --userconfig .npmrc.local && \
rm -f .npmrc.local && \
npm rebuild && \
Expand Down
29 changes: 0 additions & 29 deletions jest.config.ts

This file was deleted.

14 changes: 14 additions & 0 deletions mocha.setup.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'mocha';
import { use } from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { reset } from 'testdouble';

use(chaiAsPromised);

/** @type {import('mocha').RootHookObject} */
export const mochaHooks = {
/** @returns {void} */
afterEach() {
reset();
},
};
Loading

0 comments on commit c2cde65

Please sign in to comment.