karma-runner / karma-qunit

A Karma plugin. Adapter for QUnit testing framework.
MIT License
51 stars 38 forks source link

Existing fixture should be preserved #92

Closed Krinkle closed 6 years ago

Krinkle commented 7 years ago

Since #22 (v0.1.5) two QUnit features are broken in karma-qunit.

Firstly, qunit-fixture is not just a recipient for any dummy element that a user might want to have automatically cleaned up. It is also a place where one can put fixtures (surprise!) that will be available to every test.

QUnit has always torn down and re-created this element between tests, but its contents are saved from the first impression at startup and then re-parsed for each test. This behaviour has been part of QUnit since the first stable version and breaking of this behaviour is one of the reasons why it's been next to impossible to use karma-qunit for jQuery core's own test suite. (Something I'm trying as part of https://github.com/jquery/jquery/issues/1999).

In current versions of QUnit, this first impression is saved in QUnit.config.fixture.

Also, contrary to the comment in adapter.js, QUnit's own runner does not create #qunit-fixture by default. The entire fixture feature is opt-in and implicitly enabled by the HTML test page having such element at startup.

Still, #22 was a much requested feature (for valid reasons), because at the time it wasn't supported by Karma to customise this HTML page (since it has its own context page instead). And even now that it is possible, it makes more sense to auto-create this given there's no downside to doing so.

So, three problems:

  1. Any pre-existing #qunit-fixture element should be preserved (e.g. when using a custom Karma's customContextFile option).
  2. QUnit.testStart runs after QUnit's own test start handler, which already re-creates the qunit-fixture every tests and repopulates it with a fresh parse of QUnit.config.fixture. Setting this config option is currently broken because karma-qunit removes the fixture and re-creates it.
  3. The element only needs to be created at QUnit.begin, not at every QUnit.testStart.
BradCOnGitHub commented 7 years ago

I'm having the same issue. Trying to move some older tests qunit we have using a custom framework into karma. Because those tests have HTML pages with custom content in the #qunit-fixture I can't do it.