question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can group initialization be asynchronous?

See original GitHub issue

In my test case, I want to create multiple instances of a model in a database. And run a separate test for each:

test.group('Status code must mee 2xx or 3xx', async (group) => {
  let links = await ShortLinkFactory.createMany(50)

  links.forEach(link => {
    test(link.id, async (assert) => {
      await supertest(link.url)
        .get('/')
        .expect((res) => {
          assert.isAbove(res.statusCode, 200)
          assert.isBelow(res.statusCode, 400)
        })
    })
  })
})

Of course I can do everything in one test, but then I do not get a beautiful and convenient log that conveniently displays which links returned the expected result and which failed

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
thetutlagecommented, Jan 7, 2022

The groups cannot be asynchronous right now. Once, we all move to ESM + top level await, then this is will possible automatically without changing anything in Japa.

However, what you are trying to do is a better fit for datasets. Datasets are coming in the next version. Following is an example code for the same.

test('some title', ({ assert }, link) => {
  
})
.with(() => ShortLinkFactory.createMany(50))

The above test will run for 50 times.

0reactions
thetutlagecommented, Feb 21, 2022

The newer version has datasets for this exact use case. Here are the docs https://japa.dev/datasets

Closing it for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use synchronous or asynchronous initialization - Optimizely
Initializing a client asynchronously executes like the synchronous initialization, except the manager will first attempt to download the newest datafile.
Read more >
c# - How to initialize an object using async-await pattern
And here comes the problem, with the initial value. Since the ImportantValue is calculated asynchronously, the class cannot be fully initialized in constructor....
Read more >
Initialize Databases Asynchronously - Sybase Infocenter - SAP
The asynchronous initialization is performed by a service task that is started by the create database or alter database command. When it restarts,...
Read more >
Use AsyncPackage to load VSPackages in the background
If the caller uses IAsyncServiceProvider to asynchronously query for your service, then your load and initialization will be done asynchronously ...
Read more >
swift-evolution/0317-async-let.md at main - GitHub
While task groups are indeed very powerful, they are hard to use with heterogeneous results and step-by-step initialization patterns. The following example, an ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found