-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[BUG] rimraf causes failure with multiple browsers on Windows #808
Comments
I am happy to submit a PR if you are willing to accept replacing rimraf with fs-extra. |
@jperl If I understand correctly, fs-extra simply includes rimraf: So I wonder how is this fixing the problem. I can reproduce this easily on win - interestingly, it only happens under jest environment, and never otherwise. The assert that fires is very peculiar too. Let me see what's going on! |
@jperl so https://github.com/isaacs/rimraf/blob/d709272f6122b008de66650616fda34c8ae6f954/rimraf.js#L168 The assert fails because it looks like jest is messing up with fs errors somehow. I can repro this with the following jest test: test('whoa', () => {
try {
require('fs').rmdirSync(__dirname);
} catch (e) {
console.log('caught error instanceof Error: ', e instanceof Error);;
}
}); Running This is somewhat surprising since jest explicitly states that they don't mock core node modules. Let me dig further. |
@aslushnikov Thank you for investigating this 🙏. I admittedly did not check that |
Ok, we now know what's going on! Investigation
A reduced repro of this behavior looks like this: const vm = require('vm');
const jsdom = require('jsdom');
const env = new jsdom.JSDOM('<!DOCTYPE html>', {
runScripts: 'dangerously',
});
vm.createContext(env.window);
const testcode = `
((console) => {
try {
non_existent_variable_that_throws_not_defined_error;
} catch (e) {
console.log(e);
console.log('caught error instanceof Error: ', e instanceof Error);;
}
})
`;
vm.runInContext(testcode, env.window)(console); Reproduction without JSDOMconst vm = require('vm');
const context = { Error, console };
vm.createContext(context);
const testcode = `
try {
non_existent_variable_that_throws_not_defined_error;
} catch (e) {
console.log(e);
console.log('caught error instanceof Error: ', e instanceof Error);;
}
`;
vm.runInContext(testcode, context); This code prints "false" because:
Now, rimraf is doing an instanceof check for some of the errors it's getting from FS module: https://github.com/isaacs/rimraf/blob/d709272f6122b008de66650616fda34c8ae6f954/rimraf.js#L168 This check fails and yields this error. MitigationUnfortunately, configuring jest to run in a Short-term, we should try fixing this upstream in rimraf - instead of Long-term, I wonder if there's something Jest can do better on their side to avoid this cross-vm type passing. |
I'm impressed at how quickly you got to the root of this complex issue. Would you like me to submit the PR for rimraf? |
@jperl I'm on it, thanks! 👷♂️ |
Once/if isaacs/rimraf#209 is merged and a new version is released, we can roll the dependency. It'll fix this bug. We'll probably wait for a week to see if we can land the fix to rimraf. If there's a delay, we can detect jest environment and provide const isJestEnvironment = (function() {
try {
some_undefined_variable_goes_here;
} catch (e) {
return !(e instanceof Error);
}
})(); |
Context:
Might relate to #680
Code Snippet
Run
npx jest
Describe the bug
The second test throws this error.
Others have seen this same issue with rimraf on windows.
jestjs/jest#3942 (comment)
GoogleChrome/lighthouse#2641
I tried to force the playwright-core resolution to rimraf 3.0.1 but I ran into the same issue.
Is there a way to remove the rimraf dependency and replace it with fs-extra, that seems to be an approach that worked here. getgauge/taiko#837
The text was updated successfully, but these errors were encountered: