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

Fix jasmine & jasmine-core requires in jasmine_runner.js #633

Merged
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
5 changes: 4 additions & 1 deletion packages/jasmine/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ npm_package(

js_library(
name = "jasmine_runner",
srcs = ["src/jasmine_runner.js"],
srcs = [
"index.js",
"src/jasmine_runner.js",
],
module_name = "@bazel/jasmine",
)
22 changes: 1 addition & 21 deletions packages/jasmine/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
// Try unhoisted location of `jasmine-core` which is a transitive dep of `jasmine`.
// Try this first so that we don't accidentally fall through to the user's
// `jasmine-core`. This file will be under `node_modules/@bazel/jasmine/index.js`.
// `jasmine` is a direct dependency of `@bazel/jasmine` so
// require `jasmine` will get the correct version of `jasmine`, however,
// `jasmine-core` is a transitive dep of `jasmine` so we need to look in the
// unhoisted location first to guarantee we will get the correct `jasmine-core`
// which our version of `jasmine` depends on.
let jasmineCore;
try {
// Look under `node_modules/@bazel/jasmine/node_modules/jasmine/node_modules/jasmine-core`
jasmineCore = require('jasmine/node_modules/jasmine-core');
} catch (e) {
if (e.code !== 'MODULE_NOT_FOUND') {
// rethrow other errors
throw e;
}
// Look under `node_modules/@bazel/jasmine/node_modules/jasmine-core` and
// falls back to `node_modules/jasmine-core` if not found there.
jasmineCore = require('jasmine-core');
}
const jasmineCore = require('jasmine-core');

// a boot function for use in user bootstrap code:
// require('@bazel/jasmine').boot()
Expand Down
16 changes: 4 additions & 12 deletions packages/jasmine/src/jasmine_runner.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
const fs = require('fs');
const path = require('path');
const bazelJasmine = require('@bazel/jasmine');

const JasmineRunner = bazelJasmine.jasmine;

let jasmineCore = null
let JasmineRunner = require('jasmine/lib/jasmine');
if (global.jasmine) {
// global.jasmine has been initialized which means a bootstrap script
// has already required `jasmine-core` and called jasmineCore.boot()
jasmineCore = global.jasmineCore;
if (!jasmineCore) {
try {
// Try unhoisted jasmine-core first so that we don't
// need an @npm//jasmine-core dep in the unhoisted case.
jasmineCore = require('jasmine/node_modules/jasmine-core');
} catch (e) {
if (e.code !== 'MODULE_NOT_FOUND') {
// rethrow other errors
throw e;
}
jasmineCore = require('jasmine-core');
}
jasmineCore = bazelJasmine.jasmineCore;
}
// Override the jasmineCore boot function so that the jasmine
// runner gets the already initialize jasmine and its shared environment
Expand Down