NG6-starter icon indicating copy to clipboard operation
NG6-starter copied to clipboard

Karma testing does not seem to work

Open Quirksmode opened this issue 10 years ago • 8 comments

I followed the instructions and everything installed, but when I run karma start I get the following warnings:

WARN [reporter]: Can not load "mocha", it is not registered! Perhaps you are missing some plugin? WARN [watcher]: Pattern "/Users/Quirksmode/Downloads/NG6-starter-jspm/client/jspm_packages/es6-module-loader.js" does not match any file. INFO [karma]: Karma v0.12.36 server started at http://localhost:9876/ INFO [launcher]: Starting browser Chrome

Quirksmode avatar Dec 02 '15 22:12 Quirksmode

Installing all the packages globally seems to get it working.

But this is not ideal as ideally we want the package.json to set everything up on different developers machines using 'npm install'. Am I missing something here, or is this just how it has to be?

Quirksmode avatar Dec 03 '15 18:12 Quirksmode

Testing is not working for me with a clean clone / install ( even with globally installing the packages ). How did u get it to work? Do the tests run?

justinkames avatar Dec 04 '15 11:12 justinkames

@justinkames works for me (fresh install) - make sure you are at the root of the app and run

karma start // or npm test

returns

START:
04 12 2015 13:58:20.508:INFO [karma]: Karma v0.13.15 server started at http://localhost:9876/
04 12 2015 13:58:20.531:INFO [launcher]: Starting browser Chrome
04 12 2015 13:58:26.986:INFO [Chrome 47.0.2526 (Mac OS X 10.10.5)]: Connected on socket -AFYu1246eJAI_M-AAAA with id 37112570
  Hero
    Controller
      ✔ has a name property [REMOVE]
    Template
      ✔ has name in template [REMOVE]
    Component
      ✔ includes the intended template
      ✔ uses `controllerAs` syntax
      ✔ invokes the right controller
  Navbar
    Controller
      ✔ has a name property [REMOVE]
    Template
      ✔ has name in template [REMOVE]
    Component
      ✔ includes the intended template
      ✔ uses `controllerAs` syntax
      ✔ invokes the right controller
  About
    Controller
      ✔ has a name property [REMOVE]
    Template
      ✔ has name in template [REMOVE]
    Component
      ✔ includes the intended template
      ✔ uses `controllerAs` syntax
      ✔ invokes the right controller
  Home
    Controller
      ✔ has a name property [REMOVE]
    Template
      ✔ has name in template [REMOVE]
    Component
      ✔ includes the intended template
      ✔ uses `controllerAs` syntax
      ✔ invokes the right controller

Finished in 0.104 secs / 0.004 secs

SUMMARY:
✔ 20 tests completed

adyngom avatar Dec 04 '15 18:12 adyngom

and sorry if I'm stating the obvious here but these packages have to be installed globally

npm install -g gulp karma karma-cli webpack

adyngom avatar Dec 04 '15 18:12 adyngom

Thanks for your reply. I did the following :

$ git clone -b jspm https://github.com/AngularClass/NG6-starter.git $ npm install $ karma start

Returns :

Error: Cannot find module 'mocha'
at Function.Module._resolveFilename (module.js:337:15)
at Function.require.resolve (module.js:389:19)
at initMocha (/Users/justinkames/Documents/workspace-webstorm/NG6-starter/node_modules/karma-   mocha/lib/index.js:8:40)

$ npm install mocha --save-dev $ npm install chai --save-dev

Then :

$ karma start

  INFO [karma]: Karma v0.12.37 server started at http://localhost:9876/
  INFO [launcher]: Starting browser Chrome
  INFO [Chrome 47.0.2526 (Mac OS X 10.11.1)]: Connected on socket PsA3cTt6RyO-dS3CEJiB with    id 63391663
  Chrome 47.0.2526 (Mac OS X 10.11.1) ERROR
  Uncaught ReferenceError: System is not defined
  at /Users/justinkames/Documents/workspace-webstorm/NG6-starter/jspm.config.js:1
  Finished in 0.119 secs / 0 secs

