Skip to content

Incorrect file path reported when using @babel/register #1882

@ronen

Description

@ronen

Description

When using @babel/register, the source file path reported in the case of exceptions is missing all components between the project directory and the test file. That is, rather than reporting, say:

 /projects/my-project/test/path/to-the/test-file.js:3

Instead it reports incorrectly:

/projects/my-project/test-file.js:3

Test Source

For illustration, put this test source a few subdirectories down, in test/path/to-the/test-file.js:

import test from 'ava'
test('test-name', t => {
  "foo".bar() // throws a TypeError
})

Error Message & Stack Trace

Running ava without @babel/register works as expected, reporting:

  1 test failed

  test-name

  /projects/my-project/test/path/to-the/test-file.js:4

   3: test('test-name', t => {
   4:   "foo".bar() // throws a TypeError
   5: })

  Error thrown in test:

  TypeError {
    message: '"foo".bar is not a function',
  }

but with @babel/register required, the reporter outputs the incorrect file path:

  1 test failed

  test-name

  /projects/my-project/test-file.js:3

  Error thrown in test:

  TypeError {
    message: '"foo".bar is not a function',
  }

Config

Here's package.json in its entirety for the failing case:

{
  "ava":{
    "require": [
      "@babel/register"
    ]
  },
  "devDependencies": {
    "@babel/register": "^7.0.0-beta.55",
    "ava": "^1.0.0-beta.6"
  }
}

Command-Line Arguments

No command line arguments. Just

$ npx ava

Relevant Links

Minimal reproduction here: https://github.com/ronen/ava-filepath-issue

Environment

$ node -e "var os=require('os');console.log('Node.js ' + process.version + '\n' + os.platform() + ' ' + os.release())"
Node.js v10.7.0
darwin 17.7.0
$ npx ava --version
1.0.0-beta.6
$ npm --version
6.2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcurrent functionality does not work as desired

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions