From 870c24d5bdfbe4a33be7c07ac0d2165e4e087707 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 5 Aug 2024 16:19:22 +0200 Subject: [PATCH 1/7] Avoid polluting global namespace With modules, this is now considered bad form. --- eslint.config.mjs | 2 -- tests/assertions.js | 4 ---- tests/test.base64.js | 2 ++ tests/test.browser.js | 2 ++ tests/test.copyrect.js | 2 ++ tests/test.deflator.js | 2 ++ tests/test.display.js | 3 +++ tests/test.gesturehandler.js | 3 +++ tests/test.helper.js | 2 ++ tests/test.hextile.js | 2 ++ tests/test.inflator.js | 2 ++ tests/test.int.js | 2 ++ tests/test.jpeg.js | 2 ++ tests/test.keyboard.js | 3 +++ tests/test.localization.js | 3 +++ tests/test.raw.js | 2 ++ tests/test.rfb.js | 3 +++ tests/test.rre.js | 2 ++ tests/test.tight.js | 2 ++ tests/test.tightpng.js | 2 ++ tests/test.util.js | 3 +++ tests/test.websock.js | 3 +++ tests/test.webutil.js | 3 +++ tests/test.zrle.js | 2 ++ 24 files changed, 52 insertions(+), 6 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index 13b1a32a4..f6050b14b 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -78,8 +78,6 @@ export default [ globals: { ...globals.node, ...globals.mocha, - sinon: false, - expect: false, } }, rules: { diff --git a/tests/assertions.js b/tests/assertions.js index a70122717..ea0003b6a 100644 --- a/tests/assertions.js +++ b/tests/assertions.js @@ -1,10 +1,6 @@ import * as chai from '../node_modules/chai/chai.js'; -import sinon from '../node_modules/sinon/pkg/sinon-esm.js'; import sinonChai from '../node_modules/sinon-chai/lib/sinon-chai.js'; -window.expect = chai.expect; - -window.sinon = sinon; chai.use(sinonChai); // noVNC specific assertions diff --git a/tests/test.base64.js b/tests/test.base64.js index e5644dcdb..120608e3c 100644 --- a/tests/test.base64.js +++ b/tests/test.base64.js @@ -1,3 +1,5 @@ +import { expect } from '../node_modules/chai/chai.js'; + import Base64 from '../core/base64.js'; describe('Base64 Tools', function () { diff --git a/tests/test.browser.js b/tests/test.browser.js index 692cc23b2..fa82e7bc5 100644 --- a/tests/test.browser.js +++ b/tests/test.browser.js @@ -1,3 +1,5 @@ +import { expect } from '../node_modules/chai/chai.js'; + import { isMac, isWindows, isIOS, isAndroid, isChromeOS, isSafari, isFirefox, isChrome, isChromium, isOpera, isEdge, isGecko, isWebKit, isBlink } from '../core/util/browser.js'; diff --git a/tests/test.copyrect.js b/tests/test.copyrect.js index 60c395287..82a9bf365 100644 --- a/tests/test.copyrect.js +++ b/tests/test.copyrect.js @@ -1,3 +1,5 @@ +import { expect } from '../node_modules/chai/chai.js'; + import Websock from '../core/websock.js'; import Display from '../core/display.js'; diff --git a/tests/test.deflator.js b/tests/test.deflator.js index b565b9075..2da038232 100644 --- a/tests/test.deflator.js +++ b/tests/test.deflator.js @@ -1,3 +1,5 @@ +import { expect } from '../node_modules/chai/chai.js'; + import { inflateInit, inflate } from "../vendor/pako/lib/zlib/inflate.js"; import ZStream from "../vendor/pako/lib/zlib/zstream.js"; import Deflator from "../core/deflator.js"; diff --git a/tests/test.display.js b/tests/test.display.js index d2c51793b..48e90a436 100644 --- a/tests/test.display.js +++ b/tests/test.display.js @@ -1,3 +1,6 @@ +import { expect } from '../node_modules/chai/chai.js'; +import sinon from '../node_modules/sinon/pkg/sinon-esm.js'; + import Base64 from '../core/base64.js'; import Display from '../core/display.js'; diff --git a/tests/test.gesturehandler.js b/tests/test.gesturehandler.js index d2e27ed2a..e3c2e32a1 100644 --- a/tests/test.gesturehandler.js +++ b/tests/test.gesturehandler.js @@ -1,3 +1,6 @@ +import { expect } from '../node_modules/chai/chai.js'; +import sinon from '../node_modules/sinon/pkg/sinon-esm.js'; + import EventTargetMixin from '../core/util/eventtarget.js'; import GestureHandler from '../core/input/gesturehandler.js'; diff --git a/tests/test.helper.js b/tests/test.helper.js index 2c8720c77..04428dd1b 100644 --- a/tests/test.helper.js +++ b/tests/test.helper.js @@ -1,3 +1,5 @@ +import { expect } from '../node_modules/chai/chai.js'; + import keysyms from '../core/input/keysymdef.js'; import * as KeyboardUtil from "../core/input/util.js"; diff --git a/tests/test.hextile.js b/tests/test.hextile.js index f788fd4dc..3fea3023a 100644 --- a/tests/test.hextile.js +++ b/tests/test.hextile.js @@ -1,3 +1,5 @@ +import { expect } from '../node_modules/chai/chai.js'; + import Websock from '../core/websock.js'; import Display from '../core/display.js'; diff --git a/tests/test.inflator.js b/tests/test.inflator.js index 11a02f2f4..8bf4f6f3e 100644 --- a/tests/test.inflator.js +++ b/tests/test.inflator.js @@ -1,3 +1,5 @@ +import { expect } from '../node_modules/chai/chai.js'; + import { deflateInit, deflate, Z_FULL_FLUSH } from "../vendor/pako/lib/zlib/deflate.js"; import ZStream from "../vendor/pako/lib/zlib/zstream.js"; import Inflator from "../core/inflator.js"; diff --git a/tests/test.int.js b/tests/test.int.js index 378ebd589..641d9db6c 100644 --- a/tests/test.int.js +++ b/tests/test.int.js @@ -1,3 +1,5 @@ +import { expect } from '../node_modules/chai/chai.js'; + import { toUnsigned32bit, toSigned32bit } from '../core/util/int.js'; describe('Integer casting', function () { diff --git a/tests/test.jpeg.js b/tests/test.jpeg.js index 5cc153f90..4340242f9 100644 --- a/tests/test.jpeg.js +++ b/tests/test.jpeg.js @@ -1,3 +1,5 @@ +import { expect } from '../node_modules/chai/chai.js'; + import Websock from '../core/websock.js'; import Display from '../core/display.js'; diff --git a/tests/test.keyboard.js b/tests/test.keyboard.js index 11c8b6eb7..4296486fb 100644 --- a/tests/test.keyboard.js +++ b/tests/test.keyboard.js @@ -1,3 +1,6 @@ +import { expect } from '../node_modules/chai/chai.js'; +import sinon from '../node_modules/sinon/pkg/sinon-esm.js'; + import Keyboard from '../core/input/keyboard.js'; describe('Key Event Handling', function () { diff --git a/tests/test.localization.js b/tests/test.localization.js index a1cb45474..e49a0735a 100644 --- a/tests/test.localization.js +++ b/tests/test.localization.js @@ -1,3 +1,6 @@ +import { expect } from '../node_modules/chai/chai.js'; +import sinon from '../node_modules/sinon/pkg/sinon-esm.js'; + import _, { Localizer, l10n } from '../app/localization.js'; describe('Localization', function () { diff --git a/tests/test.raw.js b/tests/test.raw.js index 19b2377f7..e3d8b4570 100644 --- a/tests/test.raw.js +++ b/tests/test.raw.js @@ -1,3 +1,5 @@ +import { expect } from '../node_modules/chai/chai.js'; + import Websock from '../core/websock.js'; import Display from '../core/display.js'; diff --git a/tests/test.rfb.js b/tests/test.rfb.js index 2be3bfbfc..b4d59e022 100644 --- a/tests/test.rfb.js +++ b/tests/test.rfb.js @@ -1,3 +1,6 @@ +import { expect } from '../node_modules/chai/chai.js'; +import sinon from '../node_modules/sinon/pkg/sinon-esm.js'; + import RFB from '../core/rfb.js'; import Websock from '../core/websock.js'; import ZStream from "../vendor/pako/lib/zlib/zstream.js"; diff --git a/tests/test.rre.js b/tests/test.rre.js index 7b5f73d0e..5ca0d7326 100644 --- a/tests/test.rre.js +++ b/tests/test.rre.js @@ -1,3 +1,5 @@ +import { expect } from '../node_modules/chai/chai.js'; + import Websock from '../core/websock.js'; import Display from '../core/display.js'; diff --git a/tests/test.tight.js b/tests/test.tight.js index 3d6b555da..28080bf4e 100644 --- a/tests/test.tight.js +++ b/tests/test.tight.js @@ -1,3 +1,5 @@ +import { expect } from '../node_modules/chai/chai.js'; + import Websock from '../core/websock.js'; import Display from '../core/display.js'; diff --git a/tests/test.tightpng.js b/tests/test.tightpng.js index e7edc8fa6..01d2493e2 100644 --- a/tests/test.tightpng.js +++ b/tests/test.tightpng.js @@ -1,3 +1,5 @@ +import { expect } from '../node_modules/chai/chai.js'; + import Websock from '../core/websock.js'; import Display from '../core/display.js'; diff --git a/tests/test.util.js b/tests/test.util.js index eb7240951..16dbb7c9f 100644 --- a/tests/test.util.js +++ b/tests/test.util.js @@ -1,4 +1,7 @@ /* eslint-disable no-console */ +import { expect } from '../node_modules/chai/chai.js'; +import sinon from '../node_modules/sinon/pkg/sinon-esm.js'; + import * as Log from '../core/util/logging.js'; import { encodeUTF8, decodeUTF8 } from '../core/util/strings.js'; diff --git a/tests/test.websock.js b/tests/test.websock.js index 53145b360..38b654a88 100644 --- a/tests/test.websock.js +++ b/tests/test.websock.js @@ -1,3 +1,6 @@ +import { expect } from '../node_modules/chai/chai.js'; +import sinon from '../node_modules/sinon/pkg/sinon-esm.js'; + import Websock from '../core/websock.js'; import FakeWebSocket from './fake.websocket.js'; diff --git a/tests/test.webutil.js b/tests/test.webutil.js index 9151a0603..45c71e495 100644 --- a/tests/test.webutil.js +++ b/tests/test.webutil.js @@ -1,5 +1,8 @@ /* jshint expr: true */ +import { expect } from '../node_modules/chai/chai.js'; +import sinon from '../node_modules/sinon/pkg/sinon-esm.js'; + import * as WebUtil from '../app/webutil.js'; describe('WebUtil', function () { diff --git a/tests/test.zrle.js b/tests/test.zrle.js index f7c6089d5..679b4ad32 100644 --- a/tests/test.zrle.js +++ b/tests/test.zrle.js @@ -1,3 +1,5 @@ +import { expect } from '../node_modules/chai/chai.js'; + import Websock from '../core/websock.js'; import Display from '../core/display.js'; From 236fa87af4395214c27d85fa3d149b4419c4537c Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 5 Aug 2024 16:23:29 +0200 Subject: [PATCH 2/7] Explicitly import test support routines This gives us a strong ordering, and clear dependencies, which is needed in other test runners. --- karma.conf.js | 2 +- tests/test.copyrect.js | 1 + tests/test.deflator.js | 1 + tests/test.display.js | 1 + tests/test.gesturehandler.js | 1 + tests/test.hextile.js | 1 + tests/test.inflator.js | 1 + tests/test.jpeg.js | 1 + tests/test.keyboard.js | 1 + tests/test.localization.js | 1 + tests/test.raw.js | 1 + tests/test.rfb.js | 1 + tests/test.rre.js | 1 + tests/test.tight.js | 1 + tests/test.tightpng.js | 1 + tests/test.util.js | 1 + tests/test.websock.js | 1 + tests/test.webutil.js | 1 + tests/test.zrle.js | 1 + 19 files changed, 19 insertions(+), 1 deletion(-) diff --git a/karma.conf.js b/karma.conf.js index 54380ebd2..a019887f1 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -44,7 +44,7 @@ module.exports = (config) => { { pattern: 'tests/test.*.js', type: 'module' }, // test support files { pattern: 'tests/fake.*.js', included: false, type: 'module' }, - { pattern: 'tests/assertions.js', type: 'module' }, + { pattern: 'tests/assertions.js', included: false, type: 'module' }, ], client: { diff --git a/tests/test.copyrect.js b/tests/test.copyrect.js index 82a9bf365..ad9f8b310 100644 --- a/tests/test.copyrect.js +++ b/tests/test.copyrect.js @@ -1,3 +1,4 @@ +import './assertions.js'; import { expect } from '../node_modules/chai/chai.js'; import Websock from '../core/websock.js'; diff --git a/tests/test.deflator.js b/tests/test.deflator.js index 2da038232..76c4d8f1f 100644 --- a/tests/test.deflator.js +++ b/tests/test.deflator.js @@ -1,3 +1,4 @@ +import './assertions.js'; import { expect } from '../node_modules/chai/chai.js'; import { inflateInit, inflate } from "../vendor/pako/lib/zlib/inflate.js"; diff --git a/tests/test.display.js b/tests/test.display.js index 48e90a436..131e76d10 100644 --- a/tests/test.display.js +++ b/tests/test.display.js @@ -1,3 +1,4 @@ +import './assertions.js'; import { expect } from '../node_modules/chai/chai.js'; import sinon from '../node_modules/sinon/pkg/sinon-esm.js'; diff --git a/tests/test.gesturehandler.js b/tests/test.gesturehandler.js index e3c2e32a1..880cdd14e 100644 --- a/tests/test.gesturehandler.js +++ b/tests/test.gesturehandler.js @@ -1,3 +1,4 @@ +import './assertions.js'; import { expect } from '../node_modules/chai/chai.js'; import sinon from '../node_modules/sinon/pkg/sinon-esm.js'; diff --git a/tests/test.hextile.js b/tests/test.hextile.js index 3fea3023a..5a59e97b0 100644 --- a/tests/test.hextile.js +++ b/tests/test.hextile.js @@ -1,3 +1,4 @@ +import './assertions.js'; import { expect } from '../node_modules/chai/chai.js'; import Websock from '../core/websock.js'; diff --git a/tests/test.inflator.js b/tests/test.inflator.js index 8bf4f6f3e..b1ebb7227 100644 --- a/tests/test.inflator.js +++ b/tests/test.inflator.js @@ -1,3 +1,4 @@ +import './assertions.js'; import { expect } from '../node_modules/chai/chai.js'; import { deflateInit, deflate, Z_FULL_FLUSH } from "../vendor/pako/lib/zlib/deflate.js"; diff --git a/tests/test.jpeg.js b/tests/test.jpeg.js index 4340242f9..b50f22a5d 100644 --- a/tests/test.jpeg.js +++ b/tests/test.jpeg.js @@ -1,3 +1,4 @@ +import './assertions.js'; import { expect } from '../node_modules/chai/chai.js'; import Websock from '../core/websock.js'; diff --git a/tests/test.keyboard.js b/tests/test.keyboard.js index 4296486fb..d7c4de8ae 100644 --- a/tests/test.keyboard.js +++ b/tests/test.keyboard.js @@ -1,3 +1,4 @@ +import './assertions.js'; import { expect } from '../node_modules/chai/chai.js'; import sinon from '../node_modules/sinon/pkg/sinon-esm.js'; diff --git a/tests/test.localization.js b/tests/test.localization.js index e49a0735a..2d05d1c64 100644 --- a/tests/test.localization.js +++ b/tests/test.localization.js @@ -1,3 +1,4 @@ +import './assertions.js'; import { expect } from '../node_modules/chai/chai.js'; import sinon from '../node_modules/sinon/pkg/sinon-esm.js'; diff --git a/tests/test.raw.js b/tests/test.raw.js index e3d8b4570..2c62916d2 100644 --- a/tests/test.raw.js +++ b/tests/test.raw.js @@ -1,3 +1,4 @@ +import './assertions.js'; import { expect } from '../node_modules/chai/chai.js'; import Websock from '../core/websock.js'; diff --git a/tests/test.rfb.js b/tests/test.rfb.js index b4d59e022..e7c55b28e 100644 --- a/tests/test.rfb.js +++ b/tests/test.rfb.js @@ -1,3 +1,4 @@ +import './assertions.js'; import { expect } from '../node_modules/chai/chai.js'; import sinon from '../node_modules/sinon/pkg/sinon-esm.js'; diff --git a/tests/test.rre.js b/tests/test.rre.js index 5ca0d7326..9ad931bc7 100644 --- a/tests/test.rre.js +++ b/tests/test.rre.js @@ -1,3 +1,4 @@ +import './assertions.js'; import { expect } from '../node_modules/chai/chai.js'; import Websock from '../core/websock.js'; diff --git a/tests/test.tight.js b/tests/test.tight.js index 28080bf4e..bfa30d643 100644 --- a/tests/test.tight.js +++ b/tests/test.tight.js @@ -1,3 +1,4 @@ +import './assertions.js'; import { expect } from '../node_modules/chai/chai.js'; import Websock from '../core/websock.js'; diff --git a/tests/test.tightpng.js b/tests/test.tightpng.js index 01d2493e2..a52cfd5dc 100644 --- a/tests/test.tightpng.js +++ b/tests/test.tightpng.js @@ -1,3 +1,4 @@ +import './assertions.js'; import { expect } from '../node_modules/chai/chai.js'; import Websock from '../core/websock.js'; diff --git a/tests/test.util.js b/tests/test.util.js index 16dbb7c9f..f836f4b2f 100644 --- a/tests/test.util.js +++ b/tests/test.util.js @@ -1,4 +1,5 @@ /* eslint-disable no-console */ +import './assertions.js'; import { expect } from '../node_modules/chai/chai.js'; import sinon from '../node_modules/sinon/pkg/sinon-esm.js'; diff --git a/tests/test.websock.js b/tests/test.websock.js index 38b654a88..3509b36ea 100644 --- a/tests/test.websock.js +++ b/tests/test.websock.js @@ -1,3 +1,4 @@ +import './assertions.js'; import { expect } from '../node_modules/chai/chai.js'; import sinon from '../node_modules/sinon/pkg/sinon-esm.js'; diff --git a/tests/test.webutil.js b/tests/test.webutil.js index 45c71e495..6046c3f07 100644 --- a/tests/test.webutil.js +++ b/tests/test.webutil.js @@ -1,5 +1,6 @@ /* jshint expr: true */ +import './assertions.js'; import { expect } from '../node_modules/chai/chai.js'; import sinon from '../node_modules/sinon/pkg/sinon-esm.js'; diff --git a/tests/test.zrle.js b/tests/test.zrle.js index 679b4ad32..27e2a02cb 100644 --- a/tests/test.zrle.js +++ b/tests/test.zrle.js @@ -1,3 +1,4 @@ +import './assertions.js'; import { expect } from '../node_modules/chai/chai.js'; import Websock from '../core/websock.js'; From 88e95cba630df4eab0598e8df0202555b96eb9a4 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 5 Aug 2024 12:32:20 +0200 Subject: [PATCH 3/7] TEMP: Switch to web-test-runner Karma is deprecated, so switch to something that is still maintained. --- karma.conf.js | 92 ------------------------------------ package.json | 15 ++---- tests/assertions.js | 4 +- tests/test.base64.js | 2 +- tests/test.browser.js | 2 +- tests/test.copyrect.js | 2 +- tests/test.deflator.js | 2 +- tests/test.display.js | 4 +- tests/test.gesturehandler.js | 4 +- tests/test.helper.js | 2 +- tests/test.hextile.js | 2 +- tests/test.inflator.js | 2 +- tests/test.int.js | 2 +- tests/test.jpeg.js | 2 +- tests/test.keyboard.js | 4 +- tests/test.localization.js | 4 +- tests/test.raw.js | 2 +- tests/test.rfb.js | 4 +- tests/test.rre.js | 2 +- tests/test.tight.js | 2 +- tests/test.tightpng.js | 2 +- tests/test.util.js | 4 +- tests/test.websock.js | 4 +- tests/test.webutil.js | 4 +- tests/test.zrle.js | 2 +- web-test-runner.config.mjs | 13 +++++ 26 files changed, 48 insertions(+), 136 deletions(-) delete mode 100644 karma.conf.js create mode 100644 web-test-runner.config.mjs diff --git a/karma.conf.js b/karma.conf.js deleted file mode 100644 index a019887f1..000000000 --- a/karma.conf.js +++ /dev/null @@ -1,92 +0,0 @@ -// Karma configuration - -// The Safari launcher is broken, so construct our own -function SafariBrowser(id, baseBrowserDecorator, args) { - baseBrowserDecorator(this); - - this._start = function(url) { - this._execCommand('/usr/bin/open', ['-W', '-n', '-a', 'Safari', url]); - } -} - -SafariBrowser.prototype = { - name: 'Safari' -} - -module.exports = (config) => { - let browsers = []; - - if (process.env.TEST_BROWSER_NAME) { - browsers = process.env.TEST_BROWSER_NAME.split(','); - } - - const my_conf = { - - // base path that will be used to resolve all patterns (eg. files, exclude) - basePath: '', - - // frameworks to use - // available frameworks: https://npmjs.org/browse/keyword/karma-adapter - frameworks: ['mocha'], - - // list of files / patterns to load in the browser - files: [ - // node modules - { pattern: 'node_modules/chai/**', included: false }, - { pattern: 'node_modules/sinon/**', included: false }, - { pattern: 'node_modules/sinon-chai/**', included: false }, - // modules to test - { pattern: 'app/localization.js', included: false, type: 'module' }, - { pattern: 'app/webutil.js', included: false, type: 'module' }, - { pattern: 'core/**/*.js', included: false, type: 'module' }, - { pattern: 'vendor/pako/**/*.js', included: false, type: 'module' }, - // tests - { pattern: 'tests/test.*.js', type: 'module' }, - // test support files - { pattern: 'tests/fake.*.js', included: false, type: 'module' }, - { pattern: 'tests/assertions.js', included: false, type: 'module' }, - ], - - client: { - mocha: { - // replace Karma debug page with mocha display - 'reporter': 'html', - 'ui': 'bdd' - } - }, - - // list of files to exclude - exclude: [ - ], - - plugins: [ - 'karma-*', - '@chiragrupani/karma-chromium-edge-launcher', - { 'launcher:Safari': [ 'type', SafariBrowser ] }, - ], - - // start these browsers - // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher - browsers: browsers, - - // test results reporter to use - // possible values: 'dots', 'progress' - // available reporters: https://npmjs.org/browse/keyword/karma-reporter - reporters: ['mocha'], - - - // 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: false, - - // Continuous Integration mode - // if true, Karma captures browsers, runs the tests and exits - singleRun: true, - }; - - config.set(my_conf); -}; diff --git a/package.json b/package.json index e28850a8d..1558d838d 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ ], "scripts": { "lint": "eslint app core po/po2js po/xgettext-html tests utils", - "test": "karma start karma.conf.js", + "test": "web-test-runner", "prepublish": "node ./utils/convert.js --clean" }, "repository": { @@ -46,22 +46,13 @@ "fs-extra": "latest", "globals": "latest", "jsdom": "latest", - "karma": "latest", - "karma-mocha": "latest", - "karma-chrome-launcher": "latest", - "@chiragrupani/karma-chromium-edge-launcher": "latest", - "karma-firefox-launcher": "latest", - "karma-ie-launcher": "latest", - "karma-mocha-reporter": "latest", - "karma-safari-launcher": "latest", - "karma-script-launcher": "latest", "mocha": "latest", "node-getopt": "latest", "po2json": "latest", "sinon": "latest", - "sinon-chai": "latest" + "sinon-chai": "latest", + "@web/test-runner": "latest" }, - "dependencies": {}, "keywords": [ "vnc", "rfb", diff --git a/tests/assertions.js b/tests/assertions.js index ea0003b6a..34ab038f0 100644 --- a/tests/assertions.js +++ b/tests/assertions.js @@ -1,5 +1,5 @@ -import * as chai from '../node_modules/chai/chai.js'; -import sinonChai from '../node_modules/sinon-chai/lib/sinon-chai.js'; +import * as chai from 'chai'; +import sinonChai from 'sinon-chai'; chai.use(sinonChai); diff --git a/tests/test.base64.js b/tests/test.base64.js index 120608e3c..b29a80d86 100644 --- a/tests/test.base64.js +++ b/tests/test.base64.js @@ -1,4 +1,4 @@ -import { expect } from '../node_modules/chai/chai.js'; +import { expect } from 'chai'; import Base64 from '../core/base64.js'; diff --git a/tests/test.browser.js b/tests/test.browser.js index fa82e7bc5..936db2a1a 100644 --- a/tests/test.browser.js +++ b/tests/test.browser.js @@ -1,4 +1,4 @@ -import { expect } from '../node_modules/chai/chai.js'; +import { expect } from 'chai'; import { isMac, isWindows, isIOS, isAndroid, isChromeOS, isSafari, isFirefox, isChrome, isChromium, isOpera, isEdge, diff --git a/tests/test.copyrect.js b/tests/test.copyrect.js index ad9f8b310..81e425c62 100644 --- a/tests/test.copyrect.js +++ b/tests/test.copyrect.js @@ -1,5 +1,5 @@ import './assertions.js'; -import { expect } from '../node_modules/chai/chai.js'; +import { expect } from 'chai'; import Websock from '../core/websock.js'; import Display from '../core/display.js'; diff --git a/tests/test.deflator.js b/tests/test.deflator.js index 76c4d8f1f..181709414 100644 --- a/tests/test.deflator.js +++ b/tests/test.deflator.js @@ -1,5 +1,5 @@ import './assertions.js'; -import { expect } from '../node_modules/chai/chai.js'; +import { expect } from 'chai'; import { inflateInit, inflate } from "../vendor/pako/lib/zlib/inflate.js"; import ZStream from "../vendor/pako/lib/zlib/zstream.js"; diff --git a/tests/test.display.js b/tests/test.display.js index 131e76d10..37990e8ee 100644 --- a/tests/test.display.js +++ b/tests/test.display.js @@ -1,6 +1,6 @@ import './assertions.js'; -import { expect } from '../node_modules/chai/chai.js'; -import sinon from '../node_modules/sinon/pkg/sinon-esm.js'; +import { expect } from 'chai'; +import sinon from 'sinon'; import Base64 from '../core/base64.js'; import Display from '../core/display.js'; diff --git a/tests/test.gesturehandler.js b/tests/test.gesturehandler.js index 880cdd14e..798eab19e 100644 --- a/tests/test.gesturehandler.js +++ b/tests/test.gesturehandler.js @@ -1,6 +1,6 @@ import './assertions.js'; -import { expect } from '../node_modules/chai/chai.js'; -import sinon from '../node_modules/sinon/pkg/sinon-esm.js'; +import { expect } from 'chai'; +import sinon from 'sinon'; import EventTargetMixin from '../core/util/eventtarget.js'; diff --git a/tests/test.helper.js b/tests/test.helper.js index 04428dd1b..17fc568e2 100644 --- a/tests/test.helper.js +++ b/tests/test.helper.js @@ -1,4 +1,4 @@ -import { expect } from '../node_modules/chai/chai.js'; +import { expect } from 'chai'; import keysyms from '../core/input/keysymdef.js'; import * as KeyboardUtil from "../core/input/util.js"; diff --git a/tests/test.hextile.js b/tests/test.hextile.js index 5a59e97b0..70607bef4 100644 --- a/tests/test.hextile.js +++ b/tests/test.hextile.js @@ -1,5 +1,5 @@ import './assertions.js'; -import { expect } from '../node_modules/chai/chai.js'; +import { expect } from 'chai'; import Websock from '../core/websock.js'; import Display from '../core/display.js'; diff --git a/tests/test.inflator.js b/tests/test.inflator.js index b1ebb7227..8553bebaf 100644 --- a/tests/test.inflator.js +++ b/tests/test.inflator.js @@ -1,5 +1,5 @@ import './assertions.js'; -import { expect } from '../node_modules/chai/chai.js'; +import { expect } from 'chai'; import { deflateInit, deflate, Z_FULL_FLUSH } from "../vendor/pako/lib/zlib/deflate.js"; import ZStream from "../vendor/pako/lib/zlib/zstream.js"; diff --git a/tests/test.int.js b/tests/test.int.js index 641d9db6c..739dde895 100644 --- a/tests/test.int.js +++ b/tests/test.int.js @@ -1,4 +1,4 @@ -import { expect } from '../node_modules/chai/chai.js'; +import { expect } from 'chai'; import { toUnsigned32bit, toSigned32bit } from '../core/util/int.js'; diff --git a/tests/test.jpeg.js b/tests/test.jpeg.js index b50f22a5d..692de4488 100644 --- a/tests/test.jpeg.js +++ b/tests/test.jpeg.js @@ -1,5 +1,5 @@ import './assertions.js'; -import { expect } from '../node_modules/chai/chai.js'; +import { expect } from 'chai'; import Websock from '../core/websock.js'; import Display from '../core/display.js'; diff --git a/tests/test.keyboard.js b/tests/test.keyboard.js index d7c4de8ae..14d0ff428 100644 --- a/tests/test.keyboard.js +++ b/tests/test.keyboard.js @@ -1,6 +1,6 @@ import './assertions.js'; -import { expect } from '../node_modules/chai/chai.js'; -import sinon from '../node_modules/sinon/pkg/sinon-esm.js'; +import { expect } from 'chai'; +import sinon from 'sinon'; import Keyboard from '../core/input/keyboard.js'; diff --git a/tests/test.localization.js b/tests/test.localization.js index 2d05d1c64..9678f2d34 100644 --- a/tests/test.localization.js +++ b/tests/test.localization.js @@ -1,6 +1,6 @@ import './assertions.js'; -import { expect } from '../node_modules/chai/chai.js'; -import sinon from '../node_modules/sinon/pkg/sinon-esm.js'; +import { expect } from 'chai'; +import sinon from 'sinon'; import _, { Localizer, l10n } from '../app/localization.js'; diff --git a/tests/test.raw.js b/tests/test.raw.js index 2c62916d2..aff9384f1 100644 --- a/tests/test.raw.js +++ b/tests/test.raw.js @@ -1,5 +1,5 @@ import './assertions.js'; -import { expect } from '../node_modules/chai/chai.js'; +import { expect } from 'chai'; import Websock from '../core/websock.js'; import Display from '../core/display.js'; diff --git a/tests/test.rfb.js b/tests/test.rfb.js index e7c55b28e..3cf8fcd86 100644 --- a/tests/test.rfb.js +++ b/tests/test.rfb.js @@ -1,6 +1,6 @@ import './assertions.js'; -import { expect } from '../node_modules/chai/chai.js'; -import sinon from '../node_modules/sinon/pkg/sinon-esm.js'; +import { expect } from 'chai'; +import sinon from 'sinon'; import RFB from '../core/rfb.js'; import Websock from '../core/websock.js'; diff --git a/tests/test.rre.js b/tests/test.rre.js index 9ad931bc7..d16a26e1e 100644 --- a/tests/test.rre.js +++ b/tests/test.rre.js @@ -1,5 +1,5 @@ import './assertions.js'; -import { expect } from '../node_modules/chai/chai.js'; +import { expect } from 'chai'; import Websock from '../core/websock.js'; import Display from '../core/display.js'; diff --git a/tests/test.tight.js b/tests/test.tight.js index bfa30d643..2162dd0f6 100644 --- a/tests/test.tight.js +++ b/tests/test.tight.js @@ -1,5 +1,5 @@ import './assertions.js'; -import { expect } from '../node_modules/chai/chai.js'; +import { expect } from 'chai'; import Websock from '../core/websock.js'; import Display from '../core/display.js'; diff --git a/tests/test.tightpng.js b/tests/test.tightpng.js index a52cfd5dc..cac586d62 100644 --- a/tests/test.tightpng.js +++ b/tests/test.tightpng.js @@ -1,5 +1,5 @@ import './assertions.js'; -import { expect } from '../node_modules/chai/chai.js'; +import { expect } from 'chai'; import Websock from '../core/websock.js'; import Display from '../core/display.js'; diff --git a/tests/test.util.js b/tests/test.util.js index f836f4b2f..766e51ed7 100644 --- a/tests/test.util.js +++ b/tests/test.util.js @@ -1,7 +1,7 @@ /* eslint-disable no-console */ import './assertions.js'; -import { expect } from '../node_modules/chai/chai.js'; -import sinon from '../node_modules/sinon/pkg/sinon-esm.js'; +import { expect } from 'chai'; +import sinon from 'sinon'; import * as Log from '../core/util/logging.js'; import { encodeUTF8, decodeUTF8 } from '../core/util/strings.js'; diff --git a/tests/test.websock.js b/tests/test.websock.js index 3509b36ea..f13404902 100644 --- a/tests/test.websock.js +++ b/tests/test.websock.js @@ -1,6 +1,6 @@ import './assertions.js'; -import { expect } from '../node_modules/chai/chai.js'; -import sinon from '../node_modules/sinon/pkg/sinon-esm.js'; +import { expect } from 'chai'; +import sinon from 'sinon'; import Websock from '../core/websock.js'; import FakeWebSocket from './fake.websocket.js'; diff --git a/tests/test.webutil.js b/tests/test.webutil.js index 6046c3f07..4bea3ca55 100644 --- a/tests/test.webutil.js +++ b/tests/test.webutil.js @@ -1,8 +1,8 @@ /* jshint expr: true */ import './assertions.js'; -import { expect } from '../node_modules/chai/chai.js'; -import sinon from '../node_modules/sinon/pkg/sinon-esm.js'; +import { expect } from 'chai'; +import sinon from 'sinon'; import * as WebUtil from '../app/webutil.js'; diff --git a/tests/test.zrle.js b/tests/test.zrle.js index 27e2a02cb..a2203b101 100644 --- a/tests/test.zrle.js +++ b/tests/test.zrle.js @@ -1,5 +1,5 @@ import './assertions.js'; -import { expect } from '../node_modules/chai/chai.js'; +import { expect } from 'chai'; import Websock from '../core/websock.js'; import Display from '../core/display.js'; diff --git a/web-test-runner.config.mjs b/web-test-runner.config.mjs new file mode 100644 index 000000000..96901af2e --- /dev/null +++ b/web-test-runner.config.mjs @@ -0,0 +1,13 @@ +import { defaultReporter } from '@web/test-runner'; +import { summaryReporter } from '@web/test-runner'; + +export default { + nodeResolve: true, + files: [ + 'tests/test.*.js', + ], + reporters: [ + defaultReporter(), + summaryReporter(), + ] +}; \ No newline at end of file From edb5dde6a7b13af36edbd338178e07b6580101e4 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 5 Aug 2024 13:40:36 +0200 Subject: [PATCH 4/7] TEMP: test on all browsers --- .github/workflows/test.yml | 8 ++--- package.json | 3 +- web-test-runner.config.mjs | 63 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b72195b52..302f2a104 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,13 +10,13 @@ jobs: - ubuntu-latest - windows-latest browser: - - ChromeHeadless - - FirefoxHeadless + - chrome + - firefox include: - os: macos-latest - browser: Safari + browser: safari - os: windows-latest - browser: EdgeHeadless + browser: edge fail-fast: false runs-on: ${{ matrix.os }} steps: diff --git a/package.json b/package.json index 1558d838d..111155afa 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,8 @@ "po2json": "latest", "sinon": "latest", "sinon-chai": "latest", - "@web/test-runner": "latest" + "@web/test-runner": "latest", + "@web/test-runner-webdriver": "latest" }, "keywords": [ "vnc", diff --git a/web-test-runner.config.mjs b/web-test-runner.config.mjs index 96901af2e..e5a1e7cc8 100644 --- a/web-test-runner.config.mjs +++ b/web-test-runner.config.mjs @@ -1,11 +1,74 @@ import { defaultReporter } from '@web/test-runner'; import { summaryReporter } from '@web/test-runner'; +import { webdriverLauncher } from '@web/test-runner-webdriver'; + +let browsers; +let launchers; + +if (process.env.TEST_BROWSER_NAME) { + browsers = process.env.TEST_BROWSER_NAME.split(','); +} else { + browsers = ['chrome', 'firefox']; + if (process.platform === 'win32') { + browsers.push('edge'); + } + if (process.platform === 'darwin') { + browsers.push('safari'); + } +} + +launchers = []; + +for (let browser of browsers) { + switch (browser) { + case 'chrome': + launchers.push(webdriverLauncher({ + capabilities: { + browserName: 'chrome', + 'goog:chromeOptions': { + args: ['headless', 'disable-gpu'] + }, + }, + })); + break; + case 'firefox': + launchers.push(webdriverLauncher({ + capabilities: { + browserName: 'firefox', + 'moz:firefoxOptions': { + args: ['-headless'] + } + }, + })); + break; + case 'edge': + launchers.push(webdriverLauncher({ + capabilities: { + browserName: 'edge', + 'ms:edgeOptions': { + args: ['--headless'] + } + }, + })); + break; + case 'safari': + launchers.push(webdriverLauncher({ + capabilities: { + browserName: 'safari', + }, + })); + break; + default: + throw new Error('Unknown browser: ' + browser); + } +} export default { nodeResolve: true, files: [ 'tests/test.*.js', ], + browsers: launchers, reporters: [ defaultReporter(), summaryReporter(), From f412a88a07a59050c69934af125a8b2610f7d323 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 5 Aug 2024 13:40:48 +0200 Subject: [PATCH 5/7] Silence logging during tests It's even more in the way now with the new test runner, so let's silence it in the tests that log things. --- tests/test.rfb.js | 4 ++++ tests/test.util.js | 10 +++++----- tests/test.webutil.js | 4 ++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/test.rfb.js b/tests/test.rfb.js index 3cf8fcd86..71129dcd4 100644 --- a/tests/test.rfb.js +++ b/tests/test.rfb.js @@ -7,6 +7,7 @@ import Websock from '../core/websock.js'; import ZStream from "../vendor/pako/lib/zlib/zstream.js"; import { deflateInit, deflate, Z_DEFAULT_COMPRESSION } from "../vendor/pako/lib/zlib/deflate.js"; import { encodings } from '../core/encodings.js'; +import { initLogging } from '../core/util/logging.js'; import { toUnsigned32bit } from '../core/util/int.js'; import { encodeUTF8 } from '../core/util/strings.js'; import KeyTable from '../core/input/keysym.js'; @@ -115,6 +116,9 @@ describe('Remote Frame Buffer Protocol Client', function () { // Avoiding printing the entire Websock buffer on errors Websock.prototype.inspect = function () { return "[object Websock]"; }; + + // Avoid spamming test output + initLogging('none'); }); after(function () { diff --git a/tests/test.util.js b/tests/test.util.js index 766e51ed7..8a48f6a71 100644 --- a/tests/test.util.js +++ b/tests/test.util.js @@ -11,11 +11,11 @@ describe('Utils', function () { describe('logging functions', function () { beforeEach(function () { - sinon.spy(console, 'log'); - sinon.spy(console, 'debug'); - sinon.spy(console, 'warn'); - sinon.spy(console, 'error'); - sinon.spy(console, 'info'); + sinon.stub(console, 'log'); + sinon.stub(console, 'debug'); + sinon.stub(console, 'warn'); + sinon.stub(console, 'error'); + sinon.stub(console, 'info'); }); afterEach(function () { diff --git a/tests/test.webutil.js b/tests/test.webutil.js index 4bea3ca55..4ed087cb6 100644 --- a/tests/test.webutil.js +++ b/tests/test.webutil.js @@ -5,6 +5,7 @@ import { expect } from 'chai'; import sinon from 'sinon'; import * as WebUtil from '../app/webutil.js'; +import { initLogging } from '../core/util/logging.js'; describe('WebUtil', function () { "use strict"; @@ -67,6 +68,9 @@ describe('WebUtil', function () { before(function () { chrome = window.chrome; window.chrome = null; + + // Avoid spamming test output + initLogging('none'); }); after(function () { window.chrome = chrome; From 9a4beb64a36a46060263427d5181e100bcdd7cb0 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 5 Aug 2024 14:18:04 +0200 Subject: [PATCH 6/7] Quickly abort hung tests The default timeout is an absurd two minutes. Let's try to be more responsive. --- web-test-runner.config.mjs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/web-test-runner.config.mjs b/web-test-runner.config.mjs index e5a1e7cc8..8c312d67d 100644 --- a/web-test-runner.config.mjs +++ b/web-test-runner.config.mjs @@ -72,5 +72,7 @@ export default { reporters: [ defaultReporter(), summaryReporter(), - ] + ], + // We have small test files, so let's kill hangs quickly + testsFinishTimeout: 10000, }; \ No newline at end of file From 9ddd7160d3463ec16ba7ccc10d8a3715ed94d319 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 5 Aug 2024 16:36:28 +0200 Subject: [PATCH 7/7] TEMP: fail a test --- tests/test.keyboard.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test.keyboard.js b/tests/test.keyboard.js index 14d0ff428..0fdacd0c8 100644 --- a/tests/test.keyboard.js +++ b/tests/test.keyboard.js @@ -595,7 +595,7 @@ describe('Key Event Handling', function () { expect(kbd.onkeyevent).to.have.been.calledWith(0xffe1, 'ShiftLeft', true); kbd.onkeyevent.resetHistory(); - kbd._handleKeyDown(keyevent('keydown', {code: 'ShiftRight', key: 'Shift', location: 2})); + kbd._handleKeyDown(keyevent('keydown', {code: 'ShiftRight', key: 'ShiftFoo', location: 2})); expect(kbd.onkeyevent).to.have.been.calledOnce; expect(kbd.onkeyevent).to.have.been.calledWith(0xffe2, 'ShiftRight', true); kbd.onkeyevent.resetHistory();