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.

feat: run parallel tests with different test contexts

See original GitHub issue

I’d love to be able to initialise setupTest several times in the same file or even across files in the test suite.

E.g. do something like this
import { setupTest, createPage, cleanup } from '@nuxtjs/module-test-utils'

describe('module with default options', () => {
  setupTest({
    __dirname,
    browser: true,
    fixture: '../example',
  })

  test('My test', async () => {
    // ...
  })
})

describe('module with other options', () => {
  setupTest({
    __dirname,
    browser: true,
    fixture: '../example',
    config: differentOptions,
  })

  test('My test', async () => {
    // ...
  })
})

If I do this, I get non-determinative behaviour - or errors - even if the test is setup only once in each test spec file. (That is, options leak from one test context into another.) Or (if I pass different config objects in different files), I get:

 TypeError: Cannot read property 'moduleContainer' of undefined

   at node_modules/@nuxtjs/module-test-utils/dist/index.js:286:29
   at fulfilled (node_modules/tslib/tslib.js:112:62)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
pi0commented, Aug 9, 2020

@danielroe #49 would be perfect if all internals can be instructed to use mock mfs. random build dir is also nice idea for a shorter term. Something else that would be awesome is if we can do snapshot builds similar to new nuxt generate to avoid unnecessary rebuilds when running tests multiple times. We may also introduce a lock-file to fix multi build conflict.

Also, issue with multiple describes in single file should be fixed by #51 (2.0.0-2) 😃

1reaction
pi0commented, Aug 9, 2020

In fact, I’ve tested further and there is a conflict even when multiple files set up different contexts. The tests at least run but one context overwrites the other.

There is no shared context between multiple files no matter keeping context in test file or an imported library each test file is sandboxed in a worker. The reason multiple setup files are failing is mostly because the setup is also doing a nuxt build which because two runnin in parallel, conflicting on fs level (buildDir)

// test/shared.js
let state = 0

exports.inc = () => { state ++ }
exports.get = () => state
// test/a.test.js
const { get, inc } = require('./shared.js')

describe('A', () => {
  test('inc', () => {
    expect(get()).toBe(0)
    inc()
    expect(get()).toBe(1)
  })
})
// test/b.test.js
const { get, inc } = require('./shared.js')

describe('B', () => {
  test('inc', () => {
    expect(get()).toBe(0)
    inc()
    expect(get()).toBe(1)
  })
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Revving up Continuous Integration with Parallel Testing
Our starting definition may look deceptively simple: we say we're performing parallel testing when two or more tests are run simultaneously.
Read more >
tun unit tests in parallel and other test sequentially in the ...
i am having an issue to understand how can i run all the unit tests in my boot spring application(kotlin) ...
Read more >
How to run Jest tests sequentially
The --runInBand or -i option of the Jest CLI allows you to run tests sequentially (in non-parallel mode). The final command will look...
Read more >
Run VSTest tests in parallel - Azure Pipelines
Continuous testing. Speed up testing by running tests in parallel using Visual Studio Test task.
Read more >
Choosing a Test Runner
When using these runners, Test Environment will create an independent local blockchain for each parallel run, so there is zero risk of your...
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