Skip to content

Enabling coverage with enabled Babel plugin fails #123

Closed

Description

@jleja

I have a demo repo set up to illustrate the issue. When using a Babel plugin, such as babel-plugin-transform-object-rest-spread, building the project fails with the error TypeError: The plugin "transform-object-rest-spread" didn't export a Plugin instance , preventing the build from succeeding.

Steps taken to build the demo repo:

  • Create new Ember 2.13 project
  • Configure project to use pods
  • Add babel config to ember-cli-build.js
  • Update package.json to include devDependency for babel-plugin-transform-object-rest-spread
  • Add config/coverage.js to configure using Babel instrumentation, as well as to indicate the desired plugin
  • Add new test route and controller, set an object to render to template that uses the spread operator

Test results:

$ ember test
'instrument' is imported from external module 'ember-data/-debug' but never used
cleaning up...
Built project successfully. Stored in "/Users/jleja/code/testApp/tmp/class-tests_dist-vC0AgVDo.tmp".
ok 1 PhantomJS 2.1 - ESLint | app: app.js
ok 2 PhantomJS 2.1 - ESLint | app: resolver.js
ok 3 PhantomJS 2.1 - ESLint | app: router.js
ok 4 PhantomJS 2.1 - ESLint | app: test/controller.js
ok 5 PhantomJS 2.1 - ESLint | app: test/route.js
ok 6 PhantomJS 2.1 - ESLint | tests: helpers/destroy-app.js
ok 7 PhantomJS 2.1 - ESLint | tests: helpers/module-for-acceptance.js
ok 8 PhantomJS 2.1 - ESLint | tests: helpers/resolver.js
ok 9 PhantomJS 2.1 - ESLint | tests: helpers/start-app.js
ok 10 PhantomJS 2.1 - ESLint | tests: test-helper.js
ok 11 PhantomJS 2.1 - ESLint | tests: unit/test/route-test.js
ok 12 PhantomJS 2.1 - Unit | Route | test: it exists

1..12
# tests 12
# pass  12
# skip  0
# fail  0
$ COVERAGE=true ember test
⠸ Building'instrument' is imported from external module 'ember-data/-debug' but never used
⠴ BuildingUnable to cover: app/app.js . Try setting useBabelInstrumenter to true. 
 TypeError: The plugin "transform-object-rest-spread" didn't export a Plugin instance
    at PluginManager.validate (/Users/jleja/code/testApp/node_modules/ember-cli-code-coverage/node_modules/babel-core/lib/transformation/file/plugin-manager.js:164:13)
    at PluginManager.add (/Users/jleja/code/testApp/node_modules/ember-cli-code-coverage/node_modules/babel-core/lib/transformation/file/plugin-manager.js:213:10)
    at File.buildTransformers (/Users/jleja/code/testApp/node_modules/ember-cli-code-coverage/node_modules/babel-core/lib/transformation/file/index.js:237:21)
    at new File (/Users/jleja/code/testApp/node_modules/ember-cli-code-coverage/node_modules/babel-core/lib/transformation/file/index.js:139:10)
    at Pipeline.transform (/Users/jleja/code/testApp/node_modules/ember-cli-code-coverage/node_modules/babel-core/lib/transformation/pipeline.js:164:16)
    at Instrumenter.instrumentSync (/Users/jleja/code/testApp/node_modules/ember-cli-code-coverage/lib/babel-istanbul-instrumenter.js:36:45)
    at CoverageInstrumenter.processString (/Users/jleja/code/testApp/node_modules/ember-cli-code-coverage/lib/coverage-instrumenter.js:113:25)
    at CoverageInstrumenter.processFile (/Users/jleja/code/testApp/node_modules/broccoli-filter/index.js:165:31)
    at asyncProcessFile (/Users/jleja/code/testApp/node_modules/broccoli-filter/index.js:122:21)
    at tryCatch (/Users/jleja/code/testApp/node_modules/rsvp/dist/rsvp.js:539:12)

(Same TypeError repeats for each file)

cleaning up...
Built project successfully. Stored in "/Users/jleja/code/testApp/tmp/class-tests_dist-VG1YuBo3.tmp".
not ok 1 PhantomJS 2.1 - Global error: TypeError: undefined is not an object (evaluating '_resolver.default') at http://localhost:7357/assets/tests.js, line 83
    ---
        Log: |
            { type: 'error',
              text: 'TypeError: undefined is not an object (evaluating \'_resolver.default\') at http://localhost:7357/assets/tests.js, line 83\n' }
    ...
not ok 2 PhantomJS 2.1 - Global error: Error: Assertion Failed: The tests file was not loaded. Make sure your tests index.html includes "assets/tests.js". at http://localhost:7357/assets/vendor.js, line 18622
    ---
        Log: |
            { type: 'error',
              text: 'Error: Assertion Failed: The tests file was not loaded. Make sure your tests index.html includes "assets/tests.js". at http://localhost:7357/assets/vendor.js, line 18622\n' }
    ...

While I haven't really tried any other plugins, I have at least tried seeing what would happen if I just loaded the Babel plugin without needing to transform anything. Same errors occur.

