-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d85133e
Showing
11 changed files
with
1,925 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"# intern-issue-1168" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
define({ | ||
true: function () { | ||
return false; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
var registerSuite = intern.getInterface('object').registerSuite; | ||
var assert = intern.getPlugin('chai').assert; | ||
|
||
define(['./require', 'module', 'dojo/Deferred'], function ( | ||
require, | ||
module, | ||
Deferred | ||
) { | ||
var src; | ||
var requireContext; | ||
|
||
registerSuite(module.id, { | ||
before: function () { | ||
var deferred = new Deferred(); | ||
requireContext = require({ | ||
map: { '*': { 'app/src': 'app/mocked' } }, | ||
}, ['app/src'], function (mockedSrc) { | ||
src = mockedSrc; | ||
deferred.resolve(); | ||
}); | ||
return deferred.promise; | ||
}, | ||
|
||
after: function () { | ||
requireContext.restore(); | ||
}, | ||
|
||
tests: { | ||
'mocked src': function () { | ||
assert.isFalse(src.true()); | ||
}, | ||
}, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright Koninklijke Philips N.V. 2018 | ||
// | ||
// All rights are reserved. Reproduction or transmission in whole or in part, in | ||
// any form or by any means, electronic, mechanical or otherwise, is prohibited | ||
// without the prior written consent of the copyright owner. | ||
// | ||
|
||
// The dojo AMD loader has an optional first 'config' parameter. This is used | ||
// most often in unittest code to magically map moduleIds to a stub implementation. | ||
// Unfortunately, this has a persistent side effect on the loader's internal | ||
// administration. This version of 'require' provides a way to undo that. | ||
// | ||
// Usage: | ||
// define([ ..., 'interntests/require'], function( ..., require) { | ||
// var requireContext; | ||
// before: function() { | ||
// requireContext = require( | ||
// { map: { '*': { ... } } }, // <--- this is where the magic happens | ||
// [ ... ], | ||
// function( ... ) { ... } | ||
// ); | ||
// }, | ||
// after: function() { | ||
// requireContext.restore(); | ||
// } | ||
// }); | ||
// | ||
// Note: | ||
// the map should override on '*' level, so it gets correctly replaced while undoing. | ||
// | ||
// Mapping data-dojo-types | ||
// ----------------------- | ||
// In cases where the stubbed modules are declared as a data-dojo-type in a template, | ||
// the _WidgetsInTemplateMixin needs to be aware of the mapping when it instantiates | ||
// the module instances. This is done by passing the 'require' function while instantiating | ||
// the widget, like this: | ||
// | ||
// var instance = new MyWidget({ contextRequire: require }); | ||
// | ||
// _WidgetsInTemplateMixin will look for such a contextRequire and use it if available. | ||
// This ensures the map is applied at this point. | ||
// | ||
// Note: | ||
// Unfortunately, when it creates the widgets in the template, it does not pass the | ||
// contextRequire to their constructor. This means that mappings will not be applied to | ||
// nested widgets, which may be unexpected and unintended. | ||
// To fix this we would have to change the dojo parser. | ||
// | ||
|
||
define(['require', 'dojo/_base/lang'], function (require, lang) { | ||
function isString(object) { | ||
return {}.toString.call(object) === '[object String]'; | ||
} | ||
|
||
function testRequire( | ||
config, | ||
deps, | ||
callback, | ||
referenceModule, | ||
contextRequire | ||
) { | ||
if (Array.isArray(config) || isString(config)) { | ||
// require is called without a config object, just forward to actual require | ||
return require(config, deps, callback, referenceModule, contextRequire); | ||
} | ||
var globalRequireMap = lang.mixin({ '*': {} }, require.map); | ||
var mergedMap = lang.mixin({}, globalRequireMap, config.map); | ||
var mergedConfig = lang.mixin({}, config, { map: mergedMap }); | ||
// Clear the dependencies from the cache so they will get reloaded/redefined with the mapped configuration. | ||
deps.forEach(require.undef); | ||
// Call the actual require -- this will persistently update the global map internally | ||
require(mergedConfig, deps, callback, referenceModule, contextRequire); | ||
return { | ||
restore: function restore() { | ||
// Clear the loaded dependencies from the cache to avoid them being used with the mapped configuration. | ||
deps.forEach(require.undef); | ||
// Clear the constructor cache built-up by the dojo parser | ||
delete testRequire._dojoParserCtorMap; | ||
// Restore the updated global map to its original value | ||
require({ map: globalRequireMap }); | ||
}, | ||
}; | ||
} | ||
|
||
testRequire.undef = require.undef; | ||
|
||
return testRequire; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
define({ | ||
true: function () { | ||
return true; | ||
}, | ||
trueToo: function () { | ||
return true; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
var registerSuite = intern.getInterface('object').registerSuite; | ||
var assert = intern.getPlugin('chai').assert; | ||
|
||
define(['module', 'app/src'], function (module, src) { | ||
registerSuite(module.id, { | ||
tests: { | ||
'regular src': function () { | ||
assert.isTrue(src.true()); | ||
}, | ||
}, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
var registerSuite = intern.getInterface('object').registerSuite; | ||
var assert = intern.getPlugin('chai').assert; | ||
|
||
define(['module', 'dojo/Deferred'], function (module, Deferred) { | ||
var src; | ||
|
||
registerSuite(module.id, { | ||
before: function () { | ||
var deferred = new Deferred(); | ||
require(['app/src'], function (delayedSrc) { | ||
src = delayedSrc; | ||
deferred.resolve(); | ||
}); | ||
return deferred.promise; | ||
}, | ||
|
||
tests: { | ||
'regular src 2': function () { | ||
assert.isTrue(src.trueToo()); | ||
}, | ||
}, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
define(['./src.test', './mocked.test', './src.test2'], () => {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"loader": { | ||
"script": "dojo", | ||
"options": { | ||
"has": { | ||
"dojo-undef-api": true | ||
}, | ||
"packages": [ | ||
{ "name": "app", "location": "app" }, | ||
{ "name": "dojo", "location": "node_modules/dojo" } | ||
] | ||
} | ||
}, | ||
"suites": "app/tests.all", | ||
"environments": { | ||
"browserName": "chrome", | ||
"fixSessionCapabilities": "no-detect" | ||
}, | ||
"coverage": ["app/src.js"] | ||
} |
Oops, something went wrong.