diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 89528af51..8c588b784 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,6 +24,13 @@ jobs: - name: build run: yarn ci:build + - uses: dorny/test-reporter@v1 + if: ${{ (success() || failure()) && github.repository == 'mistic100/Photo-Sphere-Viewer' }} + with: + name: tests-results + path: reports/*.json + reporter: mocha-json + e2e: if: ${{ !startsWith(github.ref_name, 'dependabot') }} @@ -44,9 +51,9 @@ jobs: - uses: dorny/test-reporter@v1 if: ${{ (success() || failure()) && github.repository == 'mistic100/Photo-Sphere-Viewer' }} with: - name: test-results - path: cypress/reports/junit/*.xml - reporter: java-junit + name: e2e-results + path: reports/*.json + reporter: mocha-json # build-doc: # runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index 4f744b7d7..a668d35ab 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,5 @@ docs/.vitepress/.temp !docs/.typedoc dist /public -cypress/reports +/reports cypress/screenshots diff --git a/.mocharc.js b/.mocharc.js new file mode 100644 index 000000000..955e26ca1 --- /dev/null +++ b/.mocharc.js @@ -0,0 +1,5 @@ +const path = require('path'); + +module.exports = { + reporter: path.join(__dirname, 'build/mocha-reporter.js'), +}; diff --git a/build/mocha-reporter.js b/build/mocha-reporter.js new file mode 100644 index 000000000..6f78873f2 --- /dev/null +++ b/build/mocha-reporter.js @@ -0,0 +1,23 @@ +const BaseReporter = require('mocha/lib/reporters/base'); +const SpecReporter = require('mocha/lib/reporters/spec'); +// Cypress breaks the reporter ? +// https://github.com/cypress-io/cypress/issues/27636 +const JsonReporter = require('../node_modules/mocha/lib/reporters/json.js'); +const path = require('path'); + +module.exports = class MultiReporter extends BaseReporter { + constructor(runner, options) { + super(runner, options); + + // mocha uses "reporterOption", cypress uses "reporterOptions" + const title = options.reporterOption?.title ?? options.reporterOptions?.title ?? 'report'; + + new SpecReporter(runner, {}); + + new JsonReporter(runner, { + reporterOption: { + output: path.join(__dirname, '../reports', `${title}.json`), + }, + }); + } +}; diff --git a/cypress.config.ts b/cypress.config.ts index aa354203a..4f65407c7 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -8,8 +8,8 @@ export default defineConfig({ scrollBehavior: false, screenshotOnRunFailure: false, }, - reporter: 'mocha-junit-reporter', + reporter: 'build/mocha-reporter.js', reporterOptions: { - mochaFile: 'cypress/reports/junit/report.xml', + title: 'e2e', }, }); diff --git a/packages/core/package.json b/packages/core/package.json index 84786c999..b2c3041e0 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -13,7 +13,7 @@ "build": "tsup", "watch": "tsup --watch", "lint": "tsc --noEmit && eslint . --fix && stylelint \"src/**/*.scss\" --fix", - "test": "mocha -r ts-node/register \"src/**/*.spec.ts\"", + "test": "mocha -r ts-node/register \"src/**/*.spec.ts\" -O title=core", "publish-dist": "cd dist && npm publish --tag=$NPM_TAG --access=public", "npm-link": "cd dist && npm link" }, diff --git a/packages/shared/package.json b/packages/shared/package.json index 72b566b56..daaef82f3 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -4,6 +4,6 @@ "private": true, "scripts": { "lint": "tsc --noEmit && eslint . --fix && stylelint \"*.scss\" --fix", - "test": "mocha -r ts-node/register \"**/*.spec.ts\"" + "test": "mocha -r ts-node/register \"**/*.spec.ts\" -O title=shared" } }