Cannot require Underscore with CasperJS

I use CasperJSto run automated tests with an interface, but I am having problems using other npm modules in my tests. I know patchRequire, but I believe that this should only be called outside the test environment, since patches for the test runner are automatically required. I turned it on, but the results were the same. It says that he cannot find the module. I confirmed that the underscore is installed in node_modulesthe root folder of the projects.

code

'use strict'

_ = require 'underscore'

testConfig =
    testPageUrl: ''
    testSearchTerm: 'the'

config = _.extend testConfig, require 'common/config'

Javascript Code

'use strict';

_ = require('underscore');

testConfig = {
  testPageUrl: '',
  testSearchTerm: 'the'
};

config = _.extend(testConfig, require('common/config'));

Mistake

CasperError: cannot find module underscore

+4
source share
1 answer

, , , -, npm casper script.

./proxies/underscore.js:

module.exports = require('underscore');

./tests/test.js

var _ = require('../proxies/underscore');
+6

All Articles