-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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: do not write fixture in test-require-symlink #15067
Conversation
|
||
// Copy fixturesSrouce to linkTarget recursively. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: fixtureSource
if (err || !o.includes('SeCreateSymbolicLinkPrivilege')) | ||
common.skip('insufficient privileges'); | ||
const linkTarget = path.join(common.tmpDir, | ||
'module-require-symlink', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be dirName
or tmpDirTarget
.
test(); | ||
} | ||
const linkDir = path.join(common.tmpDir, | ||
'module-require-symlink', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be dirName
or tmpDirTarget
.
fs.unlinkSync(linkDir); | ||
}); | ||
const linkScriptTarget = path.join(common.tmpDir, | ||
'module-require-symlink', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be dirName
or tmpDirTarget
.
const linkTarget = fixtures.path('module-require-symlink', | ||
'node_modules', | ||
'dep2'); | ||
function copyDir(source, target) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't you rather execSync('cp -Rf Src Trg')
/ for windows execSync('xcopy /E /Y Src Trg')
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer the more verbose way here because:
- there's no difference between Windows and POSIX test code that way
- it does not depend on even the most mundane external dependency.
execSync
always feels like a code smell to me, although it's almost certainly not going to cause problems here.
I admit my reasons are not super-compelling but I'm also not sure the counter-arguments are super-compelling either. I'll certainly change it if this is a blocking objection. :-)
if (common.isWindows) { | ||
// On Windows, creating symlinks requires admin privileges. | ||
// We'll only try to run symlink test if we have enough privileges. | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too thrilled about this (I know it was like this before). I rather have an emperical test:
const symLinkTest = path.join(common.tmpDir, 'symLinkTest .js');
try {
fs.symlinkSync(__filename, symLinkTest);
} catch (e) {
assert.strictEqual(e.code, 'EPERM');
common.skip('insufficient privileges');
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, done! (I changed the assert to an if ... throw
.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be tested upfront as opposed to wrapping the actual symlink calls in the test in a try-catch block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm...maybe even better: It looks like there's a common.canCreateSymlink()
used in two files. I can use it here.
fea8367
to
b49c223
Compare
if (stats.isDirectory()) { | ||
copyDir(fullPathSource, fullPathTarget); | ||
} else { | ||
fs.writeFileSync(fullPathTarget, fs.readFileSync(fullPathSource)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can now be fs.copyFileSync()
.
Ping @Trott |
4383a34
to
3f1c2de
Compare
if (common.isWindows) { | ||
// On Windows, creating symlinks requires admin privileges. | ||
// We'll only try to run symlink test if we have enough privileges. | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be tested upfront as opposed to wrapping the actual symlink calls in the test in a try-catch block?
6443815
to
59f37e4
Compare
@refack Is this OK by you as is, or do you object? If you want changes, can you clarify what changes you'd like to see? |
|
New CI (so this could land as soon as): https://ci.nodejs.org/job/node-test-pull-request/10092/ |
This failed CI across the board:
|
Hmmm...passing for me locally. But obviously not in CI.... will take a look... |
Odd. When I log in to a CI machine where it's failing and run the test from the CLI there, it works fine. |
|
@refack Tried both |
I added some logging of the error in CI and it seems like
|
Ah! Looks like symlinking with a full path messes things up because of a symlink higher up in the path. The tmp directories in test are symlinked to I'll fix the test to use relative paths for symlinking all within the tmp dir. |
OK, hopefully that fixes it... |
Cleaned up the test but missed cleaning up the fixture which still refers to the full path of the tmp directory... |
test-require-symlink modifies the fixture directory by adding a symlink. Copy the fixture to the test tmpdir instead of modifying the fixture directory. This also uses a more empirical test for checking for the ability to make symlinks on Windows.
OK, results look much better that time, but a few infra-related issues, some of which are now fixed, so one more time... |
@Trott the CI seems fine (the linter is failing often... I do not know why but maybe a eslint update might help - or does someone know where the errors might come from?). Is this ready to land? |
test-require-symlink modifies the fixture directory by adding a symlink. Copy the fixture to the test tmpdir instead of modifying the fixture directory. This also uses a more empirical test for checking for the ability to make symlinks on Windows. PR-URL: nodejs#15067 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Landed in 6f34076 |
test-require-symlink modifies the fixture directory by adding a symlink. Copy the fixture to the test tmpdir instead of modifying the fixture directory. This also uses a more empirical test for checking for the ability to make symlinks on Windows. PR-URL: #15067 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
test-require-symlink modifies the fixture directory by adding a symlink. Copy the fixture to the test tmpdir instead of modifying the fixture directory. This also uses a more empirical test for checking for the ability to make symlinks on Windows. PR-URL: nodejs/node#15067 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
test-require-symlink modifies the fixture directory by adding a symlink. Copy the fixture to the test tmpdir instead of modifying the fixture directory. This also uses a more empirical test for checking for the ability to make symlinks on Windows. PR-URL: nodejs/node#15067 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This does not land cleanly in LTS. Please feel free to manually backport by following the guide. Please also feel free to replace do-not-land if it is being backported |
test-require-symlink modifies the fixture directory by adding a symlink.
Copy the fixture to the test tmpdir instead of modifying the fixture
directory.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
test module