Avoid test collisions by using different directories in runInTempDirectory#902
Avoid test collisions by using different directories in runInTempDirectory#902adamwathan merged 2 commits intotailwindlabs:nextfrom
Conversation
|
This has been driving me mental for months because it's so sporadic, thanks for taking the time to dig in to it. Looking at your implementation made me wonder, "does Jest provide a unique ID for each process?" and it turns out it does! I think the timestamp solution is probably robust enough but I wonder if using this ID would be a better idea? |
|
Nice find! There isn't much difference, but I like the use of |
|
I'm gonna be so happy if I never see that stupid false test failure ever again 😅 Thanks so much! |
|
Goddammit it's still happening for me. I wish I could come up with a bullet proof way to reproduce but it basically just happens around 50% of the time I run the full test suite after making any code change 😫 The weird thing is that the symptom I actually see is that a This test some writes the file to the wrong directory sometimes: test('tailwind.config.js is picked up by default', () => {
return inTempDirectory(() => {
fs.writeFileSync(
path.resolve(defaultConfigFile),
`module.exports = {
theme: {
screens: {
mobile: '400px',
},
},
}`
)
return postcss([tailwind])
.process(
`
@responsive {
.foo {
color: blue;
}
}
`,
{ from: undefined }
)
.then(result => {
expect(result.css).toMatchCss(`
.foo {
color: blue;
}
@media (min-width: 400px) {
.mobile\\:foo {
color: blue;
}
}
`)
})
})
})All this parallel test worker shit is really unfriendly to any sort of integration testing :/ |
|
We could always run tests sequentially: // package.json
- "test": "jest && eslint ."
+ "test": "jest --runInBand && eslint ."There doesn't seem to be much difference duration wise: Though it would be nice to find an actual solution to these problems. But it's difficult to debug it further for me, since I don't have failures anymore. 😃 |
The tests were randomly failing for me:
I believe it's a timing issue with the tests being run in parallel.
This PR fixes that by using a different temporary directory for each test.