babel-plugin-rewire icon indicating copy to clipboard operation
babel-plugin-rewire copied to clipboard

Karma&Browserify with config object does not work.

Open davidreher opened this issue 9 years ago • 3 comments

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?

davidreher avatar Nov 03 '15 13:11 davidreher

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.

speedskater avatar Nov 04 '15 11:11 speedskater

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

VoloshinS avatar Nov 25 '15 11:11 VoloshinS

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

speedskater avatar Nov 25 '15 12:11 speedskater