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

test.concurrent() issue? #49

Open
nutchanon-c opened this issue Mar 16, 2023 · 2 comments
Open

test.concurrent() issue? #49

nutchanon-c opened this issue Mar 16, 2023 · 2 comments

Comments

@nutchanon-c
Copy link

In one test file, I have a few describe() and a few test.concurrent() under each describe. In each test.concurrent(), I have it save to different snapshot files.

For example, for 10 total test, there will be 10 snapshot files.

However, I see that the snapshots are being saved to incorrect files with also incorrect names despite passing in the hint as well (they get mixed up with the test names).

Are there any workarounds to this issue?

@igor-dv
Copy link
Owner

igor-dv commented Mar 21, 2023

I never tested it with concurrency, so I may assume there is some race condition there. The workaround depends on the reason you need a concurrency, you can do it from outside rather with using jest.

Would you like to provide a reproduction of the problem ? Either adding a test here , or creating a project that reproduces it ? If I will have a bit of time I can take a look if it's solvable.

@nutchanon-c
Copy link
Author

I can't seem to really reproduce it in my own personal project. However, it happens with some internal tests that I probably could not share the code here but the structure is something like this. The actual project is written with TypeScript.

The actual tests between expecting toMatchSpecificSnapshot() includes multiple get/post requests and a test usually takes around 20 seconds or so to complete.

The snapshot files are created correctly, but it would jump around from file to file with incorrect snapshot name (describe + it/test name + hint). The faulty behavior is the same is if you're running tests concurrently with toMatchSnapshot().

describe("test", () => {
  it.concurrent("test 1", async () => {
    // sending http requests and getting the result
    expect(2).toMatchSpecificSnapshot("./snapshots/one.snp", "test1");
  });
  it.concurrent("test 2", async () => {
    // sending http requests and getting the result
    expect({ foo: 2, bar: 3 }).toMatchSpecificSnapshot(
      "./snapshots/two.snp",
      { foo: expect.any(Number) },
      "test2"
    );
  });
  it.concurrent("test 3", async () => {
    // sending http requests and getting the result
    expect({ baz: 3 }).toMatchSpecificSnapshot(
      "./snapshots/three.snp",
      { baz: expect.any(Number) },
      "test3"
    );
  });
});

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

No branches or pull requests

2 participants