Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests break after removing the "default" property #430

Open
atd opened this issue Sep 25, 2017 · 5 comments
Open

Tests break after removing the "default" property #430

atd opened this issue Sep 25, 2017 · 5 comments
Labels

Comments

@atd
Copy link

atd commented Sep 25, 2017

After following the last FAQ How can I export my library without the "default" property? (installing babel-plugin-add-module-exports and changing .babelrc), gulp test shows the following error:

$ gulp test               
[12:48:34] Using gulpfile ~/dev/cartodb.js/gulpfile.js
[12:48:34] Starting 'lint-src'...
[12:48:34] Starting 'lint-test'...
[12:48:34] Starting 'lint-gulpfile'...
[12:48:35] Finished 'lint-src' after 329 ms
[12:48:35] Finished 'lint-gulpfile' after 209 ms
[12:48:35] Finished 'lint-test' after 297 ms
[12:48:35] Starting 'lint'...
[12:48:35] Finished 'lint' after 9.63 μs
[12:48:35] Starting 'test'...
[12:48:35] 'test' errored after 299 ms
[12:48:35] TypeError in plugin 'gulp-mocha'
Message:
    /home/atd/dev/cartodb.js/test/setup/node.js: Property right of AssignmentExpression expected node to be of a type ["Expression"] but instead got null
Details:
    _babel: true
Stack:
TypeError: /home/atd/dev/cartodb.js/test/setup/node.js: Property right of AssignmentExpression expected node to be of a type ["Expression"] but instead got null
    at Object.validate (/home/atd/dev/cartodb.js/node_modules/babel-types/lib/definitions/index.js:109:13)
    at Object.validate (/home/atd/dev/cartodb.js/node_modules/babel-types/lib/index.js:505:9)
    at NodePath._replaceWith (/home/atd/dev/cartodb.js/node_modules/babel-traverse/lib/path/replacement.js:176:7)
    at NodePath._remove (/home/atd/dev/cartodb.js/node_modules/babel-traverse/lib/path/removal.js:58:10)
    at NodePath.remove (/home/atd/dev/cartodb.js/node_modules/babel-traverse/lib/path/removal.js:30:8)
    at PluginPass.CallExpression (/home/atd/dev/cartodb.js/node_modules/babel-plugin-transform-es2015-modules-amd/lib/index.js:42:12)
    at NodePath._call (/home/atd/dev/cartodb.js/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/home/atd/dev/cartodb.js/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/home/atd/dev/cartodb.js/node_modules/babel-traverse/lib/path/context.js:105:12)
    at TraversalContext.visitQueue (/home/atd/dev/cartodb.js/node_modules/babel-traverse/lib/context.js:150:16)

@atd atd changed the title Test break after removing the "default" property Tests break after removing the "default" property Sep 25, 2017
@jamesplease
Copy link
Member

If you build the lib, then look at the dist file, what does it appear to be exporting? You may need to adjust the tests to account for what’s exported.

@atd
Copy link
Author

atd commented Sep 26, 2017

These are the last lines of the dist file

          var cartodb = {
            greet: function greet() {
              return 'hello';
            }
          };
        
          exports.default = cartodb;
          module.exports = exports['default'];

Without the babel-plugin-add-module-exports:

        var cartodb = {
          greet: function greet() {
            return 'hello';
          }
        };
        
        exports.default = cartodb;

In any case, the only generated unit test doesn't seem to be related with the dist folder, but the src folder. Maybe there is a babel transformation in between?

import cartodb from '../../src/cartodb.js';

describe('cartodb', () => {
  describe('Greet function', () => {
    beforeEach(() => {
      spy(cartodb, 'greet');
      cartodb.greet();
    });

    it('should have been run once', () => {
      expect(cartodb.greet).to.have.been.calledOnce;
    });

    it('should have always returned hello', () => {
      expect(cartodb.greet).to.have.always.returned('hello');
    });
  });
});

@Nick-Lucas
Copy link

@atd did you manage to resolve this? I am facing the same issue and am lost

@atd
Copy link
Author

atd commented Jul 29, 2018

Hi @Nick-Lucas I cannot remember the details but it seems I switched to module.exports

https://github.com/atd/cartodb.js/blob/master/src/cartodb.js#L114-L116

@Nick-Lucas
Copy link

Ahhh gotcha, thanks!

I also managed to solve it. I had added transform-es2015-modules-umd as shown in the FAQ, but later realised this was just part of the example and removed it from my own code. This was the plugin which was breaking and the build works great without it.

User error!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants