sabberworm / karma-iframes Goto Github PK
View Code? Open in Web Editor NEWLets you run each test in a separate context, loaded as an iframe.
License: GNU General Public License v3.0
Lets you run each test in a separate context, loaded as an iframe.
License: GNU General Public License v3.0
Hello,
We are using karma-iframes for a while, with Karma v4.4.1
When trying to upgrade to Karma v5+ (tried several v5+ with no more success)
karma-server refuse to start with this error :
31 08 2020 11:30:29.879:ERROR [karma-server]: Server start failed on port 9877: TypeError: common.PromiseContainer is not a constructor npm ERR! code ELIFECYCLE npm ERR! errno 130
This doesn't occur if I remove "iframes" from our list of frameworks.
Is there a needed configuration change for karma-iframes when upgrading karma from v4 to v5 ?
Thanks for the help.
Edit:
here is our dev dependencies for karma plugins :
"karma": "5.1.1",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage-istanbul-reporter": "^2.0.4",
"karma-iframes": "^1.2.2",
"karma-junit-reporter": "^1.2.0",
"karma-mocha": "^2.0.1",
"karma-sinon-chai": "^2.0.2",
"karma-sourcemap-loader": "^0.3.8",
"karma-spec-reporter": "0.0.32",
"karma-webpack": "^4.0.2",
relevant configuration :
config.set({
frameworks: ["mocha", "sinon-chai", "iframes"],
reporters: ["spec", "coverage-istanbul", "junit"],
files: [
'test/**/*.spec.js'
],
preprocessors: {
'test/**/*.spec.js': ["webpack", "sourcemap", "iframes"]
},
The callback of window.onerror is as follows:
window.onerror = function(message, source, lineno, colno, error) { ... }
The last parameter 'error' is an Error instance. When this error is caught and sent to the context (via the reverse context), postMessage is used but Error objects can't be serialised in postMessage and so the call fails and the error never makes it to the parent context. The error thrown in this case looks like:
Uncaught DOMException: Failed to execute 'postMessage' on 'Window': Error could not be cloned.
This seems to specifically be for errors in the JS document itself (syntax errors etc) rather than asserts in the tests themselves.
The offending code is in reverse-context.js, lines 30-36:
DIRECT_METHODS = ['error', 'log', 'complete', 'result'];
DIRECT_METHODS.forEach(method => {
karma[method] = function() {
callParentKarmaMethod(method, Array.prototype.slice.call(arguments));
}
karma[method].displayName = method+' (proxied)';
});
This could be corrected by adding a transform to the arguments array that converts Error objects into strings, e.g.
DIRECT_METHODS = ['error', 'log', 'complete', 'result'];
DIRECT_METHODS.forEach(method => {
karma[method] = function() {
var args = Array.prototype.slice.call(arguments);
for (var i = 0, l = args.length; i < l; ++i) {
if (args[i] instanceof Error) {
args[i] = args[i].stack || args[i].toString();
}
}
callParentKarmaMethod(method, args);
}
karma[method].displayName = method+' (proxied)';
});
This does mean however that karma never sees an Error object on the other end, only a string, but it gets sent right to karma.error so this might be ok.
こんばんは
After I added karma-iframes as documented I get the error: Uncaught ReferenceError: jasmine is not defined
Issue:
On Windows only, the reverse-context script is added twice, this causes the context to not be setup properly.
Cause:
In rewrite-middleware.js
.filter(file => file.originalPath !== REVERSE_CONTEXT);
Does not evaluate to through for reverse-context filepath on windows as require-resolve does not normalize path separators.
REVERSE_CONTEXT
Resolution:
In frameworks.js when require resolving REVERSE_CONTEXT
let REVERSE_CONTEXT = require.resolve('../static/reverse-context.js').split(path.sep).join('/');
And change rewrite-middleware.js Line 74
return (file.originalPath === REVERSE_CONTEXT) || (file.originalPath === REVERSE_CONTEXT.split(path.sep).join('/')));
to
return file.originalPath === REVERSE_CONTEXT;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.