Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to use t.try in before hook #2511

Closed
tymfear opened this issue Jun 12, 2020 · 4 comments
Closed

Impossible to use t.try in before hook #2511

tymfear opened this issue Jun 12, 2020 · 4 comments

Comments

@tymfear
Copy link
Contributor

tymfear commented Jun 12, 2020

Please provide details about:

  • What you're trying to do
    Use t.try in the test.before hook

  • What happened
    The following error is thrown:

  TypeError {
    message: 'test.registerUniqueTitle is not a function',
  }
  • What you expected to happen
    No error are thrown

Please share relevant sample code. Or better yet, provide a link to a minimal reproducible example.

import anyTest, { ExecutionContext, TestInterface } from 'ava';
const test: TestInterface = anyTest as TestInterface;

test.before(async (t: ExecutionContext) => {
  const res = await t.try((tt: ExecutionContext) => tt.is(1, 1))

  res.commit();
})

test('test', async (t: ExecutionContext) => t.pass());

We'll also need your AVA configuration (in package.json or ava.config.* configuration files) and how you're invoking AVA. Share the installed AVA version (get it by running npx ava --version).
AVA version: 3.8.2

Config:

export default function factory() {
  return {
    require: ['ts-node/register', 'tsconfig-paths/register'],
    files: ['spec/**/*'],
    cache: true,
    failWithoutAssertions: true,
    verbose: true,
    extensions: ['ts'],
    concurrency: process.env.AVA_CONCURRENCY || 10,
    timeout: '90s',
  };
}

AVA is invoked with npx ava path/to/file command. Also reproducible with IDEA Node configuration

@novemberborn
Copy link
Member

Good find @tymfear!

Looking at the code, we don't enforce unique titles for hooks. Which means that we shouldn't allow them to use snapshots either, so that's a bit of an oversight.

Enforcing unique titles for before and after hooks isn't as straight-forward as it sounds. I'm tempted to explicitly fail these assertions in all hooks going forward (though this would be a breaking change when it comes to snapshots). What would you think of that? What setup / teardown problems are you running into that require t.try()?

@tymfear
Copy link
Contributor Author

tymfear commented Jun 14, 2020

@novemberborn I was just using it to check if my preconditions are fulfilled and I can go on with tests. It was part of the retry mechanism. I was using the deepEqual, but replaced it with lodash and plain error throwing, so not a big deal.

Probably, another parameter could be added to the t.try hook, that will allow configuring unique title, and that would allow hook usage anywhere without breaking changes?

@novemberborn
Copy link
Member

Probably, another parameter could be added to the t.try hook, that will allow configuring unique title, and that would allow hook usage anywhere without breaking changes?

You can already provide the title. Really what it comes down to is that snapshots require unique titles, and we're not enforcing title uniqueness for hooks.

I'm just not sure that we should, which means we should be explicitly failing snapshot and try assertions.

@novemberborn
Copy link
Member

I'm just not sure that we should, which means we should be explicitly failing snapshot and try assertions.

See #2523.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants