avajs / babel

Babel provider for AVA.
11 stars 3 forks source link

Optional chaining in source not working #33

Closed donkeyDau closed 3 years ago

donkeyDau commented 3 years ago

I've just started using AVA and can't get my tests run when an import source function uses optional chaining.

I get this error:

  Uncaught exception in service/__test__/business/entities/updateEntity/updateEntity.test.js

  /some/path/modules/lib/src/getGraphQlError.js:2
    const message = error?.response?.errors?.[0]?.message;
                          ^

  SyntaxError: Invalid or unexpected token

  › SyntaxError: Invalid or unexpected token
  › Object._compile (node_modules/pirates/lib/index.js:99:24)

My package.json looks like:

{
  "name": "test",
  "private": true,
  "ava": {
    "require": [
      "esm",
      "@babel/register"
    ],
    "babel": true
  },
  "devDependencies": {
    "@ava/babel": "2.0.0",
    "@babel/register": "7.15.3",
    "ava": "3.15.0",
    "esm": "3.2.25"
  }
}

I'm pretty sure I'm missing something obvious but I couldn't get a grip on it so far ...

novemberborn commented 3 years ago

@ava/babel only compiles test files. It looks like that does support optional chaining (though it hasn't been updated in a while for newer proposals).

I think you're better off without @ava/babel and relying on @babel/register to compile everything on the fly. But then Babel needs to be configured to compile optional chaining.