Activity

  1. anehx commented on Jun 19, 2017

    @anehx

    I got the same with babel-plugin-transform-decorators-legacy and babel-plugin-transform-async-generator-functions.. I think this appears for every babel plugin.

  2. anehx commented on Jun 19, 2017

    @anehx

    Fixed this by depending on the current master branch of this addon which fixed this issue...

  3. jleja commented on Jun 19, 2017

    @jleja
    Author

    In my demo branch, checking out master does indeed fix it. In the application I'm working on, doing that starts surfacing [BABEL] app/templates/testing.hbs: Using removed Babel 5 option: base.optional - Put the specific transforms you want in the 'plugins' option. Looks like another dependency is the issue, shall look further into it. Thanks!

  4. jleja commented on Jun 19, 2017

    @jleja
    Author

    That wasn't too hard to track down. In my application, I had Babel configured as:

    babel: {
                compact: false,
                optional: ['es7.decorators'],
                plugins: ['transform-object-rest-spread']
            }
    

    Doesn't like the optional setting, so I'll just move that to a plugin. Closing this issue down!

  5. rwjblue commented on Jun 19, 2017

    @rwjblue
    Collaborator

    optional isn't valid with babel@6, see readme of https://github.com/rwjblue/ember-computed-decorators#babel-6x for details on getting decorators to work

  6. jleja commented on Jun 19, 2017

    @jleja
    Author

    Thanks @rwjblue!

  7. buschtoens commented on Aug 18, 2017

    @buschtoens

    I'm trying to get coverage running with ES6 classes and static class properties, but apparently I must be doing something wrong...

    buschtoens/ember-joda#4

    Failed to parse file: ember-joda/transforms/day-of-week.js
    Unable to cover: ember-joda/transforms/day-of-week.js . Newer JS features may need Babel instumentation to work. Try setting useBabelInstrumenter to true in your config/coverage.js.
     Error: Line 5: Unexpected token =
        at constructError (/home/travis/build/buschtoens/ember-joda/node_modules/esprima/esprima.js:2407:21)
        at createError (/home/travis/build/buschtoens/ember-joda/node_modules/esprima/esprima.js:2426:17)
        at unexpectedTokenError (/home/travis/build/buschtoens/ember-joda/node_modules/esprima/esprima.js:2500:13)
        at throwUnexpectedToken (/home/travis/build/buschtoens/ember-joda/node_modules/esprima/esprima.js:2505:15)
        at parseClassBody (/home/travis/build/buschtoens/ember-joda/node_modules/esprima/esprima.js:5147:21)
        at parseClassDeclaration (/home/travis/build/buschtoens/ember-joda/node_modules/esprima/esprima.js:5169:21)
        at parseExportDefaultDeclaration (/home/travis/build/buschtoens/ember-joda/node_modules/esprima/esprima.js:5296:27)
        at parseExportDeclaration (/home/travis/build/buschtoens/ember-joda/node_modules/esprima/esprima.js:5345:20)
        at parseStatementListItem (/home/travis/build/buschtoens/ember-joda/node_modules/esprima/esprima.js:3970:24)
        at parseScriptBody (/home/travis/build/buschtoens/ember-joda/node_modules/esprima/esprima.js:5490:25)
    

    https://travis-ci.org/buschtoens/ember-joda/jobs/265890944#L558-L570

  8. buschtoens commented on Aug 18, 2017

    @buschtoens

    My bad. The config file has to be located at tests/dummy/config/coverage.js for addons. Seems a bit weird to me, but fits the docs (implicitly), since configPath is tests/dummy/config for addons:

    Configuration is optional. It should be put in a file at config/coverage.js (configPath configuration in package.json is honored)

    However, while the plugin is now found, it can't be used:

    Unable to cover: ember-joda/index.js . Newer JS features may need Babel instumentation to work. Try setting useBabelInstrumenter to true in your config/coverage.js.
     Error: Plugin 1 specified in "base" provided an invalid property of "_parallelBabel"
        at Plugin.init (/home/travis/build/buschtoens/ember-joda/node_modules/babel-core/lib/transformation/plugin.js:131:13)
        at Function.normalisePlugin (/home/travis/build/buschtoens/ember-joda/node_modules/babel-core/lib/transformation/file/options/option-manager.js:152:12)
        at /home/travis/build/buschtoens/ember-joda/node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
        at Array.map (native)
        at Function.normalisePlugins (/home/travis/build/buschtoens/ember-joda/node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
        at OptionManager.mergeOptions (/home/travis/build/buschtoens/ember-joda/node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
        at OptionManager.init (/home/travis/build/buschtoens/ember-joda/node_modules/babel-core/lib/transformation/file/options/option-manager.js:368:12)
        at File.initOptions (/home/travis/build/buschtoens/ember-joda/node_modules/babel-core/lib/transformation/file/index.js:212:65)
        at new File (/home/travis/build/buschtoens/ember-joda/node_modules/babel-core/lib/transformation/file/index.js:135:24)
        at Pipeline.transform (/home/travis/build/buschtoens/ember-joda/node_modules/babel-core/lib/transformation/pipeline.js:46:16)
    

    https://travis-ci.org/buschtoens/ember-joda/jobs/265930210#L567-L578

  9. buschtoens commented on Aug 18, 2017

    @buschtoens

    And there we have it: #133

    Sorry for the commotion. 😅

  10. reiallenramos commented on Mar 10, 2020

    @reiallenramos

    Recently encountered this problem when we upgraded from Ember 2.xx to 3.14. ember test works fine but fails when COVERAGE=true is added. @jleja do you still have the fix? It's not obvious in your comments what you did that resolved the issue. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions