acvetkov / sinon-chrome

Testing chrome extensions with Node.js
ISC License
435 stars 46 forks source link

Karma configuration #37

Closed herodrigues closed 7 years ago

herodrigues commented 7 years ago

I know that there is a karma sinon-chrome wrap, but I could not find any reliable solution to what I'm looking for. I'm getting this error:

Chrome 52.0.2743 (Linux 0.0.0) ERROR
  Uncaught TypeError: Cannot read property 'create' of undefined
  at node_modules/sinon-chrome/dist/sinon-chrome.latest.js:7537

My spec file

  describe('chrome.*', function () {
    beforeEach(function () {
      console.log(chrome);
    });

    it('should open a new tab', function () {
      // chrome.tabs.create({});
      // expect(chrome.tabs.create.called).toBe(true);
    });
  });

I installed sinon-chrome and karma-sinon-chrome via npm. My karma config file:

  frameworks: [
      'jasmine',
      'requirejs',
      'sinon-chrome'
    ],

    // list of files / patterns to load in the browser
    files: [
      { pattern: 'src/**/*.js', included: false },
      { pattern: 'test/*-spec.js', included: false },
      'require.conf.js'
    ],

    // list of files to exclude
    exclude: [
      'src/vendor/**/*.js'
    ],

    // plugins
    plugins: [
      'karma-jasmine',
      'karma-chrome-launcher',
      'karma-requirejs',
      'karma-sinon-chrome'
      //'karma-coverage'
    ],
acvetkov commented 7 years ago

Hi, @herodrigues . https://github.com/9joneg/karma-sinon-chrome/issues/3

9joneg commented 7 years ago

Sinon.JS v1.x as source doesn't work with AMD loaders / RequireJS / Webpack / Browserify.

This has been resolved in Sinon v2.x

https://github.com/sinonjs/sinon#important-sinon-v1x-does-not-work-with-amdcommonjs-bundlers

herodrigues commented 7 years ago

So, there is no solution yet?

acvetkov commented 7 years ago

So, we should wait sinon 2 stable version (now 2.0.0-pre.2).

herodrigues commented 7 years ago

Thanks @acvetkov.

I followed your instructions in https://github.com/acvetkov/sinon-chrome/issues/11

Here is my solution for those who need it.

My webpack.config.js:

var webpack = require('webpack');
var path = require('path');

module.exports = {
  resolve: {
    modulesDirectories: ['node_modules'],
    alias: {
      sinon: path.resolve(__dirname, 'node_modules/sinon/pkg/sinon.js')
    },
    extensions: ['', '.js', '.jsx']
  },
  module: {
    noParse: []
  }
}
acvetkov commented 7 years ago

https://github.com/acvetkov/sinon-chrome/issues/11