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 13b1a32a..f6050b14 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 a7012271..ea0003b6 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 e5644dcd..120608e3 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 692cc23b..fa82e7bc 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 60c39528..82a9bf36 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 b565b907..2da03823 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 d2c51793..48e90a43 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 d2e27ed2..e3c2e32a 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 2c8720c7..04428dd1 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 f788fd4d..3fea3023 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 11a02f2f..8bf4f6f3 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 378ebd58..641d9db6 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 5cc153f9..4340242f 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 11c8b6eb..4296486f 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 a1cb4547..e49a0735 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 19b2377f..e3d8b457 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 2be3bfbf..b4d59e02 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 7b5f73d0..5ca0d732 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 3d6b555d..28080bf4 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 e7edc8fa..01d2493e 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 eb724095..16dbb7c9 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 53145b36..38b654a8 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 9151a060..45c71e49 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 f7c6089d..679b4ad3 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 54380ebd..a019887f 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 82a9bf36..ad9f8b31 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 2da03823..76c4d8f1 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 48e90a43..131e76d1 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 e3c2e32a..880cdd14 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 3fea3023..5a59e97b 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 8bf4f6f3..b1ebb722 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 4340242f..b50f22a5 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 4296486f..d7c4de8a 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 e49a0735..2d05d1c6 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 e3d8b457..2c62916d 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 b4d59e02..e7c55b28 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 5ca0d732..9ad931bc 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 28080bf4..bfa30d64 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 01d2493e..a52cfd5d 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 16dbb7c9..f836f4b2 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 38b654a8..3509b36e 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 45c71e49..6046c3f0 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 679b4ad3..27e2a02c 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 a019887f..00000000 --- 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 e28850a8..1558d838 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 ea0003b6..34ab038f 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 120608e3..b29a80d8 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 fa82e7bc..936db2a1 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 ad9f8b31..81e425c6 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 76c4d8f1..18170941 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 131e76d1..37990e8e 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 880cdd14..798eab19 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 04428dd1..17fc568e 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 5a59e97b..70607bef 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 b1ebb722..8553beba 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 641d9db6..739dde89 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 b50f22a5..692de448 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 d7c4de8a..14d0ff42 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 2d05d1c6..9678f2d3 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 2c62916d..aff9384f 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 e7c55b28..3cf8fcd8 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 9ad931bc..d16a26e1 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 bfa30d64..2162dd0f 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 a52cfd5d..cac586d6 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 f836f4b2..766e51ed 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 3509b36e..f1340490 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 6046c3f0..4bea3ca5 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 27e2a02c..a2203b10 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 00000000..96901af2 --- /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 b72195b5..302f2a10 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 1558d838..111155af 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 96901af2..e5a1e7cc 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 3cf8fcd8..71129dcd 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 766e51ed..8a48f6a7 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 4bea3ca5..4ed087cb 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 e5a1e7cc..8c312d67 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 14d0ff42..0fdacd0c 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();