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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃殌 Feature: Parallel tests inside suite (was: in addition to it, will) #4588

Closed
nopeless opened this issue Feb 25, 2021 · 2 comments
Closed
Labels
status: wontfix typically a feature which won't be added, or a "bug" which is actually intended behavior type: feature enhancement proposal

Comments

@nopeless
Copy link

nopeless commented Feb 25, 2021

Is your feature request related to a problem or a nice-to-have?? Please describe.
nice-to-have

this will allow better aesthetics

// resolve after t ms; reject after t ms
const sleep = (t) => new Promise(r => setTimeout(r, t));
const sleepError = (t) => new Promise((_, r) => setTimeout(() => r(new Error(`random reason`)), t));

describe(`batch of asyncs`, function() {
  // and this lint error should be suppressed as well
  /* eslint-disable mocha/no-setup-in-describe */

  // set them to reject by default to prevent tests from being resolved when no task was assigned in the first place
  const e = Promise.reject(new Error("test not specified"));  
  let task1 = e, task2 = e, task3 = e;
  before(function () {
    task1 = sleep(1000);
    task2 = sleepError(2000);
    task3 = sleep(3000);
    // wait for these to resolve
    return Promise.allSettled([task1, task2, task3]);
  });
  it(`task1: should be accepted`, function() {
    return task1;
  });
  it(`task2: should be rejected`, function() {
    return task2;
  });
  it(`task3: should be accepted`, function() {
    return task3;
  });
});

into

// resolve after t ms; reject after t ms
const sleep = (t) => new Promise(r => setTimeout(r, t));
const sleepError = (t) => new Promise((_, r) => setTimeout(() => r(new Error(`random reason`)), t));

describe(`batch of asyncs`, function() {
  will(`be accepted`, function() {
    return sleep(1000)
  });
  will(`be rejected`, function() {
    return sleepError(1000)
  });
  will(`be accepted`, function() {
    return sleep(3000)
  });
});

fixes:

  • task1, 2, 3 will have proper timing reports
  • the logs will be in sequential order of success

breaks:

  • this means that tests using "will" will not be in order in code(or, delay the output of other tests to ensure that the print order is preserved).

optional:

  • slow error (5012ms) -> slow error (suite -> 5012ms)
    to indicate that the test was not done in serial

Describe alternatives you've considered
The before hook is just too verbose(and goes against a mocha eslint rule), and using parallel tests seems overkill

Additional context
I'm willing to make a fork myself

Additional features if possible
describeAsync an asynchronous suite. Lists all output to a single array then prints when the suite is complete. If all other tests are done, behave like describe and print reports normally.
mocha/no-root-describeAsync disables an asynchronous describe on root level, which will cause major tests to shift order

@nopeless
Copy link
Author

nopeless commented Dec 3, 2021

This will require a rewrite of a good section of the codebase though
I'll think about it after #4792 gets resolved

@Munter Munter changed the title in addition to it, will Parallel tests inside suite (was: in addition to it, will) Dec 6, 2021
@JoshuaKGoldberg
Copy link
Member

describeAsync an asynchronous suite

Tracked by #2116.

was ... will
...
This will require a rewrite of a good section of the codebase though

Per #5027, we're not planning on adding in any major changes. Feel free to write this as a set of functions that eventually call to Mocha APIs. Cheers!

Note that #1457 might make it easier to do that.

@JoshuaKGoldberg JoshuaKGoldberg closed this as not planned Won't fix, can't repro, duplicate, stale Dec 28, 2023
@JoshuaKGoldberg JoshuaKGoldberg added the status: wontfix typically a feature which won't be added, or a "bug" which is actually intended behavior label Dec 28, 2023
@JoshuaKGoldberg JoshuaKGoldberg changed the title Parallel tests inside suite (was: in addition to it, will) 馃殌 Feature: Parallel tests inside suite (was: in addition to it, will) Dec 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: wontfix typically a feature which won't be added, or a "bug" which is actually intended behavior type: feature enhancement proposal
Projects
None yet
Development

No branches or pull requests

2 participants