Coder Social home page Coder Social logo

karma-iframes's People

Contributors

audoh-red7 avatar dependabot[bot] avatar dogoku avatar mattalxndr avatar sabberworm avatar taulinger avatar thealien avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

karma-iframes's Issues

Updating Karma to v5+ : PromiseContainer is not a constructor

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"]
    },

JS errors sent from the iframe to the parent context aren't serialised correctly

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.

reverse-context.js added twice due to failing filter guard on Windows

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;

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.