Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing controller which are using node modules #15

Closed
MiLk opened this issue Mar 13, 2014 · 11 comments
Closed

Testing controller which are using node modules #15

MiLk opened this issue Mar 13, 2014 · 11 comments

Comments

@MiLk
Copy link

MiLk commented Mar 13, 2014

I'm currently working on an application using node-webkit and AngularJS.

I tried to use the karma-nodewebkit-launcher module,
as I didn't find any other solution to run tests on the AngularJS part.

But I have an issue.
When I add a controller which use a node module to the file list in karma.conf.js,
I obtain the following error:

  Uncaught RangeError: Maximum call stack size exceeded
  at http://localhost:9876/context.html:1

I'm using node-webkit 0.8.4 with OSX 10.8.5.

My karma.conf.js is:

module.exports = function(config) {
  config.set({
    basePath: '../',

    files: [
      'app/assets/js/jquery/jquery.min.js',
      'app/assets/js/jquery/jquery-ui.min.js',
      'app/assets/js/angular/angular.min.js',
      'app/assets/js/angular/angular-route.min.js',
      'app/assets/js/angular/angular-mocks.js',
      //'app/assets/js/files/bootstrap.js',
      //'app/assets/js/files/functions.js',
      //'app/lib/**/*.js',
      'app/scripts/app.js',
      'app/scripts/controllers/*.js',
      'test/spec/controllers/*.js',
      'app/scripts/directives/*.js',
      'test/spec/directives/*.js'
    ],

    exclude: [
      'app/assets/js/jquery/plugins/uploader/*.js',
    ],

    autoWatch: false,

    frameworks: ['mocha'],

    browsers: ['NodeWebkit'],

    singleRun: true
  });
};

Did I do something wrong ?
Is there a file missing in my karma.conf.js ?

Thank you.

@michalc
Copy link

michalc commented Mar 13, 2014

Hi,

I'm not sure exactly, but I've found karma-runner/karma#835 . Could a framework be somehow included twice?

If that doesn't help, than can you post a minimal example, with just enough code in order to be able to reproduce the issue at my end?

@MiLk
Copy link
Author

MiLk commented Mar 14, 2014

Hi,

I've just created a new little project: https://github.com/MiLk/node-webkit-test
The problem seems to be related to karma-mocha (same error with chai and expect.js).
By using karma-jasmine, I don't have any issue with the basic app.

Thank you for your help.

@MiLk
Copy link
Author

MiLk commented Mar 14, 2014

In MiLk/node-webkit-test@9b095fc, I added a node module from npm in a controller.

But I obtain this error:

  Uncaught Error: Cannot find module 'underscore'
  at module.js:343

Adding 'node_modules/underscore/*.js', to the file list in karma.conf.js doesn't change anything.

@michalc
Copy link

michalc commented Mar 14, 2014

Regarding the underscore error, it looks like Node can't find the locally installed modules. A solution that works at my end is to set the environment variable NODE_PATH before running the tests

export NODE_PATH=/full/path/to/node-webkit-test/node_modules

@MiLk
Copy link
Author

MiLk commented Mar 14, 2014

Ok, thank you. I'll try this solution on Monday.

@michalc
Copy link

michalc commented Mar 16, 2014

Regarding Mocha... it seems to overwrite the global global object with window, which I think causes things to break, and I've not managed to find a workaround without editing Mocha itself. I've submitted this change as a PR to Mocha https://github.com/visionmedia/mocha/pull/1159/files

However, you can hack this in your local Mocha install by changing line 5695 of node_modules/mocha/mocha.js from

global = (function() { return this; })();

to

var global = (function() { return this; })();

Any better work-arounds or solutions without Mocha.js being changed are welcome.

@MiLk
Copy link
Author

MiLk commented Mar 17, 2014

By editing the NODE_PATH, I'm now able to use modules installed from npm.
But I'm still not able to use my modules.

A call to process.cwd() indicates that the app is run from /private/var/folders/xx/xxxxx/T/karma-xxx/runner.nw'. It should explain, why he's not able to require the required modules.

I've added a new commit to my test project: MiLk/node-webkit-test@4623b19

I got the following error:

  Uncaught Error: Cannot find module './lib/random'
  at module.js:343

The fix for Mocha works for me.

Thank you.

@MiLk
Copy link
Author

MiLk commented Mar 17, 2014

Regarding 2d181f9, adding process.env.NODE_PATH = path.join(process.cwd(),'node_modules') + ':' + process.env.NODE_PATH; before the _execCommand() call here https://github.com/intelligentgolf/karma-nodewebkit-launcher/blob/master/index.js#L39 solve the problem.

What do you think about it ?

@boneskull
Copy link

mochajs/mocha#1159 was merged into the latest release, but the build didn't happen-- see mochajs/mocha#1284

@michalc
Copy link

michalc commented Jan 11, 2015

@boneskull The mocha build appears to have now been merged.

@MiLk I've included your suggestion, thanks. If there appears to be no problems, I'll bump the version in npm.

@michalc
Copy link

michalc commented Jan 15, 2015

Version bumped, closing this issue. If there are problems with the new version, feel free to post again.

@michalc michalc closed this as completed Jan 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants