Skip to content

Wrong line number shown for failing assert #1980

Closed
@ratiotile

Description

@ratiotile

Issuehunt badges

Description

AVA reports the wrong line number on failing tests. It seems that sourcemaps aren't working, as the line number is greater than the size of the test file. When the line number falls within the source file, a snippet is displayed, but it does not correspond with the failing assertion.

Test Source

import test from 'ava'
import * as convert from './parameter_convert.js'

test('int converter', t => {
  let converted = convert.to.int('foo')
  t.is(converted, 'foo')
})

Error Message & Stack Trace

The test file is only 7 lines long, yet the line 40 is indicated in the message below:

middleware › test_parameter_convert › int converter

test_parameter_convert.js:40

  Difference:

  - NaN
  + 'foo'

Config

I am using ava.config.js:

export default {
  files: ['src/**/test_*.js'],
  sources: ['src/**/*.js'],
  color: true,
  compileEnhancements: false,
  require: ['./babel_register.js'],
  verbose: true,
}

.babelrc

module.exports = function(api) {
  let config = {
    sourceMaps: 'inline',
    presets: [
      '@babel/preset-flow',
      [
        '@babel/preset-env',
        {
          targets: {
            node: 'current',
          },
          modules: 'commonjs',
        },
      ],
    ],
  api.cache.forever()
  return config
}

Command-Line Arguments

ava

Relevant Links

Minimal reproduction
parameter_convert.js

// @flow
/**
 * Conversion functions
 */
export const to = {
  string: (raw: any) => String(raw),
  date: (raw: any) => new Date(raw),
  int: (raw: any) => {
    const converted = Number(raw)
    return converted === undefined ? raw : converted
  },
}

Environment

darwin 17.7.0
ava 1.0.0-rc.2
npm 6.4.1

There is a $60.00 open bounty on this issue. Add more on Issuehunt.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions