Skip to content
Snippets Groups Projects
Commit 6ffbd638 authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

Add unit test support using karma+mocha+chai

parent 4c91da4f
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,7 @@ test: ...@@ -14,6 +14,7 @@ test:
stage: test stage: test
script: script:
- apt update - apt update
- apt install -y npm - apt install -y npm chromium
- npm install - npm install
- npm run build - npm run build
- npm test
...@@ -15,6 +15,9 @@ npm install ...@@ -15,6 +15,9 @@ npm install
# constantly build dist/bundle.js and run a local web-server on port 8002 # constantly build dist/bundle.js and run a local web-server on port 8002
npm run watch-local npm run watch-local
# run tests
npm test
``` ```
Jump to <http://localhost:8002> and you should get a Single Sign On login page. Jump to <http://localhost:8002> and you should get a Single Sign On login page.
// Trick to use the auto-downloaded puppeteer chrome binary
process.env.CHROME_BIN = require('puppeteer').executablePath();
module.exports = function(config) {
config.set({
basePath: 'dist',
frameworks: ['mocha', 'chai'],
files: [
'./bundle.js',
{pattern: './**/*', included: false, watched: true, served: true},
],
autoWatch: true,
browsers: ['ChromeHeadlessNoSandbox'],
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: 'ChromeHeadless',
flags: ['--no-sandbox']
}
},
singleRun: false,
logLevel: config.LOG_ERROR
});
}
...@@ -3,7 +3,14 @@ ...@@ -3,7 +3,14 @@
"version": "1.0.0", "version": "1.0.0",
"main": "src/index.js", "main": "src/index.js",
"devDependencies": { "devDependencies": {
"karma": "^4.2.0",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.0.0",
"karma-mocha": "^1.3.0",
"node-sass": "^4.12.0", "node-sass": "^4.12.0",
"puppeteer": "^1.15.0",
"mocha": "^6.2.0",
"chai": "^4.2.0",
"rollup": "^1.11.3", "rollup": "^1.11.3",
"rollup-plugin-commonjs": "^9.3.4", "rollup-plugin-commonjs": "^9.3.4",
"rollup-plugin-copy": "^2.0.1", "rollup-plugin-copy": "^2.0.1",
...@@ -13,6 +20,7 @@ ...@@ -13,6 +20,7 @@
"rollup-plugin-terser": "^4.0.4", "rollup-plugin-terser": "^4.0.4",
"rollup-plugin-json": "^4.0.0", "rollup-plugin-json": "^4.0.0",
"rollup-plugin-replace": "^2.2.0", "rollup-plugin-replace": "^2.2.0",
"rollup-plugin-multi-entry": "^2.1.0",
"i18next-scanner": "^2.10.2", "i18next-scanner": "^2.10.2",
"vpu-auth": "file:./vendor/auth", "vpu-auth": "file:./vendor/auth",
"vpu-common": "file:./vendor/common" "vpu-common": "file:./vendor/common"
...@@ -31,9 +39,11 @@ ...@@ -31,9 +39,11 @@
"build-dev": "rollup -c --environment BUILD:development", "build-dev": "rollup -c --environment BUILD:development",
"build-prod": "rollup -c --environment BUILD:production", "build-prod": "rollup -c --environment BUILD:production",
"build-demo": "rollup -c --environment BUILD:demo", "build-demo": "rollup -c --environment BUILD:demo",
"build-test": "rollup -c --environment BUILD:test",
"i18next": "i18next-scanner", "i18next": "i18next-scanner",
"watch": "npm run watch-local", "watch": "npm run watch-local",
"watch-local": "rollup -c --watch", "watch-local": "rollup -c --watch",
"watch-dev": "rollup -c --watch --environment BUILD:development" "watch-dev": "rollup -c --watch --environment BUILD:development",
"test": "npm run build-test && karma start --singleRun"
} }
} }
...@@ -6,17 +6,19 @@ import {terser} from "rollup-plugin-terser"; ...@@ -6,17 +6,19 @@ import {terser} from "rollup-plugin-terser";
import json from 'rollup-plugin-json'; import json from 'rollup-plugin-json';
import replace from "rollup-plugin-replace"; import replace from "rollup-plugin-replace";
import serve from 'rollup-plugin-serve'; import serve from 'rollup-plugin-serve';
import multiEntry from 'rollup-plugin-multi-entry';
const build = (typeof process.env.BUILD !== 'undefined') ? process.env.BUILD : 'local'; const build = (typeof process.env.BUILD !== 'undefined') ? process.env.BUILD : 'local';
console.log("build: " + build); console.log("build: " + build);
export default { export default {
input: 'src/demo.js', input: (build != 'test') ? 'src/demo.js' : 'test/**/*.js',
output: { output: {
file: 'dist/bundle.js', file: 'dist/bundle.js',
format: 'esm' format: 'esm'
}, },
plugins: [ plugins: [
multiEntry(),
resolve(), resolve(),
commonjs(), commonjs(),
json(), json(),
...@@ -28,7 +30,7 @@ export default { ...@@ -28,7 +30,7 @@ export default {
minimize: false, minimize: false,
plugins: [] plugins: []
}), }),
(build !== 'local') ? terser() : false, (build !== 'local' && build !== 'test') ? terser() : false,
copy({ copy({
targets: [ targets: [
'assets/index.html', 'assets/index.html',
......
import '../src/person-select';
describe('vpu-library-person-select basics', () => {
let node;
beforeEach(async () => {
node = document.createElement('vpu-library-person-select');
document.body.appendChild(node);
await node.updateComplete;
});
afterEach(() => {
node.remove();
});
it('should render', () => {
expect(node).to.have.property('shadowRoot');
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment