Skip to content
This repository has been archived by the owner on Jan 2, 2018. It is now read-only.

Picking up suites of other modules? #6

Closed
jacob414 opened this issue Apr 25, 2016 · 11 comments
Closed

Picking up suites of other modules? #6

jacob414 opened this issue Apr 25, 2016 · 11 comments

Comments

@jacob414
Copy link

Hello,

I installed the plugin into my project using npm install roc-plugin-test-mocha-karma-webpack --save, but it looks like it's trying to load suites from other installed modules (causing various problems in PhantomJS). I have created a suite tests/poc.test.js with no-op contents:

 import { describe, it } from 'Mocha';

 describe("Proof of concept test", () => {
   console.log('POC test definition');
   it("Should be run", () => {
     console.log("Is this test running?");
   });
 });

Trying to run it using:

$ roc test

From my project root. I have also tried roc test --grep=poc, but the results are the same.

Instead it crashes on what looks like the tests of installed modules, e.g.:

ERROR in .//Mocha//minimatch/test/extglob-ending-with-state-char.js
Module not found: Error: Cannot resolve module 'tap' in /Users/jacob/src/lab/miveo/roc-0/node_modules/Mocha/node_modules/minimatch/test
@ .//Mocha//minimatch/test/extglob-ending-with-state-char.js 1:11-25

(Around 25 of those is reported with small slight variations, reporting missing modules tap, less, sass, fs etc)

(The repo with my attempts is here)

@dlmr
Copy link
Member

dlmr commented Apr 25, 2016

The problem is that you are importing Mocha directly. If you remove the import it will work since it is exposed from Karma directly.

You will additionally either rename app/ to src/ or tell the test command where it can find the files that you want to generate coverage for. For example by directly passing it to the command roc test --test-src-path app/.

@jacob414
Copy link
Author

Better, now my suite is logging for definition (result of console.log('POC test definition')), it's still printing a lot of complaint about missing modules from elsewhere, though. I still don't see any logging from the actual test, though.

On a side note: are you considering having support for tests running in an actual browser, too? (I have done that in an own project by linking Mocha via a SCRIPT element and linking separately transpiled suites from SCRIPT elements too. I'm considering attempting that inside my Roc lab project.)

@dlmr
Copy link
Member

dlmr commented Apr 25, 2016

It works for me:

$ roc test --test-src-path app/
Found a local version of Roc, will use that over the global one. 

25 04 2016 11:48:41.006:INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
25 04 2016 11:48:41.013:INFO [launcher]: Starting browser PhantomJS
25 04 2016 11:48:41.773:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket /#jo9wH_X_J4Qpm68kAAAA with id 68708130
PhantomJS 2.1.1 (Mac OS X 0.0.0) LOG LOG: 'POC test definition'
LOG LOG: 'A TEST RUNNING'

  Proof of concept test
    ✓ Should be run

PhantomJS 2.1.1 (Mac OS X 0.0.0): Executed 1 of 1 SUCCESS (0.028 secs / 0.007 secs)
TOTAL: 1 SUCCESS

In regards to browser tests. We are using Karma and it supports running tests in the browser. This plugin currently is using PhantomJS but it is easy to make it use Chrome or Firefox. You can also start tests in watchmode and open the URL that Karma returns, seen as http://localhost:9876/ above.

@jacob414
Copy link
Author

jacob414 commented Apr 25, 2016

Strange. I still get complaints about the fs module. I suspect we have some installation method / version missmatch [1], will start to re-install tools and see if I can replicate your run.

[..]o/roc-0$ roc test --test-src-path app/
Found a local version of Roc, will use that over the global one.

Hash: 5ed37ab6a514541195ba
Version: webpack 1.12.14

 # ..lots of output.. 

25 04 2016 13:46:54.221:INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
25 04 2016 13:46:54.226:INFO [launcher]: Starting browser PhantomJS
25 04 2016 13:47:11.939:INFO [Chrome 50.0.2661 (Mac OS X 10.11.4)]: Connected on socket /#HK3bSTKP9narZYTPAAAA with id manual-9098
Chrome 50.0.2661 (Mac OS X 10.11.4) LOG LOG: 'POC test definition'
Chrome 50.0.2661 (Mac OS X 10.11.4) ERROR
  Uncaught Error: Cannot find module "fs"
  at /Users/jacob/src/lab/miveo/roc-0/node_modules/roc-plugin-test-mocha-karma-webpack/lib/karma/utils/entry.js:30700 <- webpack:///~/mocha/lib/utils.js:9:0

After this the test runner freezes and must be killed with kill -9 ...

  1. Actually, it's auto-killed after 60000ms
  2. Re-installed PhantomJS using npm install -g phantomjs-prebuilt, killed quickly now, output ending in:
    25 04 2016 14:03:50.769:INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
    25 04 2016 14:03:50.774:INFO [launcher]: Starting browser PhantomJS
    25 04 2016 14:03:51.323:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket /#8gBB6-UCuRv9-zhkAAAA with id 16888694
    PhantomJS 2.1.1 (Mac OS X 0.0.0) LOG LOG: 'POC test definition'
    PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
    Error: Cannot find module "fs"
    at /Users/jacob/src/lab/miveo/roc-0/node_modules/roc-plugin-test-mocha-karma-webpack/lib/karma/utils/entry.js:30700 <- webpack:///~/mocha/lib/utils.js:9:0

[1]: Trying with Node v5.8.0, PhantomJS 2.1.1 (installed as npm i -g phantomjs-prebuilt) for now

@dlmr
Copy link
Member

dlmr commented Apr 25, 2016

What if you remove all of your node_modules and install it again? I cloned your repo and it worked for me directly. I can look a bit more into this a little later if there still is a problem!

@jacob414
Copy link
Author

Reinstalling, I'll be back with the results shortly..

@jacob414
Copy link
Author

jacob414 commented Apr 25, 2016

Unfortunately still failing, tail of error message:

25 04 2016 14:20:55.602:INFO [launcher]: Starting browser PhantomJS
25 04 2016 14:20:56.203:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket /#hO_Q1S4MRU2xsz9fAAAA with id 46501002
PhantomJS 2.1.1 (Mac OS X 0.0.0) LOG LOG: 'POC test definition'
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
  Error: Cannot find module "fs"
  at /Users/jacob/src/lab/miveo/roc-0/node_modules/roc-plugin-test-mocha-karma-webpack/lib/karma/utils/entry.js:30700 <- webpack:///~/mocha/lib/utils.js:9:0

PhantomJS 2.1.1 (Mac OS X 0.0.0): Executed 0 of 0 ERROR (0.277 secs / 0 secs)

I've also found this mention of a similar problem in the project jade-loader, I stuck one of those in a webpack.config.js of mine once. The fact that you can run my No-op test on your machine indicates it's something else, though.

@dlmr
Copy link
Member

dlmr commented Apr 25, 2016

This is quite strange. I once again made a clean copy of your repo and was able to test it without problems. I understand what the error is and how to fix it, but I can't understand why you are getting it.

@jacob414
Copy link
Author

Trying a rm -rf and re-clone my own repo now, let's see if some old state is to blame..

@jacob414
Copy link
Author

jacob414 commented Apr 25, 2016

D'oh! It was. You can close the issue now (browser-testing + watcher looks very promising, btw).

@dlmr
Copy link
Member

dlmr commented Apr 25, 2016

Great that it works! 🙂

@dlmr dlmr closed this as completed Apr 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants