Skip to content

Support for babel env option #14

@bashar-qassis

Description

@bashar-qassis

I'm in a case where tests and source code are both using imports (ES6 syntax). pectin wants modules to be set to false while mocha want them to be true.
Babel supports multiple envs in the babelrc config file, so supporting it in pectin would be great.

I'm currently using node v13.10.1, babel 6 and pectin ^3.6.1

PS: any other suggestions for me to do this in a "better" way are also welcome 😊

.babelrc file

{
  "env": {
    "test": {
      "presets": [
        [
          "env",
          {
            "targets": {
              "node": "current"
            }
          }
        ]
      ]
    },
    "build": {
      "presets": [
        [
          "env",
          {
            "modules": false,
            "targets": {
              "node": "current"
            }
          }
        ]
      ]
    }
  }
}

sample app.js

export function foo () {
    return 'bar'
}

sample test.spec.js

import { foo } from '../src/app'

describe('testing app', () => {
    it('should return bar', function () {
        expect(foo()).to.deep.equal('bar')
    })
})

mocha.opts

--require babel-core/register
--require babel-register
--require test/setup.js
--recursive

source: https://babeljs.io/docs/en/6.26.3/babelrc

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions