speedskater / babel-plugin-rewire

A babel plugin adding the ability to rewire module dependencies. This enables to mock modules for testing purposes.
842 stars 90 forks source link

Karma&Browserify with config object does not work. #73

Open davidreher opened 9 years ago

davidreher commented 9 years ago

Hey, I have a karma.conf.js with the following content:

var babelPluginRewire = require('babel-plugin-rewire');

module.exports = function (config) {
  config.set({
    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '../../',

    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['browserify', 'jasmine'],
[...]
    browserify: {
      debug: true,
      plugin: ['tsify'],
      transform: [['babelify', {plugins: [babelPluginRewire]}], ['stringify', {extensions: ['*.json']}]]
    },
[...]

and I do not get any RewireApi object in my tests (the following test fails):

import React from 'react';

describe('rewire', () => {
  it('works', () => {
    expect(React.__RewireApi__).toBeDefined();
  });
});

Can you help me with this?

speedskater commented 9 years ago

Thanks for reporting this Bug and the Delay on this issue but I am currently on holidays and will return on the 23rd of november. I will comment on this Bug as soon as I will return.

VoloshinS commented 8 years ago

Hi! Is there any updates on this issue?

After adding plugin to karma configs:

...
    browserify: {
      debug: true,
      plugins: ['tsify'],
      transform: [['babelify', {plugins: ['rewire']}], 'reactify']
    },
...

I get following error for all tests' files:

ERROR [framework.browserify]: TypeError: /path_to_file.js: Property id of FunctionDeclaration expected node to be of a type ["Identifier"] but instead got null while parsing file: /path_to_file.js
speedskater commented 8 years ago

@VoloshinS sorry haven't looked into it till now. fighting with babel 6 at the moment...