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

making sure __CANJS_DEVTOOLS__.register is called #49

Merged
merged 1 commit into from
Jun 21, 2018
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
65 changes: 52 additions & 13 deletions can-debug-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,61 @@ QUnit.test("calls canReflect bind symbols safely", function(assert) {
testHelpers.dev.devOnlyTest("calls window.__CANJS_DEVTOOLS__.register if available", function(assert) {
var done = assert.async();

var devtools = window.__CANJS_DEVTOOLS__ = window.__CANJS_DEVTOOLS__ || {};

var origRegister = devtools.register;
devtools.register = function(can) {
assert.ok("Symbol" in can, "can.Symbol passed");
assert.ok("Reflect" in can, "can.Reflect passed");
assert.ok("queues" in can, "can.queues passed");
assert.ok("getGraph" in can, "can.getGraph passed");
assert.ok("formatGraph" in can, "can.formatGraph passed");
assert.ok("mergeDeep" in can, "can.mergeDeep passed");
var fakeWindow = {
__CANJS_DEVTOOLS__: {
register: function(can) {
assert.ok("Symbol" in can, "can.Symbol passed");
assert.ok("Reflect" in can, "can.Reflect passed");
assert.ok("queues" in can, "can.queues passed");
assert.ok("getGraph" in can, "can.getGraph passed");
assert.ok("formatGraph" in can, "can.formatGraph passed");
assert.ok("mergeDeep" in can, "can.mergeDeep passed");
done();
}
}
};

clone({})
clone({
"can-globals": {
default: {
getKeyValue: function(key) {
if (key === "global") {
return fakeWindow;
}
}
}
}
})
.import("can-debug");
});

testHelpers.dev.devOnlyTest("calls window.__CANJS_DEVTOOLS__.register if __CANJS_DEVTOOLS__ is set later", function(assert) {
var done = assert.async();
var fakeWindow = {};

clone({
"can-globals": {
default: {
getKeyValue: function(key) {
if (key === "global") {
return fakeWindow;
}
}
}
}
})
.import("can-debug")
.then(function() {
devtools.register = origRegister;
done();
fakeWindow.__CANJS_DEVTOOLS__ = {
register: function(can) {
assert.ok("Symbol" in can, "can.Symbol passed");
assert.ok("Reflect" in can, "can.Reflect passed");
assert.ok("queues" in can, "can.queues passed");
assert.ok("getGraph" in can, "can.getGraph passed");
assert.ok("formatGraph" in can, "can.formatGraph passed");
assert.ok("mergeDeep" in can, "can.mergeDeep passed");
done();
}
};
});
});
30 changes: 21 additions & 9 deletions can-debug.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var namespace = require("can-namespace");
var globals = require("can-globals");
var proxyNamespace = require("./src/proxy-namespace");
var temporarilyBind = require("./src/temporarily-bind");

Expand All @@ -25,15 +26,26 @@ module.exports = namespace.debug = {
logWhatChangesMe: temporarilyBind(logWhatChangesMe)
};

window.can = typeof Proxy !== "undefined" ? proxyNamespace(namespace) : namespace;
var global = globals.getKeyValue("global");

if (window.__CANJS_DEVTOOLS__) {
window.__CANJS_DEVTOOLS__.register({
Symbol: canSymbol,
Reflect: canReflect,
queues: canQueues,
getGraph: namespace.debug.getGraph,
formatGraph: namespace.debug.formatGraph,
mergeDeep: mergeDeep
global.can = typeof Proxy !== "undefined" ? proxyNamespace(namespace) : namespace;

var devtoolsCanModules = {
Symbol: canSymbol,
Reflect: canReflect,
queues: canQueues,
getGraph: namespace.debug.getGraph,
formatGraph: namespace.debug.formatGraph,
mergeDeep: mergeDeep
};

if (global.__CANJS_DEVTOOLS__) {
global.__CANJS_DEVTOOLS__.register(devtoolsCanModules);
} else {
Object.defineProperty(global, "__CANJS_DEVTOOLS__", {
set: function(devtoolsGlobal) {
devtoolsGlobal.register(devtoolsCanModules);
return devtoolsGlobal;
}
});
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
},
"dependencies": {
"can-diff": "^1.0.0",
"can-globals": "^1.0.0",
"can-namespace": "1.0.0",
"can-queues": "^1.0.0",
"can-reflect": "^1.10.1",
Expand Down