| 1 |
"use strict"; |
| 2 |
|
| 3 |
var assert = require("chai").assert |
| 4 |
, globalThis = require("ext/global-this") |
| 5 |
, requireUncached = require("ncjsm/require-uncached") |
| 6 |
, adaptRealm = require("../adapt-realm"); |
| 7 |
|
| 8 |
var uniGlobal = require(".."); |
| 9 |
|
| 10 |
describe("adapt-realm.js", function () { |
| 11 |
it("should adapt outer realm to share same uni global", function () { |
| 12 |
var otherRealmGlobal = { EvalError: function () { /* noop */ } }; |
| 13 |
adaptRealm(otherRealmGlobal); |
| 14 |
var otherRealmUniGlobal = requireUncached(function () { |
| 15 |
var originalEvalError = EvalError; |
| 16 |
globalThis.EvalError = otherRealmGlobal.EvalError; |
| 17 |
try { return require(".."); } finally { globalThis.EvalError = originalEvalError; } |
| 18 |
}); |
| 19 |
assert.equal(uniGlobal("foo"), otherRealmUniGlobal("foo")); |
| 20 |
}); |
| 21 |
|
| 22 |
it("Adapting same realm twice should be ineffective", function () { |
| 23 |
var otherRealmGlobal = { EvalError: function () { /* noop */ } }; |
| 24 |
adaptRealm(otherRealmGlobal); |
| 25 |
adaptRealm(otherRealmGlobal); |
| 26 |
}); |
| 27 |
}); |