Ava babel-register does not broadcast

I am trying to include Ava (migrating from a mocha) as my test runner for a reaction / electron application.

I have this config in my package.json

  "ava": {
    "files": [
      "./app/**/*.spec.js"
    ],
    "source": [
      "./app/**/*.{js,jsx}"
    ],
    "concurrency": 5,
    "failFast": true,
    "require": [
      "babel-register",
      "ignore-styles",
      "./app/test/setup.js"
    ],
    "babel": {
      "presets": [
        "es2015",
        "react"
      ]
    }
  },

With my setup.js, just being an assistant to configure jsdom.

I get an error message:

(function (exports, require, module, __filename, __dirname) { import { jsdom } from 'jsdom';
                                                              ^^^^^^
SyntaxError: Unexpected token import

So it seems that it is babel-registernot required properly.

+4
source share
1 answer

You probably already found the answer, but I would share my decision. For me, it was moving the section babelnext to the section avaas follows:

{
  "ava": { ... ava config ... },
  "babel": { ... babael config ... }
}

Full example

{
  "ava": {
    "files": [
      "./app/**/*.spec.js"
    ],
    "source": [
      "./app/**/*.{js,jsx}"
    ],
    "concurrency": 5,
    "failFast": true,
    "require": [
      "babel-register",
      "ignore-styles",
      "./app/test/setup.js"
    ]
  },
  "babel": {
    "babelrc": false,
    "presets": [
      "es2015",
      "react"
    ]
  }
}

The reason is that this is a babel search. Either a file package.jsonor a file .babelrc.

+1

Source: https://habr.com/ru/post/1658866/


All Articles