Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to and support ESM #46

Merged
merged 10 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,13 @@ globals:
ARGV: readonly
Debugger: readonly
GIRepositoryGType: readonly
globalThis: readonly
imports: readonly
Intl: readonly
log: readonly
logError: readonly
print: readonly
printerr: readonly
window: readonly
parserOptions:
ecmaVersion: 2020
sourceType: module
23 changes: 11 additions & 12 deletions bin/jasmine-runner.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env gjs
#!/usr/bin/env -S gjs -m

/* global jasmineImporter */

const {GLib} = imports.gi;
import GLib from 'gi://GLib';

// Create a separate GJS importer object for Jasmine modules, so that Jasmine's
// modules are not exposed to test code (e.g. client code might have its own
Expand All @@ -13,30 +13,29 @@ const {GLib} = imports.gi;
// registers a GType, and we cannot register two GTypes with the same name in
// the same process.

let base;
if (GLib.getenv('JASMINE_UNINSTALLED')) {
// Trick to use the uninstalled copy of Jasmine when running "make check".
const srcdir = GLib.getenv('SRCDIR');
window.jasmineImporter = imports['.'];
globalThis.jasmineImporter = imports['.'];
jasmineImporter.searchPath = [
GLib.build_filenamev([srcdir, 'src']),
GLib.build_filenamev([srcdir, 'lib']),
];
base = `file://${GLib.build_filenamev([srcdir, 'src'])}`;
} else {
const oldSearchPath = imports.searchPath.slice(); // make a copy
imports.searchPath.unshift('@datadir@');
window.jasmineImporter = imports['jasmine-gjs'];
globalThis.jasmineImporter = imports['jasmine-gjs'];
imports.searchPath = oldSearchPath;
base = 'file://@datadir@/jasmine-gjs';
}

const Command = jasmineImporter.command;
const Timer = jasmineImporter.timer;
const JasmineBoot = jasmineImporter.jasmineBoot;

Timer.installAPI(window);
const Command = await import(`${base}/command.js`);
const JasmineBoot = await import(`${base}/jasmineBoot.js`);

// Do not conflict with global "jasmine" object
const _jasmine = new JasmineBoot.Jasmine();
_jasmine.installAPI(window);
_jasmine.installAPI(globalThis);

// Don't put any code after this; the return value is used as the exit code.
Command.run(_jasmine, ARGV, 10);
await Command.run(_jasmine, ARGV, 10);
15 changes: 8 additions & 7 deletions bin/jasmine.in
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
#!/usr/bin/env gjs
#!/usr/bin/env -S gjs -m

const {GLib} = imports.gi;
const System = imports.system;
import GLib from 'gi://GLib';
import * as System from 'system';

let runnerPath = '@pkglibexecdir@/jasmine-runner';
let base;
if (GLib.getenv('JASMINE_UNINSTALLED')) {
// Trick to use the uninstalled copy of Jasmine when running "make check".
const srcdir = GLib.getenv('SRCDIR');
imports.searchPath.unshift(GLib.build_filenamev([srcdir, 'src']));
base = `file://${GLib.build_filenamev([srcdir, 'src'])}`;
const builddir = GLib.getenv('BUILDDIR');
runnerPath = GLib.build_filenamev([builddir, 'jasmine-runner']);
} else {
imports.searchPath.unshift('@datadir@/jasmine-gjs');
base = 'file://@datadir@/jasmine-gjs';
}

const Config = imports.config;
const Options = imports.options;
const Config = await import(`${base}/config.js`);
const Options = await import(`${base}/options.js`);

const [files, options] = Options.parseOptions(ARGV);

Expand Down
Loading