Fixed by running $ jspm dl-loader

$ karma start

 INFO [Chrome 47.0.2526 (Mac OS X 10.11.1)]: Connected on socket J1D8hfUGqGv4gPFsFCpd with   id 31894073
 Chrome 47.0.2526 (Mac OS X 10.11.1) ERROR
Uncaught TypeError: baseURL should only be configured once and must be configured first.
at /Users/justinkames/Documents/workspace-webstorm/NG6-starter/client/jspm_packages/system.js:4

Updating karma-jpsm in package.json fixed this

"karma-jspm": "2.0.1",

$ karma start

INFO [karma]: Karma v0.12.37 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 47.0.2526 (Mac OS X 10.11.1)]: Connected on socket 0Al7Wml4ToEgVk9KIXpG with id   294793
WARN [web-server]: 404: /client/app/common/hero/hero.spec.js
WARN [web-server]: 404: /client/app/common/navbar/navbar.spec.js
WARN [web-server]: 404: /client/app/common/user/user.spec.js
WARN [web-server]: 404: /client/app/components/about/about.spec.js
WARN [web-server]: 404: /client/app/components/home/home.spec.js
Chrome 47.0.2526 (Mac OS X 10.11.1) ERROR: 'Potentially unhandled rejection [5] Error: XHR error     (404 Not Found) loading http://localhost:9876/client/app/common/hero/hero.spec.js
at error (http://localhost:9876/base/client/jspm_packages/system.src.js? 6536115be64e0ff966e05546f7767676fa7c03d6:1020:16)
at XMLHttpRequest.xhr.onreadystatechange (http://localhost:9876/base/client/jspm_packages/system.src.js?  6536115be64e0ff966e05546f7767676fa7c03d6:1028:13)'
WARN [Chrome 47.0.2526 (Mac OS X 10.11.1)]: Disconnected (1 times), because no message in 10000 ms.

This where I am currently stuck..

$ npm list --depth=0

├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] └── [email protected]

SystemJS version :

├─┬ [email protected]

justinkames avatar Dec 07 '15 11:12 justinkames

@justinkames your steps seem to be ok (I have my own environment, as anyone else), but the point is you have to add in karma.conf.js

proxies: {
  '/client': '/base/client'
}

Hope it helps, karma+jspm uses to be a bit of hell. Check https://github.com/Workiva/karma-jspm/issues/91 for further info.

telekosmos avatar Jan 04 '16 18:01 telekosmos

Same issue:

C:\ > git clone -b jspm https://github.com/AngularClass/NG6-starter.git C:\ > cd NG6-starter C:\ > git checkout jspm C:\ > npm install C:\ > karma start

Error: Cannot find module 'mocha' at Function.Module._resolveFilename (module.js:325:15) at Function.require.resolve (internal/module.js:16:19)

Then C:\ > npm install mocha --save-dev C:\ > npm install chai --save-dev

Results in

START: WARN [watcher]: Pattern "C:\Users\bkdevconstructiv\tmp\NG6-starter\client\jspm_p ackages\es6-module-loader.js" does not match any file. ERROR [karma]: { [Error: EMFILE: too many open files, open 'C:\Users\bkdevconstr uctiv\tmp\NG6-starter\client\jspm_packages\npm\[email protected]'] errno: -4066, code: 'EMFILE', syscall: 'open',

What to do?

rdehuyss avatar Jan 28 '16 12:01 rdehuyss

Looks like you are using a PC. On a mac, you can add ulimit -f [some high number] in the .bash_profile or .zshrc file. Mine is set to ulimit -f 20000.

Therefore on a PC, maybe look for something comparable to ulimit ?

jerryorta-dev avatar Mar 13 '16 09:03 jerryorta-dev