avajs / ava

Node.js test runner that lets you develop with confidence 🚀
MIT License
20.74k stars 1.41k forks source link

Snapshot ids can collide with test names #2661

Closed ninevra closed 3 years ago

ninevra commented 3 years ago

What you're trying to do

I'm just testing edge cases in hopes of better understanding the code. This isn't likely to be important to anyone's use case.

What happened

If a snapshot has an id that matches a test name, it compares against the first snapshot from that test.

What you expected to happen

This should probably either:

The existing behavior could be used intentionally, but I can't think of a good reason to do so.

Sample code

const test = require('ava');

test('a name', t => {
  t.snapshot('one', 'a snapshot with no id');
  t.snapshot('two', {id: 'a name'});
});

This produces:

  a name

  test.js:5

   4:   t.snapshot('one', 'a snapshot with no id');
   5:   t.snapshot('two', {id: 'a name'});         
   6: });                                          

  Did not match snapshot

  Difference:

  - 'two'
  + 'one'

  › test.js:5:5

  ─

  1 test failed

The snapshot report looks like:

# Snapshot report for `test.js`

The actual snapshot is saved in `test.js.snap`.

Generated by [AVA](https://avajs.dev).

## a name

> a snapshot with no id

    'one'

Configuration

AVA v3.15.0.

No AVA configuration.

Invoking AVA as npx ava or npx ava --update-snapshots.

novemberborn commented 3 years ago

Perhaps we should remove this feature?

novemberborn commented 3 years ago

https://github.com/avajs/ava/issues/2669