[gjs/esm/static-imports] tests: Add ES module static import tests
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/esm/static-imports] tests: Add ES module static import tests
- Date: Wed, 9 Dec 2020 23:18:57 +0000 (UTC)
commit 95c5a0d58a1361e055472da42510c7ef96402cb9
Author: Philip Chimento <philip chimento gmail com>
Date: Wed Dec 9 15:12:37 2020 -0800
tests: Add ES module static import tests
Adds an '-m' flag to minijasmine, to execute the given file as a module.
(No fancy command line parsing is done; the -m must come after the file
name.)
.clang-format | 1 +
installed-tests/esm-test.sh | 25 ------------------
installed-tests/esm.test.in | 4 ---
installed-tests/esm/.eslintrc.yml | 5 ----
installed-tests/esm/default-import.js | 3 ---
installed-tests/esm/default-import.js.output | 1 -
installed-tests/esm/exports.js | 3 ---
installed-tests/esm/gi-import.js | 3 ---
installed-tests/esm/gi-import.js.output | 1 -
installed-tests/esm/named-import.js | 3 ---
installed-tests/esm/named-import.js.output | 1 -
installed-tests/esm/system-import.js | 3 ---
installed-tests/esm/system-import.js.output | 3 ---
installed-tests/js/jsunit.gresources.xml | 1 +
installed-tests/js/meson.build | 19 ++++++++++++++
installed-tests/js/modules/exports.js | 6 +++++
installed-tests/js/testESModules.js | 26 +++++++++++++++++++
installed-tests/meson.build | 39 ----------------------------
installed-tests/minijasmine.cpp | 17 +++++++++---
19 files changed, 66 insertions(+), 98 deletions(-)
---
diff --git a/.clang-format b/.clang-format
index deed826d..21a71334 100644
--- a/.clang-format
+++ b/.clang-format
@@ -25,4 +25,5 @@ SpacesBeforeTrailingComments: 2
# operate on diffs like clang-format does.
Language: JavaScript
DisableFormat: true
+SortIncludes: false # https://bugs.llvm.org/show_bug.cgi?id=27042
...
diff --git a/installed-tests/js/jsunit.gresources.xml b/installed-tests/js/jsunit.gresources.xml
index 674e342f..5503446d 100644
--- a/installed-tests/js/jsunit.gresources.xml
+++ b/installed-tests/js/jsunit.gresources.xml
@@ -12,6 +12,7 @@
<file>modules/badOverrides/Gio.js</file>
<file>modules/badOverrides/Regress.js</file>
<file>modules/badOverrides/WarnLib.js</file>
+ <file>modules/exports.js</file>
<file>modules/foobar.js</file>
<file>modules/lexicalScope.js</file>
<file>modules/modunicode.js</file>
diff --git a/installed-tests/js/meson.build b/installed-tests/js/meson.build
index dae48e07..3d5e7e25 100644
--- a/installed-tests/js/meson.build
+++ b/installed-tests/js/meson.build
@@ -194,3 +194,22 @@ gdbus_test_description = configure_file(
if get_option('installed_tests')
install_data('testGDBus.js', install_dir: installed_js_tests_dir)
endif
+
+# testESModules.js is also separate because it needs an extra minijasmine flag
+
+test('ESModules', minijasmine, args: [files('testESModules.js'), '-m'],
+ env: tests_environment, protocol: 'tap', suite: 'JS')
+
+esm_test_description_subst = {
+ 'name': 'testESModules.js',
+ 'installed_tests_execdir': installed_tests_execdir,
+}
+esm_test_description = configure_file(
+ configuration: esm_test_description_subst,
+ input: '../minijasmine.test.in', output: 'testESModules.test',
+ install: get_option('installed_tests'),
+ install_dir: installed_tests_metadir)
+
+if get_option('installed_tests')
+ install_data('testESModules.js', install_dir: installed_js_tests_dir)
+endif
diff --git a/installed-tests/js/modules/exports.js b/installed-tests/js/modules/exports.js
new file mode 100644
index 00000000..180151b9
--- /dev/null
+++ b/installed-tests/js/modules/exports.js
@@ -0,0 +1,6 @@
+// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
+// SPDX-FileCopyrightText: 2020 Evan Welsh <contact evanwelsh com>
+
+export default 5;
+
+export const NamedExport = 'Hello, World';
diff --git a/installed-tests/js/testESModules.js b/installed-tests/js/testESModules.js
new file mode 100644
index 00000000..be1a1c9a
--- /dev/null
+++ b/installed-tests/js/testESModules.js
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
+// SPDX-FileCopyrightText: 2020 Evan Welsh <contact evanwelsh com>
+
+import gi from 'gi';
+import system from 'system';
+
+import $ from 'resource:///org/gjs/jsunit/modules/exports.js';
+import {NamedExport} from 'resource:///org/gjs/jsunit/modules/exports.js';
+
+describe('ES module imports', function () {
+ it('default import', function () {
+ expect($).toEqual(5);
+ });
+
+ it('named import', function () {
+ expect(NamedExport).toEqual('Hello, World');
+ });
+
+ it('system import', function () {
+ expect(system.exit.toString()).toEqual('function exit() {\n [native code]\n}');
+ });
+
+ it('GObject introspection import', function() {
+ expect(gi.require('GObject').toString()).toEqual('[object GIRepositoryNamespace]');
+ });
+});
diff --git a/installed-tests/meson.build b/installed-tests/meson.build
index 6545685a..d256f93a 100644
--- a/installed-tests/meson.build
+++ b/installed-tests/meson.build
@@ -44,45 +44,6 @@ endforeach
subdir('js')
-# esm script tests #
-
-esm_tests = [
- 'default-import',
- 'named-import',
- 'gi-import',
- 'system-import'
-]
-
-esm_test_driver = find_program(files('esm-test.sh'))
-if get_option('installed_tests')
- install_data('esm-test.sh', install_dir: installed_tests_execdir)
-endif
-
-foreach test : esm_tests
- test_file = files('esm' / '@0@.js'.format(test))
-
- test('@0@ command'.format(test), esm_test_driver,
- args: test_file, env: tests_environment, protocol: 'tap',
- suite: 'ESM')
-
- test_description_subst = {
- 'name': '@0@.js'.format(test),
- 'installed_tests_execdir': installed_tests_execdir,
- }
- test_description = configure_file(configuration: test_description_subst,
- input: 'esm.test.in',
- output: '@0@.test'.format(test),
- install: get_option('installed_tests'),
- install_dir: installed_tests_metadir)
-
- if get_option('installed_tests')
- install_data(test_file, install_dir: installed_tests_execdir / 'esm')
- install_data('esm' / '@0@.js'.format(test),
- 'esm' / '@0@.js.output'.format(test),
- install_dir: installed_tests_execdir / 'esm')
- endif
-endforeach
-
# Debugger script tests #
debugger_tests = [
diff --git a/installed-tests/minijasmine.cpp b/installed-tests/minijasmine.cpp
index be8ba42f..9cc1d7b3 100644
--- a/installed-tests/minijasmine.cpp
+++ b/installed-tests/minijasmine.cpp
@@ -3,7 +3,9 @@
// SPDX-FileCopyrightText: 2016 Philip Chimento
#include <locale.h> // for setlocale, LC_ALL
+#include <stdint.h>
#include <stdlib.h> // for exit
+#include <string.h>
#include <gio/gio.h>
#include <girepository.h>
@@ -62,12 +64,19 @@ main(int argc, char **argv)
bool success;
int code;
- success = gjs_context_eval(cx, "imports.minijasmine;", -1,
- "<jasmine>", &code, &error);
- if (!success)
+ int exitcode_ignored;
+ if (!gjs_context_eval(cx, "imports.minijasmine;", -1, "<jasmine>",
+ &exitcode_ignored, &error))
bail_out(cx, error->message);
- success = gjs_context_eval_file(cx, argv[1], &code, &error);
+ bool eval_as_module = argc >= 3 && strcmp(argv[2], "-m") == 0;
+ if (eval_as_module) {
+ uint8_t u8_exitcode_ignored;
+ success = gjs_context_eval_module_file(cx, argv[1],
+ &u8_exitcode_ignored, &error);
+ } else {
+ success = gjs_context_eval_file(cx, argv[1], &exitcode_ignored, &error);
+ }
if (!success)
bail_out(cx, error->message);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]