From bee30d7d82e8b4858e932cfad22a8b5c45d434ac Mon Sep 17 00:00:00 2001 From: Lena Daxenbichler Date: Tue, 10 May 2022 10:29:53 +0200 Subject: [PATCH] add js actin --- .github/workflows/test_js.yaml | 34 ++++++++++++++++++++++++++++++++++ .github/workflows/test_py.yaml | 4 +++- js/karma-coverage.js | 17 +++++++++++++++++ js/karma.conf.js | 13 +++++++++++++ package.json | 4 ++++ 5 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test_js.yaml create mode 100644 js/karma-coverage.js diff --git a/.github/workflows/test_js.yaml b/.github/workflows/test_js.yaml new file mode 100644 index 0000000..2bfe681 --- /dev/null +++ b/.github/workflows/test_js.yaml @@ -0,0 +1,34 @@ +name: JS Test chosen + +on: + push: + paths: + - '**.js' + +jobs: + test: + name: TEST CHOSEN + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Install + run: | + npm --save-dev install \ + qunit \ + karma \ + karma-qunit \ + karma-coverage \ + karma-chrome-launcher \ + karma-module-resolver-preprocessor + npm --no-save install https://github.com/jquery/jquery#main + + - name: Run tests + run: | + node_modules/karma/bin/karma start js/karma.conf.js + + - name: Run coverage + run: | + npm run karma-test:coverage diff --git a/.github/workflows/test_py.yaml b/.github/workflows/test_py.yaml index 4994d52..77efe51 100644 --- a/.github/workflows/test_py.yaml +++ b/.github/workflows/test_py.yaml @@ -1,7 +1,9 @@ -name: Test chosen +name: PY Test chosen on: push: + paths: + - '**.py' jobs: test: diff --git a/js/karma-coverage.js b/js/karma-coverage.js new file mode 100644 index 0000000..990ce24 --- /dev/null +++ b/js/karma-coverage.js @@ -0,0 +1,17 @@ +const percentage = { + lines: 33, + statements: 33, + functions: 28, + branches: 8 +} +var summary = require('./karma/coverage/coverage-summary.json'); + +for (let res in summary.total) { + if (summary.total[res].pct < percentage[res]) { + throw new Error( + `Coverage too low on ${res}, + expected: ${percentage[res]}, + got: ${summary.total[res].pct}` + ); + } +} \ No newline at end of file diff --git a/js/karma.conf.js b/js/karma.conf.js index b3d2661..5080d4d 100644 --- a/js/karma.conf.js +++ b/js/karma.conf.js @@ -33,6 +33,19 @@ module.exports = function(config) { 'progress', 'coverage' ], + coverageReporter: { + reporters: [ + { + type: 'json-summary', + dir: 'coverage/', + subdir: '.' + }, { + type: 'html', + dir: 'coverage/', + subdir: 'chrome-headless' + } + ] + }, preprocessors: { '../src/*.js': [ 'coverage', diff --git a/package.json b/package.json index 9d8c4f6..12ccb62 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,8 @@ { + "scripts": { + "karma-test": "node_modules/karma/bin/karma start js/karma.conf.js", + "karma-test:coverage": "node js/karma-coverage.js" + }, "devDependencies": { "karma": "^6.3.19", "karma-chrome-launcher": "^3.1.1",