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

Add unit test support using karma+mocha+chai

Also run tests in gitlab-ci
parent 1905212e
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,8 @@ test: ...@@ -14,7 +14,8 @@ test:
stage: test stage: test
script: script:
- apt update - apt update
- apt install -y npm - apt install -y npm chromium
- npm run setup - npm run setup
- npm install - npm install
- npm run build - npm run build
- npm test
// 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,17 +3,25 @@ ...@@ -3,17 +3,25 @@
"version": "1.0.0", "version": "1.0.0",
"main": "src/index.js", "main": "src/index.js",
"devDependencies": { "devDependencies": {
"i18next-scanner": "^2.10.2",
"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",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-multi-entry": "^2.1.0",
"rollup-plugin-node-resolve": "^4.2.3", "rollup-plugin-node-resolve": "^4.2.3",
"rollup-plugin-postcss": "^2.0.3", "rollup-plugin-postcss": "^2.0.3",
"rollup-plugin-serve": "^1.0.1",
"rollup-plugin-terser": "^4.0.4",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-replace": "^2.2.0", "rollup-plugin-replace": "^2.2.0",
"i18next-scanner": "^2.10.2" "rollup-plugin-serve": "^1.0.1",
"rollup-plugin-terser": "^4.0.4"
}, },
"dependencies": { "dependencies": {
"@webcomponents/webcomponentsjs": "^2.2.10", "@webcomponents/webcomponentsjs": "^2.2.10",
...@@ -29,9 +37,11 @@ ...@@ -29,9 +37,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"
} }
} }
import path from 'path';
import resolve from 'rollup-plugin-node-resolve'; import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs'; import commonjs from 'rollup-plugin-commonjs';
import postcss from 'rollup-plugin-postcss'; import postcss from 'rollup-plugin-postcss';
...@@ -6,18 +7,25 @@ import {terser} from "rollup-plugin-terser"; ...@@ -6,18 +7,25 @@ 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: [
resolve(), multiEntry(),
resolve({
customResolveOptions: {
// ignore node_modules from vendored packages
moduleDirectory: path.join(process.cwd(), 'node_modules')
}
}),
commonjs(), commonjs(),
json(), json(),
replace({ replace({
...@@ -28,7 +36,7 @@ export default { ...@@ -28,7 +36,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/vpu-auth';
describe('vpu-auth basics', () => {
let node;
beforeEach(async () => {
node = document.createElement('vpu-auth');
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