From 0797a5686ac484e7c42178474eb693aa0ee66746 Mon Sep 17 00:00:00 2001 From: Ibrahim Ansari Date: Sun, 18 Feb 2024 20:47:31 +0530 Subject: [PATCH] WIP: Migrate tests to ES modules The Jasmine port isn't ideal, but this should be good to merge. --- installed-tests/fixtures/backend.js | 16 +++--- .../fixtures/components/clipboard.js | 8 +-- installed-tests/fixtures/components/index.js | 13 +++++ installed-tests/fixtures/components/input.js | 6 +- installed-tests/fixtures/components/mpris.js | 10 ++-- .../fixtures/components/notification.js | 9 +-- .../fixtures/components/pulseaudio.js | 9 ++- .../fixtures/components/session.js | 6 +- installed-tests/fixtures/components/sound.js | 9 ++- installed-tests/fixtures/components/upower.js | 8 +-- installed-tests/fixtures/mpris.js | 16 +++--- installed-tests/fixtures/utils.js | 57 ++++++++----------- installed-tests/jasmine.js | 2 +- installed-tests/minijasmine | 34 +++++------ .../suites/backends/testLanBackend.js | 13 ++--- .../components/testClipboardComponent.js | 11 ++-- .../suites/components/testMprisComponent.js | 16 +++--- installed-tests/suites/core/testDevice.js | 14 ++--- installed-tests/suites/core/testManager.js | 9 ++- installed-tests/suites/core/testPacket.js | 9 +-- installed-tests/suites/core/testPlugin.js | 23 ++++---- .../suites/plugins/testBatteryPlugin.js | 6 +- .../suites/plugins/testClipboardPlugin.js | 6 +- .../suites/plugins/testContactsPlugin.js | 9 +-- .../suites/plugins/testFindmyphonePlugin.js | 6 +- .../suites/plugins/testMousepadPlugin.js | 8 +-- .../suites/plugins/testMprisPlugin.js | 6 +- .../suites/plugins/testNotificationPlugin.js | 9 ++- .../suites/plugins/testPingPlugin.js | 4 +- .../suites/plugins/testPresenterPlugin.js | 4 +- .../suites/plugins/testRuncommandPlugin.js | 6 +- .../suites/plugins/testSftpPlugin.js | 6 +- .../suites/plugins/testSharePlugin.js | 4 +- .../suites/plugins/testSmsPlugin.js | 4 +- .../suites/plugins/testSystemvolumePlugin.js | 6 +- .../suites/plugins/testTelephonyPlugin.js | 6 +- src/service/components/index.js | 2 +- src/service/plugins/contacts.js | 3 + 38 files changed, 180 insertions(+), 213 deletions(-) create mode 100644 installed-tests/fixtures/components/index.js diff --git a/installed-tests/fixtures/backend.js b/installed-tests/fixtures/backend.js index e126c35e7..a6fdd8e0e 100644 --- a/installed-tests/fixtures/backend.js +++ b/installed-tests/fixtures/backend.js @@ -2,14 +2,12 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; +import Gio from 'gi://Gio'; +import GLib from 'gi://GLib'; +import GObject from 'gi://GObject'; -const Gio = imports.gi.Gio; -const GLib = imports.gi.GLib; -const GObject = imports.gi.GObject; - -const Config = imports.config; -const Core = imports.service.core; +import Config from '../config.js'; +const Core = await import(`file://${Config.PACKAGE_DATADIR}/service/core.js`); /** @@ -24,7 +22,7 @@ const TRANSFER_MAX = 2764; * A simple IP-based backend for tests. This should ostensibly be kept up to * date with backends/lan.js as it is essentially a clone without the TLS parts. */ -var ChannelService = GObject.registerClass({ +export const ChannelService = GObject.registerClass({ GTypeName: 'GSConnectMockChannelService', Properties: { 'port': GObject.ParamSpec.uint( @@ -347,7 +345,7 @@ var ChannelService = GObject.registerClass({ /** * A simple IP-based channel for tests */ -var Channel = GObject.registerClass({ +export const Channel = GObject.registerClass({ GTypeName: 'GSConnectMockChannel', }, class MockChannel extends Core.Channel { diff --git a/installed-tests/fixtures/components/clipboard.js b/installed-tests/fixtures/components/clipboard.js index 617eed1d3..6243e72fd 100644 --- a/installed-tests/fixtures/components/clipboard.js +++ b/installed-tests/fixtures/components/clipboard.js @@ -2,12 +2,10 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; +import GObject from 'gi://GObject'; -const {GObject} = imports.gi; - -var Component = GObject.registerClass({ +const Component = GObject.registerClass({ GTypeName: 'MockClipboard', Properties: { 'text': GObject.ParamSpec.string( @@ -36,3 +34,5 @@ var Component = GObject.registerClass({ } }); +export default Component; + diff --git a/installed-tests/fixtures/components/index.js b/installed-tests/fixtures/components/index.js new file mode 100644 index 000000000..7d128e11e --- /dev/null +++ b/installed-tests/fixtures/components/index.js @@ -0,0 +1,13 @@ +// SPDX-FileCopyrightText: GSConnect Developers https://github.com/GSConnect +// +// SPDX-License-Identifier: GPL-2.0-or-later + +export {default as clipboard} from './clipboard.js'; +export {default as input} from './input.js'; +export {default as mpris} from './mpris.js'; +export {default as notification} from './notification.js'; +export {default as pulseaudio} from './pulseaudio.js'; +export {default as session} from './session.js'; +export {default as sound} from './sound.js'; +export {default as upower} from './upower.js'; + diff --git a/installed-tests/fixtures/components/input.js b/installed-tests/fixtures/components/input.js index feba057bb..ee7f0d50d 100644 --- a/installed-tests/fixtures/components/input.js +++ b/installed-tests/fixtures/components/input.js @@ -2,10 +2,8 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; - -var Component = class { +export default class Component { clickPointer() {} doubleclickPointer() {} @@ -19,5 +17,5 @@ var Component = class { scrollPointer() {} pressKeys() {} -}; +} diff --git a/installed-tests/fixtures/components/mpris.js b/installed-tests/fixtures/components/mpris.js index c350bf118..e81d60126 100644 --- a/installed-tests/fixtures/components/mpris.js +++ b/installed-tests/fixtures/components/mpris.js @@ -2,10 +2,10 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; +import GObject from 'gi://GObject'; -const {GObject} = imports.gi; -const MPRIS = imports.service.components.mpris; +import Config from '../../config.js'; +const MPRIS = await import(`file://${Config.PACKAGE_DATADIR}/service/components/mpris.js`); const MockMediaPlayer = GObject.registerClass({ @@ -96,7 +96,7 @@ const MockMediaPlayer = GObject.registerClass({ }); -var Component = GObject.registerClass({ +const Component = GObject.registerClass({ GTypeName: 'MockMPRISManager', Signals: { 'player-added': { @@ -183,3 +183,5 @@ var Component = GObject.registerClass({ } }); +export default Component; + diff --git a/installed-tests/fixtures/components/notification.js b/installed-tests/fixtures/components/notification.js index 44d676d14..d5ca2e7e8 100644 --- a/installed-tests/fixtures/components/notification.js +++ b/installed-tests/fixtures/components/notification.js @@ -2,12 +2,11 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; +import GLib from 'gi://GLib'; +import GObject from 'gi://GObject'; -const {Gio, GLib, GObject} = imports.gi; - -var Component = GObject.registerClass({ +const Component = GObject.registerClass({ GTypeName: 'GSConnectMockNotificationListener', Signals: { 'notification-added': { @@ -23,3 +22,5 @@ var Component = GObject.registerClass({ } }); +export default Component; + diff --git a/installed-tests/fixtures/components/pulseaudio.js b/installed-tests/fixtures/components/pulseaudio.js index c4f30a2a3..8cbcd7ff4 100644 --- a/installed-tests/fixtures/components/pulseaudio.js +++ b/installed-tests/fixtures/components/pulseaudio.js @@ -2,13 +2,10 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; +import GObject from 'gi://GObject'; const Tweener = imports.tweener.tweener; -const GLib = imports.gi.GLib; -const GObject = imports.gi.GObject; - class MockStream { constructor(mixer, id) { @@ -100,7 +97,7 @@ class MockStream { } -var Component = GObject.registerClass({ +const Component = GObject.registerClass({ GTypeName: 'GSConnectMockMixer', Signals: { 'output-added': { @@ -232,3 +229,5 @@ var Component = GObject.registerClass({ } }); +export default Component; + diff --git a/installed-tests/fixtures/components/session.js b/installed-tests/fixtures/components/session.js index b82a78c2e..b07692a0f 100644 --- a/installed-tests/fixtures/components/session.js +++ b/installed-tests/fixtures/components/session.js @@ -2,10 +2,8 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; - -var Component = class MockSession { +export default class MockSessionComponent { get idle() { if (this._idle === undefined) this._idle = false; @@ -34,5 +32,5 @@ var Component = class MockSession { for (const [propertyName, propertyValue] of Object.entries(obj)) this[`_${propertyName}`] = propertyValue; } -}; +} diff --git a/installed-tests/fixtures/components/sound.js b/installed-tests/fixtures/components/sound.js index 23c36a5ed..b3d692064 100644 --- a/installed-tests/fixtures/components/sound.js +++ b/installed-tests/fixtures/components/sound.js @@ -2,12 +2,11 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; +import Gio from 'gi://Gio'; +import GLib from 'gi://GLib'; -const {Gio, GLib} = imports.gi; - -var Component = class MockPlayer { +export default class MockPlayerComponent { constructor() { this._playing = new Set(); @@ -60,5 +59,5 @@ var Component = class MockPlayer { this._playing.delete(cancellable); } } -}; +} diff --git a/installed-tests/fixtures/components/upower.js b/installed-tests/fixtures/components/upower.js index 88796d49e..b8be6b13b 100644 --- a/installed-tests/fixtures/components/upower.js +++ b/installed-tests/fixtures/components/upower.js @@ -2,12 +2,10 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; +import GObject from 'gi://GObject'; -const {GObject} = imports.gi; - -var Component = GObject.registerClass({ +const Component = GObject.registerClass({ GTypeName: 'GSConnectMockBattery', Signals: { 'changed': {flags: GObject.SignalFlags.RUN_FIRST}, @@ -50,3 +48,5 @@ var Component = GObject.registerClass({ } }); +export default Component; + diff --git a/installed-tests/fixtures/mpris.js b/installed-tests/fixtures/mpris.js index 770f7a638..fabb6f746 100644 --- a/installed-tests/fixtures/mpris.js +++ b/installed-tests/fixtures/mpris.js @@ -2,13 +2,12 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; +import Gio from 'gi://Gio'; +import GObject from 'gi://GObject'; -const {Gio, GLib, GObject} = imports.gi; - -const Config = imports.config; -const DBus = imports.service.utils.dbus; -const MPRIS = imports.service.components.mpris; +import Config from '../config.js'; +const DBus = await import(`file://${Config.PACKAGE_DATADIR}/service/utils/dbus.js`); +const MPRIS = await import(`file://${Config.PACKAGE_DATADIR}/service/components/mpris.js`); /* @@ -18,7 +17,7 @@ const MPRISIface = Config.DBUS.lookup_interface('org.mpris.MediaPlayer2'); const MPRISPlayerIface = Config.DBUS.lookup_interface('org.mpris.MediaPlayer2.Player'); -var MockPlayer = GObject.registerClass({ +const MockPlayer = GObject.registerClass({ GTypeName: 'GSConnectMockPlayer', }, class MockPlayer extends MPRIS.Player { @@ -123,3 +122,6 @@ var MockPlayer = GObject.registerClass({ } } }); + +export default MockPlayer; + diff --git a/installed-tests/fixtures/utils.js b/installed-tests/fixtures/utils.js index f5fe8316c..4a6b57aca 100644 --- a/installed-tests/fixtures/utils.js +++ b/installed-tests/fixtures/utils.js @@ -2,17 +2,15 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; +import 'gi://Gdk?version=3.0'; +import 'gi://Gtk?version=3.0'; -imports.gi.versions.Gdk = '3.0'; -imports.gi.versions.Gtk = '3.0'; - -const ByteArray = imports.byteArray; -const {Gio, GLib} = imports.gi; +import Gio from 'gi://Gio'; +import GLib from 'gi://GLib'; // Ensure the environment is prepared for testing -const Config = imports.config; +import Config from '../config.js'; if (GLib.getenv('GSCONNECT_TEST')) { Config.PACKAGE_DATADIR = GLib.getenv('GJS_PATH'); @@ -21,16 +19,14 @@ if (GLib.getenv('GSCONNECT_TEST')) { GLib.setenv('G_DEBUG', 'fatal-warnings,fatal-criticals', true); GLib.setenv('GSETTINGS_BACKEND', 'memory', true); GLib.setenv('NO_AT_BRIDGE', '1', true); - - imports.searchPath.unshift(Config.PACKAGE_DATADIR); } -const _setup = imports.service.utils.setup; -const {Device} = imports.service.device; -const {Plugin} = imports.service.plugin; +await import(`file://${Config.PACKAGE_DATADIR}/service/init.js`); +const {default: Device} = await import(`file://${Config.PACKAGE_DATADIR}/service/device.js`); +const {default: Plugin} = await import(`file://${Config.PACKAGE_DATADIR}/service/plugin.js`); -const {ChannelService} = imports.fixtures.backend; +const {ChannelService} = await import('./backend.js'); // Force testing under GNOME @@ -41,8 +37,7 @@ globalThis.HAVE_GNOME = true; * File Helpers */ function get_datadir() { - const thisPath = /@(.+):\d+/.exec((new Error()).stack.split('\n')[1])[1]; - const thisFile = Gio.File.new_for_path(thisPath); + const thisFile = Gio.File.new_for_uri(import.meta.url); return thisFile.get_parent().get_parent().get_child('data').get_path(); } @@ -50,26 +45,26 @@ function get_datadir() { const DATA_PATH = get_datadir(); -function getDataPath(filename) { +export function getDataPath(filename) { return GLib.build_filenamev([DATA_PATH, filename]); } -function getDataUri(filename) { +export function getDataUri(filename) { return `file://${getDataPath(filename)}`; } -function getDataFile(filename) { +export function getDataFile(filename) { return Gio.File.new_for_path(getDataPath(filename)); } -function loadDataContents(filename) { +export function loadDataContents(filename) { const path = getDataPath(filename); const bytes = GLib.file_get_contents(path)[1]; - return ByteArray.toString(bytes); + return new TextDecoder().decode(bytes); } @@ -107,7 +102,7 @@ function getDeviceType() { * @param {Object} params - Override parameters * @return {Object} A pseudo-random identity packet */ -function generateIdentity(params = {}) { +export function generateIdentity(params = {}) { const identity = { 'id': Date.now(), 'type': 'kdeconnect.identity', @@ -210,7 +205,6 @@ Plugin.prototype.awaitPacket = _awaitPacket; * @return {string} The root temporary directory */ function isolateDirectories() { - const Config = imports.config; const tmpdir = GLib.Dir.make_tmp('gsconnect.XXXXXX'); Config.CACHEDIR = GLib.build_filenamev([tmpdir, 'cache']); @@ -227,17 +221,12 @@ function isolateDirectories() { /** * Patch in the mock components for plugin tests. */ -function mockComponents() { - const Components = imports.service.components; - const MockComponents = imports.fixtures.components; - - Components.acquire = function (name) { - return new MockComponents[name].Component(); - }; +export async function mockComponents() { + const {components} = await import(`file://${Config.PACKAGE_DATADIR}/service/components/index.js`); + const MockComponents = await import('./components/index.js'); - Components.release = function (name) { - return null; - }; + for (const [name, module] of Object.entries(MockComponents)) + components[name] = module; } /** @@ -272,7 +261,7 @@ function removeDirectory(file) { /** * A test rig with two active GSconnectChannelService instances. */ -var TestRig = class { +export class TestRig { /** * Create a new test rig. * @@ -399,5 +388,5 @@ var TestRig = class { if (this._tmpdir) removeDirectory(this._tmpdir); } -}; +} diff --git a/installed-tests/jasmine.js b/installed-tests/jasmine.js index 71998339b..6dc761b79 100644 --- a/installed-tests/jasmine.js +++ b/installed-tests/jasmine.js @@ -5,7 +5,7 @@ // SPDX-License-Identifier: MPL-2.0 // eslint-disable-next-line no-unused-vars -var getJasmineRequireObj = (function(jasmineGlobal) { +export const getJasmineRequireObj = (function(jasmineGlobal) { var jasmineRequire; if ( diff --git a/installed-tests/minijasmine b/installed-tests/minijasmine index 69a0898ba..ac5672518 100755 --- a/installed-tests/minijasmine +++ b/installed-tests/minijasmine @@ -1,10 +1,12 @@ -#!/usr/bin/env gjs +#!/usr/bin/env -S gjs -m // SPDX-FileCopyrightText: GSConnect Developers https://github.com/GSConnect // // SPDX-License-Identifier: GPL-2.0-or-later -const {GLib} = imports.gi; +import GLib from 'gi://GLib'; +import system from 'system'; +import {getJasmineRequireObj} from './jasmine.js'; // Utils @@ -93,13 +95,8 @@ class TapReporter { * Initialize Jasmine */ function initJasmine() { - // Add the current path to the importer - const thisFile = /@(.+):\d+/.exec(Error().stack.split('\n')[1])[1]; - const thisDir = GLib.path_get_dirname(thisFile); - imports.searchPath.unshift(thisDir); - // Load Jasmine - const jasmineRequire = imports.jasmine.getJasmineRequireObj(); + const jasmineRequire = getJasmineRequireObj(); const jasmineCore = jasmineRequire.core(jasmineRequire); globalThis._jasmineEnv = jasmineCore.getEnv(); @@ -118,21 +115,16 @@ function initJasmine() { /** * Initialize test suites */ -function initTests() { - // Add the test path to the importer - const testDir = GLib.path_get_dirname(ARGV[0]); - imports.searchPath.unshift(testDir); - - // Load the test suites - const testPath = GLib.path_get_basename(ARGV[0]).slice(0, -3); - void imports[testPath]; +async function initTests() { + // Load the test suite + await import(`file://${ARGV[0]}`); } /** * Run initialized tests */ -function runTests() { +async function runTests() { GLib.idle_add(GLib.PRIORITY_DEFAULT, function () { try { globalThis._jasmineEnv.execute(); @@ -144,7 +136,7 @@ function runTests() { return GLib.SOURCE_REMOVE; }); - globalThis._jasmineMain.run(); + await globalThis._jasmineMain.runAsync(); // Exhaust the event loop const context = GLib.MainContext.default(); @@ -153,12 +145,12 @@ function runTests() { continue; // Return the exit status - imports.system.exit(globalThis._jasmineRetval); + system.exit(globalThis._jasmineRetval); } // TODO: add CLI options for isolated XDG, DBus, etc initJasmine(); -initTests(); -runTests(); +await initTests(); +await runTests(); diff --git a/installed-tests/suites/backends/testLanBackend.js b/installed-tests/suites/backends/testLanBackend.js index f97a709f1..53121a9d4 100644 --- a/installed-tests/suites/backends/testLanBackend.js +++ b/installed-tests/suites/backends/testLanBackend.js @@ -2,15 +2,14 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; +import Gio from 'gi://Gio'; +import GLib from 'gi://GLib'; -const {Gio, GLib} = imports.gi; +import * as Utils from '../fixtures/utils.js'; -const Utils = imports.fixtures.utils; - -const Core = imports.service.core; -const Device = imports.service.device; -const Lan = imports.service.backends.lan; +import Config from '../config.js'; +const Core = await import(`file://${Config.PACKAGE_DATADIR}/service/core.js`); +const Lan = await import(`file://${Config.PACKAGE_DATADIR}/service/backends/lan.js`); describe('A LAN channel service', function () { diff --git a/installed-tests/suites/components/testClipboardComponent.js b/installed-tests/suites/components/testClipboardComponent.js index d3832f381..9322a8822 100644 --- a/installed-tests/suites/components/testClipboardComponent.js +++ b/installed-tests/suites/components/testClipboardComponent.js @@ -2,13 +2,14 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; +import '../fixtures/utils.js'; -const Utils = imports.fixtures.utils; +import Gdk from 'gi://Gdk'; +import Gtk from 'gi://Gtk'; +import GLib from 'gi://GLib'; -const {Gdk, Gtk, Gio, GLib} = imports.gi; - -const {Clipboard} = imports.service.components.clipboard; +import Config from '../config.js'; +const {default: Clipboard} = await import(`file://${Config.PACKAGE_DATADIR}/service/components/clipboard.js`); describe('The Clipboard component', function () { diff --git a/installed-tests/suites/components/testMprisComponent.js b/installed-tests/suites/components/testMprisComponent.js index 716920db4..b6b14fe33 100644 --- a/installed-tests/suites/components/testMprisComponent.js +++ b/installed-tests/suites/components/testMprisComponent.js @@ -2,18 +2,18 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; +import GLib from 'gi://GLib'; -const {Gio, GLib} = imports.gi; +import '../fixtures/utils.js'; +// import MockPlayer from '../fixtures/mpris.js'; -const Utils = imports.fixtures.utils; -const {MockPlayer} = imports.fixtures.mpris; - -const MPRIS = imports.service.components.mpris; +import Config from '../config.js'; +const {default: MockPlayer} = await import('../fixtures/mpris.js'); // Delay import until init done, FIXME is this needed? +const {default: Manager} = await import(`file://${Config.PACKAGE_DATADIR}/service/components/mpris.js`); // Prevent auto-loading -MPRIS.Manager.prototype._loadPlayers = function () {}; +Manager.prototype._loadPlayers = function () {}; describe('The MPRIS component', function () { @@ -21,7 +21,7 @@ describe('The MPRIS component', function () { let player; beforeAll(function () { - manager = new MPRIS.Manager(); + manager = new Manager(); player = new MockPlayer(GLib.uuid_string_random()); }); diff --git a/installed-tests/suites/core/testDevice.js b/installed-tests/suites/core/testDevice.js index a231d5b18..282b7f2e3 100644 --- a/installed-tests/suites/core/testDevice.js +++ b/installed-tests/suites/core/testDevice.js @@ -2,13 +2,13 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; +import Gio from 'gi://Gio'; +import GLib from 'gi://GLib'; -const {Gio, GLib} = imports.gi; +import * as Utils from '../fixtures/utils.js'; -const Utils = imports.fixtures.utils; - -const Device = imports.service.device; +import Config from '../config.js'; +const {default: Device} = await import(`file://${Config.PACKAGE_DATADIR}/service/device.js`); describe('A device constructed from a packet', function () { @@ -21,7 +21,7 @@ describe('A device constructed from a packet', function () { outgoingCapabilities: ['kdeconnect.ping'], }, }); - device = new Device.Device(identity); + device = new Device(identity); }); afterAll(function () { @@ -70,7 +70,7 @@ describe('A device constructed from an ID', function () { beforeAll(function () { id = GLib.uuid_string_random(); - device = new Device.Device({body: {deviceId: id}}); + device = new Device({body: {deviceId: id}}); }); afterAll(function () { diff --git a/installed-tests/suites/core/testManager.js b/installed-tests/suites/core/testManager.js index 94d6b0368..56f3662a4 100644 --- a/installed-tests/suites/core/testManager.js +++ b/installed-tests/suites/core/testManager.js @@ -2,13 +2,12 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; +import GLib from 'gi://GLib'; -const {GLib} = imports.gi; +import * as Utils from '../fixtures/utils.js'; -const Utils = imports.fixtures.utils; - -const {Manager} = imports.service.manager; +import Config from '../config.js'; +const {default: Manager} = await import(`file://${Config.PACKAGE_DATADIR}/service/manager.js`); // TODO: * device management diff --git a/installed-tests/suites/core/testPacket.js b/installed-tests/suites/core/testPacket.js index b48e4d992..cec7e047d 100644 --- a/installed-tests/suites/core/testPacket.js +++ b/installed-tests/suites/core/testPacket.js @@ -2,13 +2,10 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; +import '../fixtures/utils.js'; -const {Gio, GLib} = imports.gi; - -const Utils = imports.fixtures.utils; - -const Core = imports.service.core; +import Config from '../config.js'; +const Core = await import(`file://${Config.PACKAGE_DATADIR}/service/core.js`); /* diff --git a/installed-tests/suites/core/testPlugin.js b/installed-tests/suites/core/testPlugin.js index bd7a47a55..ac35bb9a7 100644 --- a/installed-tests/suites/core/testPlugin.js +++ b/installed-tests/suites/core/testPlugin.js @@ -2,15 +2,16 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; +import Gio from 'gi://Gio'; +import GLib from 'gi://GLib'; +import GObject from 'gi://GObject'; -const {Gio, GLib, GObject} = imports.gi; +import * as Utils from '../fixtures/utils.js'; -const Utils = imports.fixtures.utils; - -const Device = imports.service.device; -const Components = imports.service.components; -const PluginBase = imports.service.plugin; +import Config from '../config.js'; +const {default: Device} = await import(`file://${Config.PACKAGE_DATADIR}/service/device.js`); +const Components = await import(`file://${Config.PACKAGE_DATADIR}/service/components/index.js`); +const {default: Plugin} = await import(`file://${Config.PACKAGE_DATADIR}/service/plugin.js`); /* @@ -52,7 +53,7 @@ var Metadata = { const TestPlugin = GObject.registerClass({ GTypeName: 'GSConnectTestPlugin', -}, class TestPlugin extends PluginBase.Plugin { +}, class TestPlugin extends Plugin { _init(device) { super._init(device, 'foobarbaz', Metadata); @@ -121,7 +122,7 @@ describe('Plugin GActions', function () { }, }); - device = new Device.Device(identity); + device = new Device(identity); plugin = new TestPlugin(device); spyOn(plugin, 'foo').and.callThrough(); @@ -199,7 +200,7 @@ describe('Plugin packets', function () { }, }); - device = new Device.Device(identity); + device = new Device(identity); plugin = new TestPlugin(device); device._plugins.set('foobarbaz', plugin); @@ -256,7 +257,7 @@ describe('Plugin cache', function () { }, }); - device = new Device.Device(identity); + device = new Device(identity); plugin = new TestPlugin(device); }); diff --git a/installed-tests/suites/plugins/testBatteryPlugin.js b/installed-tests/suites/plugins/testBatteryPlugin.js index ff99f70ce..5fde87d06 100644 --- a/installed-tests/suites/plugins/testBatteryPlugin.js +++ b/installed-tests/suites/plugins/testBatteryPlugin.js @@ -2,9 +2,7 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; - -const Utils = imports.fixtures.utils; +import * as Utils from '../fixtures/utils.js'; const Packets = { @@ -48,7 +46,7 @@ describe('The battery plugin', function () { let localPlugin, remotePlugin; beforeAll(async function () { - Utils.mockComponents(); + await Utils.mockComponents(); testRig = new Utils.TestRig(); await testRig.prepare({ diff --git a/installed-tests/suites/plugins/testClipboardPlugin.js b/installed-tests/suites/plugins/testClipboardPlugin.js index 8e0373ab2..ee5974ab3 100644 --- a/installed-tests/suites/plugins/testClipboardPlugin.js +++ b/installed-tests/suites/plugins/testClipboardPlugin.js @@ -2,9 +2,7 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; - -const Utils = imports.fixtures.utils; +import * as Utils from '../fixtures/utils.js'; describe('The clipboard plugin', function () { @@ -12,7 +10,7 @@ describe('The clipboard plugin', function () { let localPlugin, remotePlugin; beforeAll(async function () { - Utils.mockComponents(); + await Utils.mockComponents(); testRig = new Utils.TestRig(); await testRig.prepare({ diff --git a/installed-tests/suites/plugins/testContactsPlugin.js b/installed-tests/suites/plugins/testContactsPlugin.js index 8a017d0a6..4892a026c 100644 --- a/installed-tests/suites/plugins/testContactsPlugin.js +++ b/installed-tests/suites/plugins/testContactsPlugin.js @@ -2,11 +2,11 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; +import * as Utils from '../fixtures/utils.js'; -const Utils = imports.fixtures.utils; +import GLib from 'gi://GLib'; -const GLib = imports.gi.GLib; +import Config from '../config.js'; const VCards = { @@ -136,7 +136,8 @@ describe('The contacts plugin', function () { while (localPlugin._store.contacts.length) await Promise.idle(); - imports.service.plugins.contacts.EBookContacts = null; + await import(`file://${Config.PACKAGE_DATADIR}/service/plugins/contacts.js`) + .then(({setEBookContacts}) => setEBookContacts(null)); localPlugin._requestVCards(['valid']); diff --git a/installed-tests/suites/plugins/testFindmyphonePlugin.js b/installed-tests/suites/plugins/testFindmyphonePlugin.js index b8f5cbed1..07c4276db 100644 --- a/installed-tests/suites/plugins/testFindmyphonePlugin.js +++ b/installed-tests/suites/plugins/testFindmyphonePlugin.js @@ -2,9 +2,7 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; - -const Utils = imports.fixtures.utils; +import * as Utils from '../fixtures/utils.js'; describe('The findmyphone plugin', function () { @@ -12,7 +10,7 @@ describe('The findmyphone plugin', function () { let localPlugin, remotePlugin; beforeAll(async function () { - Utils.mockComponents(); + await Utils.mockComponents(); testRig = new Utils.TestRig(); await testRig.prepare({ diff --git a/installed-tests/suites/plugins/testMousepadPlugin.js b/installed-tests/suites/plugins/testMousepadPlugin.js index 32b8c5c7a..f92516f01 100644 --- a/installed-tests/suites/plugins/testMousepadPlugin.js +++ b/installed-tests/suites/plugins/testMousepadPlugin.js @@ -2,11 +2,9 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; +import * as Utils from '../fixtures/utils.js'; -const Utils = imports.fixtures.utils; - -const {Gdk} = imports.gi; +import Gdk from 'gi://Gdk'; describe('The mousepad plugin', function () { @@ -14,7 +12,7 @@ describe('The mousepad plugin', function () { let localPlugin, remotePlugin; beforeAll(async function () { - Utils.mockComponents(); + await Utils.mockComponents(); testRig = new Utils.TestRig(); await testRig.prepare({ diff --git a/installed-tests/suites/plugins/testMprisPlugin.js b/installed-tests/suites/plugins/testMprisPlugin.js index db1382d4d..0af284a8a 100644 --- a/installed-tests/suites/plugins/testMprisPlugin.js +++ b/installed-tests/suites/plugins/testMprisPlugin.js @@ -2,9 +2,7 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; - -const Utils = imports.fixtures.utils; +import * as Utils from '../fixtures/utils.js'; describe('The mpris plugin', function () { @@ -12,7 +10,7 @@ describe('The mpris plugin', function () { let localPlugin, remotePlugin; beforeAll(async function () { - Utils.mockComponents(); + await Utils.mockComponents(); testRig = new Utils.TestRig(); await testRig.prepare({ diff --git a/installed-tests/suites/plugins/testNotificationPlugin.js b/installed-tests/suites/plugins/testNotificationPlugin.js index 595a17859..f195f53fe 100644 --- a/installed-tests/suites/plugins/testNotificationPlugin.js +++ b/installed-tests/suites/plugins/testNotificationPlugin.js @@ -2,11 +2,10 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; +import Gio from 'gi://Gio'; +import GLib from 'gi://GLib'; -const {Gio, GLib} = imports.gi; - -const Utils = imports.fixtures.utils; +import * as Utils from '../fixtures/utils.js'; const Notifications = { @@ -59,7 +58,7 @@ describe('The notification plugin', function () { let localPlugin, remotePlugin; beforeAll(async function () { - Utils.mockComponents(); + await Utils.mockComponents(); testRig = new Utils.TestRig(); await testRig.prepare({ diff --git a/installed-tests/suites/plugins/testPingPlugin.js b/installed-tests/suites/plugins/testPingPlugin.js index 766ca763d..d97bdbd2a 100644 --- a/installed-tests/suites/plugins/testPingPlugin.js +++ b/installed-tests/suites/plugins/testPingPlugin.js @@ -2,9 +2,7 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; - -const Utils = imports.fixtures.utils; +import * as Utils from '../fixtures/utils.js'; describe('The ping plugin', function () { diff --git a/installed-tests/suites/plugins/testPresenterPlugin.js b/installed-tests/suites/plugins/testPresenterPlugin.js index 99971e07b..e822dfdd2 100644 --- a/installed-tests/suites/plugins/testPresenterPlugin.js +++ b/installed-tests/suites/plugins/testPresenterPlugin.js @@ -2,9 +2,7 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; - -const Utils = imports.fixtures.utils; +import * as Utils from '../fixtures/utils.js'; describe('The presenter plugin', function () { diff --git a/installed-tests/suites/plugins/testRuncommandPlugin.js b/installed-tests/suites/plugins/testRuncommandPlugin.js index b32a721f9..149f88391 100644 --- a/installed-tests/suites/plugins/testRuncommandPlugin.js +++ b/installed-tests/suites/plugins/testRuncommandPlugin.js @@ -2,11 +2,9 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; +import GLib from 'gi://GLib'; -const {GLib} = imports.gi; - -const Utils = imports.fixtures.utils; +import * as Utils from '../fixtures/utils.js'; describe('The runcommand plugin', function () { diff --git a/installed-tests/suites/plugins/testSftpPlugin.js b/installed-tests/suites/plugins/testSftpPlugin.js index a4552e21a..02abd86dc 100644 --- a/installed-tests/suites/plugins/testSftpPlugin.js +++ b/installed-tests/suites/plugins/testSftpPlugin.js @@ -2,10 +2,10 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; +import * as Utils from '../fixtures/utils.js'; -const Utils = imports.fixtures.utils; -const {Plugin} = imports.service.plugin; +import Config from '../config.js'; +const {default: Plugin} = await import(`file://${Config.PACKAGE_DATADIR}/service/plugin.js`); const Packets = { diff --git a/installed-tests/suites/plugins/testSharePlugin.js b/installed-tests/suites/plugins/testSharePlugin.js index 7c0e3210a..d2dfc4d97 100644 --- a/installed-tests/suites/plugins/testSharePlugin.js +++ b/installed-tests/suites/plugins/testSharePlugin.js @@ -2,9 +2,7 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; - -const Utils = imports.fixtures.utils; +import * as Utils from '../fixtures/utils.js'; describe('The share plugin', function () { diff --git a/installed-tests/suites/plugins/testSmsPlugin.js b/installed-tests/suites/plugins/testSmsPlugin.js index 4f293e8a9..ec75c73d7 100644 --- a/installed-tests/suites/plugins/testSmsPlugin.js +++ b/installed-tests/suites/plugins/testSmsPlugin.js @@ -2,9 +2,7 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; - -const Utils = imports.fixtures.utils; +import * as Utils from '../fixtures/utils.js'; const Packets = { diff --git a/installed-tests/suites/plugins/testSystemvolumePlugin.js b/installed-tests/suites/plugins/testSystemvolumePlugin.js index dca40004f..22440c7c2 100644 --- a/installed-tests/suites/plugins/testSystemvolumePlugin.js +++ b/installed-tests/suites/plugins/testSystemvolumePlugin.js @@ -2,9 +2,7 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; - -const Utils = imports.fixtures.utils; +import * as Utils from '../fixtures/utils.js'; function handlePacket(packet) { @@ -24,7 +22,7 @@ describe('The systemvolume plugin', function () { let remoteDevice; beforeAll(async function () { - Utils.mockComponents(); + await Utils.mockComponents(); testRig = new Utils.TestRig(); await testRig.prepare({ diff --git a/installed-tests/suites/plugins/testTelephonyPlugin.js b/installed-tests/suites/plugins/testTelephonyPlugin.js index 4c671b0f2..48ea110cb 100644 --- a/installed-tests/suites/plugins/testTelephonyPlugin.js +++ b/installed-tests/suites/plugins/testTelephonyPlugin.js @@ -2,9 +2,7 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -'use strict'; - -const Utils = imports.fixtures.utils; +import * as Utils from '../fixtures/utils.js'; const Packets = { @@ -50,7 +48,7 @@ describe('The telephony plugin', function () { let localPlugin, remotePlugin; beforeAll(async function () { - Utils.mockComponents(); + await Utils.mockComponents(); testRig = new Utils.TestRig(); await testRig.prepare({ diff --git a/src/service/components/index.js b/src/service/components/index.js index 15c1b6a34..dd71bb9d9 100644 --- a/src/service/components/index.js +++ b/src/service/components/index.js @@ -14,7 +14,7 @@ import * as sound from './sound.js'; import * as upower from './upower.js'; import * as ydotool from './ydotool.js'; -const components = { +export const components = { atspi, clipboard, contacts, diff --git a/src/service/plugins/contacts.js b/src/service/plugins/contacts.js index 24e0d8379..21687127b 100644 --- a/src/service/plugins/contacts.js +++ b/src/service/plugins/contacts.js @@ -12,6 +12,9 @@ import Contacts from '../components/contacts.js'; * We prefer libebook's vCard parser if it's available */ let EBookContacts; +export const setEBookContacts = (ebook) => { // This function is only for tests to call! + EBookContacts = ebook; +}; try { EBookContacts = (await import('gi://EBookContacts')).default;