0

As the question states, the requiring/importing of the module works fine in these cases:

const Session = require('../session.js').default;

or

import Session from '../session.js');

But I want to replace a module that is required inside session.js, so I tried to do that in a test with Proxyquireify:

const proxyquire = require('proxyquireify')(require);
const someStub = () => { return {}; };
someStub['@noCallThru'] = true;
const Session = proxyquire('../session.js', {
  'some': someStub
}).default;

Then I get an error stating that the module '../session.js' cannot be found.

PhantomJS 1.9.8 (Linux 0.0.0) ERROR
  Error: Cannot find module '../session.js'

My karma config is this:

module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: ['browserify', 'jasmine'],
    files: [
        'spec/**/*Spec.js'
    ],
    exclude: [
        'spec/**/PlayerSpec.js'
    ],
    preprocessors: {
      'spec/**/*Spec.js': ['browserify']
    },
    browserify: {
      debug: true,
      transform: ['babelify']
    },
    reporters: ['progress', 'dots'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['PhantomJS'],
    singleRun: false,
    concurrency: Infinity
  })
};

What could be wrong? Do you need any more information?

user2602152
  • 687
  • 7
  • 24

1 Answers1

0

Just stumbled onto the same issue. Noticed that proxyquireify did not inject require calls next to proxyquire ones for some reason, so I just ended up simply doing it myself, at least for now. Try using something like this:

require('../session.js');
const Session = proxyquire('../session.js', ...);