squidfunk / karma-viewport

A Karma plugin for testing responsive features and layout

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Viewport is not defined in Karma DEBUG RUNNER

Tipster74743 opened this issue · comments


Test runs successfully and passes when running ng test in angular 4, but when debugging the tests through karma, viewport is undefined

Expected behavior

For viewport to be defined and tests to pass in debug mode.

Actual behavior

viewport is not being defined

Steps to reproduce the bug

  1. install karma-viewport using npm to an ng4 project
  2. add karma-viewport to karma.conf requirements
  3. add 'viewport' to karma frameworks array
  4. create a test and import viewport using 'declare const viewport'
  5. run test (success)
  6. click debug in karma window
  7. once successful tests will fail.

Package versions

  • karma-viewport: ^0.1.2

System information

  • Browser: Chrome

Hmm, well the debug window doesn't include the iframe, so that's the main problem I guess. Probably karma-viewport has to be extended so that it inserts an iframe itself. I need to think about this a little but this is indeed a bug.

See #13. The solution is a little hacky, as I had to override the debug.html injection logic and embed it into the standard iframe context. However, it's the best possible solution as it has minimal impact for the way tests are structured and built and works interop with all other karma modules. I will issue a release within in a few hours when the build passes.

Just released 0.2.0 which should solve your problem. I could only test within a vanilla JavaScript context, as I don't have an Angular project on my hands. Could you please verify?

Yes sir, I will verify in just a moment.

This is what I'm getting now:

01 08 2017 14:14:00.184:ERROR [karma]: ReferenceError: query is not defined
    at fs.readFile (../node_modules/karma-viewport/dist/index.js:110:13)
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:504:3)

Did I miss something by chance?

That is really strange. Which Node version are you using?

My fault, there was a broken reference which the tests didn't catch. Please try 0.2.1 which was just released.

That fixed it, it is now working as intended. Thank you!

Thank you for the report! Feel free to provide feedback as this is a very young project.

Hi, suddenly I have this issue now with "karma-viewport": "^1.0.4" , "karma": "^3.1.4", and "jasmine-core": "~3.3.0"

And it would only happen when I'm running a single spec in debug mode.

ezoic increase your site revenue