From 26fa1046a3a1401ba93161703d32fb538da599c2 Mon Sep 17 00:00:00 2001 From: Evan Welsh Date: Sun, 9 Jul 2023 22:19:40 -0700 Subject: [PATCH] tests: Load unit tests as modules Part-of: --- src/run-js-test.c | 4 ++-- tests/common/assertions.js | 4 +--- tests/unit/highlighter.js | 2 +- tests/unit/insertSorted.js | 3 +-- tests/unit/jsParse.js | 2 +- tests/unit/markup.js | 2 +- tests/unit/signalTracker.js | 2 +- 7 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/run-js-test.c b/src/run-js-test.c index b2cbd82b7..7ebaa0bbd 100644 --- a/src/run-js-test.c +++ b/src/run-js-test.c @@ -45,7 +45,7 @@ main(int argc, char **argv) GjsContext *js_context; const char *filename; char *title; - int code; + uint8_t code; context = g_option_context_new (NULL); @@ -82,7 +82,7 @@ main(int argc, char **argv) error = NULL; /* evaluate the script */ - bool success = gjs_context_eval_file(js_context, filename, &code, &error); + bool success = gjs_context_eval_module_file(js_context, filename, &code, &error); if (!success) { g_printerr ("%s\n", error->message); exit (1); diff --git a/tests/common/assertions.js b/tests/common/assertions.js index a43e55949..c254da0cc 100644 --- a/tests/common/assertions.js +++ b/tests/common/assertions.js @@ -1,5 +1,3 @@ -/* exported assertArrayEquals */ - const JsUnit = imports.jsUnit; /** @@ -10,7 +8,7 @@ const JsUnit = imports.jsUnit; * @param {T[]} array1 the first array * @param {T[]} array2 the second array */ -function assertArrayEquals(errorMessage, array1, array2) { +export function assertArrayEquals(errorMessage, array1, array2) { JsUnit.assertEquals(`${errorMessage} length`, array1.length, array2.length); for (let j = 0; j < array1.length; j++) JsUnit.assertEquals(`${errorMessage} item ${j}`, array1[j], array2[j]); diff --git a/tests/unit/highlighter.js b/tests/unit/highlighter.js index dda206511..961092c31 100644 --- a/tests/unit/highlighter.js +++ b/tests/unit/highlighter.js @@ -3,7 +3,7 @@ // Test cases for SearchResult description match highlighter const JsUnit = imports.jsUnit; -const Pango = imports.gi.Pango; +import Pango from 'gi://Pango'; const Environment = imports.ui.environment; Environment.init(); diff --git a/tests/unit/insertSorted.js b/tests/unit/insertSorted.js index cd9f56606..2fbe6ceb9 100644 --- a/tests/unit/insertSorted.js +++ b/tests/unit/insertSorted.js @@ -1,8 +1,7 @@ /* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */ // Test cases for Util.insertSorted - -const Assertions = imports.common.assertions; +import * as Assertions from '../common/assertions.js'; // Needed so that Util can bring some UI stuff // we don't actually use diff --git a/tests/unit/jsParse.js b/tests/unit/jsParse.js index 31796510c..cc3d578bc 100644 --- a/tests/unit/jsParse.js +++ b/tests/unit/jsParse.js @@ -4,7 +4,7 @@ const JsUnit = imports.jsUnit; -const Assertions = imports.common.assertions; +import * as Assertions from '../common/assertions.js'; const Environment = imports.ui.environment; Environment.init(); diff --git a/tests/unit/markup.js b/tests/unit/markup.js index 1df1eb09b..c10f2572d 100644 --- a/tests/unit/markup.js +++ b/tests/unit/markup.js @@ -3,7 +3,7 @@ // Test cases for MessageList markup parsing const JsUnit = imports.jsUnit; -const Pango = imports.gi.Pango; +import Pango from 'gi://Pango'; const Environment = imports.ui.environment; Environment.init(); diff --git a/tests/unit/signalTracker.js b/tests/unit/signalTracker.js index c6c6d4a7e..613fe4e71 100644 --- a/tests/unit/signalTracker.js +++ b/tests/unit/signalTracker.js @@ -2,7 +2,7 @@ // Test cases for version comparison -const GObject = imports.gi.GObject; +import GObject from 'gi://GObject'; const JsUnit = imports.jsUnit; const Signals = imports.misc.signals;