Commit 4b270359 authored by JC Brand's avatar JC Brand

Use Karma as test runner

parent 7e23adf2
dist: xenial dist: bionic
language: node_js language: node_js
cache: cache:
directories: directories:
...@@ -6,7 +6,11 @@ cache: ...@@ -6,7 +6,11 @@ cache:
addons: addons:
chrome: stable chrome: stable
node_js: node_js:
- "10" - "14"
install: make node_modules install: make node_modules
before_script: make serve_bg services:
script: make check - xvfb
before_script:
- make serve_bg
- export DISPLAY=:99.0
script: make check ARGS=--single-run
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
BABEL ?= node_modules/.bin/babel BABEL ?= node_modules/.bin/babel
BOOTSTRAP = ./node_modules/ BOOTSTRAP = ./node_modules/
BUILDDIR = ./docs BUILDDIR = ./docs
KARMA ?= ./node_modules/.bin/karma
CHROMIUM ?= ./node_modules/.bin/run-headless-chromium CHROMIUM ?= ./node_modules/.bin/run-headless-chromium
CLEANCSS ?= ./node_modules/clean-css-cli/bin/cleancss --skip-rebase CLEANCSS ?= ./node_modules/clean-css-cli/bin/cleancss --skip-rebase
ESLINT ?= ./node_modules/.bin/eslint ESLINT ?= ./node_modules/.bin/eslint
...@@ -197,7 +198,11 @@ eslint: node_modules ...@@ -197,7 +198,11 @@ eslint: node_modules
.PHONY: check .PHONY: check
check: eslint dev check: eslint dev
LOG_CR_VERBOSITY=INFO $(CHROMIUM) --disable-gpu --no-sandbox http://localhost:$(HTTPSERVE_PORT)/tests/index.html $(KARMA) start karma.conf.js $(ARGS)
.PHONY: test
test:
$(KARMA) start karma.conf.js $(ARGS)
######################################################################## ########################################################################
## Documentation ## Documentation
......
/* global module */
const path = require('path');
module.exports = function(config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
frameworks: ['jasmine'],
files: [
{ pattern: 'dist/*.js.map', included: false },
{ pattern: 'dist/*.css.map', included: false },
{ pattern: "dist/emojis.js", served: true },
"dist/converse.js",
"dist/converse.css",
{ pattern: "dist/webfonts/**/*.*", included: false },
{ pattern: "node_modules/sinon/pkg/sinon.js", type: 'module' },
{ pattern: "tests/console-reporter.js", type: 'module' },
{ pattern: "tests/mock.js", type: 'module' },
{ pattern: "spec/spoilers.js", type: 'module' },
{ pattern: "spec/roomslist.js", type: 'module' },
{ pattern: "spec/utils.js", type: 'module' },
{ pattern: "spec/converse.js", type: 'module' },
{ pattern: "spec/bookmarks.js", type: 'module' },
{ pattern: "spec/headline.js", type: 'module' },
{ pattern: "spec/disco.js", type: 'module' },
{ pattern: "spec/protocol.js", type: 'module' },
{ pattern: "spec/presence.js", type: 'module' },
{ pattern: "spec/eventemitter.js", type: 'module' },
{ pattern: "spec/smacks.js", type: 'module' },
{ pattern: "spec/ping.js", type: 'module' },
{ pattern: "spec/push.js", type: 'module' },
{ pattern: "spec/xmppstatus.js", type: 'module' },
{ pattern: "spec/mam.js", type: 'module' },
{ pattern: "spec/omemo.js", type: 'module' },
{ pattern: "spec/controlbox.js", type: 'module' },
{ pattern: "spec/roster.js", type: 'module' },
{ pattern: "spec/chatbox.js", type: 'module' },
{ pattern: "spec/user-details-modal.js", type: 'module' },
{ pattern: "spec/messages.js", type: 'module' },
{ pattern: "spec/muc_messages.js", type: 'module' },
{ pattern: "spec/retractions.js", type: 'module' },
{ pattern: "spec/muc.js", type: 'module' },
{ pattern: "spec/modtools.js", type: 'module' },
{ pattern: "spec/room_registration.js", type: 'module' },
{ pattern: "spec/autocomplete.js", type: 'module' },
{ pattern: "spec/minchats.js", type: 'module' },
{ pattern: "spec/notification.js", type: 'module' },
{ pattern: "spec/login.js", type: 'module' },
{ pattern: "spec/register.js", type: 'module' },
{ pattern: "spec/hats.js", type: 'module' },
{ pattern: "spec/http-file-upload.js", type: 'module' },
{ pattern: "spec/emojis.js", type: 'module' },
{ pattern: "spec/xss.js", type: 'module' },
],
exclude: ['**/*.sw?'],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress', 'kjhtml'],
webpack: {
mode: 'development',
devtool: 'inline-source-map',
module: {
rules: [{
test: /\.js$/,
exclude: /(node_modules|test)/
}]
},
output: {
path: path.resolve('test'),
filename: '[name].out.js',
chunkFilename: '[id].[chunkHash].js'
}
},
port: 9876,
colors: true,
// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false,
// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity
})
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
window.addEventListener('converse-loaded', () => { /*global mock */
const mock = window.mock;
describe("The _converse Event Emitter", function() {
return describe("The _converse Event Emitter", function() {
it("allows you to subscribe to emitted events", mock.initConverse((done, _converse) => {
it("allows you to subscribe to emitted events", mock.initConverse((done, _converse) => { this.callback = function () {};
this.callback = function () {}; spyOn(this, 'callback');
spyOn(this, 'callback'); _converse.on('connected', this.callback);
_converse.on('connected', this.callback); _converse.api.trigger('connected');
_converse.api.trigger('connected'); expect(this.callback).toHaveBeenCalled();
expect(this.callback).toHaveBeenCalled(); _converse.api.trigger('connected');
_converse.api.trigger('connected'); expect(this.callback.calls.count(), 2);
expect(this.callback.calls.count(), 2); _converse.api.trigger('connected');
_converse.api.trigger('connected'); expect(this.callback.calls.count(), 3);
expect(this.callback.calls.count(), 3); done();
done(); }));
}));
it("allows you to listen once for an emitted event", mock.initConverse((done, _converse) => {
it("allows you to listen once for an emitted event", mock.initConverse((done, _converse) => { this.callback = function () {};
this.callback = function () {}; spyOn(this, 'callback');
spyOn(this, 'callback'); _converse.once('connected', this.callback);
_converse.once('connected', this.callback); _converse.api.trigger('connected');
_converse.api.trigger('connected'); expect(this.callback).toHaveBeenCalled();
expect(this.callback).toHaveBeenCalled(); _converse.api.trigger('connected');
_converse.api.trigger('connected'); expect(this.callback.calls.count(), 1);
expect(this.callback.calls.count(), 1); _converse.api.trigger('connected');
_converse.api.trigger('connected'); expect(this.callback.calls.count(), 1);
expect(this.callback.calls.count(), 1); done();
done(); }));
}));
it("allows you to stop listening or subscribing to an event", mock.initConverse((done, _converse) => {
it("allows you to stop listening or subscribing to an event", mock.initConverse((done, _converse) => { this.callback = function () {};
this.callback = function () {}; this.anotherCallback = function () {};
this.anotherCallback = function () {}; this.neverCalled = function () {};
this.neverCalled = function () {};
spyOn(this, 'callback');
spyOn(this, 'callback'); spyOn(this, 'anotherCallback');
spyOn(this, 'anotherCallback'); spyOn(this, 'neverCalled');
spyOn(this, 'neverCalled'); _converse.on('connected', this.callback);
_converse.on('connected', this.callback); _converse.on('connected', this.anotherCallback);
_converse.on('connected', this.anotherCallback);
_converse.api.trigger('connected');
_converse.api.trigger('connected'); expect(this.callback).toHaveBeenCalled();
expect(this.callback).toHaveBeenCalled(); expect(this.anotherCallback).toHaveBeenCalled();
expect(this.anotherCallback).toHaveBeenCalled();
_converse.off('connected', this.callback);
_converse.off('connected', this.callback);
_converse.api.trigger('connected');
_converse.api.trigger('connected'); expect(this.callback.calls.count(), 1);
expect(this.callback.calls.count(), 1); expect(this.anotherCallback.calls.count(), 2);
expect(this.anotherCallback.calls.count(), 2);
_converse.once('connected', this.neverCalled);
_converse.once('connected', this.neverCalled); _converse.off('connected', this.neverCalled);
_converse.off('connected', this.neverCalled);
_converse.api.trigger('connected');
_converse.api.trigger('connected'); expect(this.callback.calls.count(), 1);
expect(this.callback.calls.count(), 1); expect(this.anotherCallback.calls.count(), 3);
expect(this.anotherCallback.calls.count(), 3); expect(this.neverCalled).not.toHaveBeenCalled();
expect(this.neverCalled).not.toHaveBeenCalled(); done();
done(); }));
}));
});
}); });
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment