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

Fix Windows compatibility #78

Merged
merged 1 commit into from
Sep 2, 2020
Merged

Conversation

brandon93s
Copy link
Contributor

Resolves #64

const error = await t.throwsAsync(cpy('license', t.context.EPERM), /EPERM/);
t.true(error instanceof CpyError);
const cpy = cpyMockedError('cp-file');
await t.throwsAsync(cpy('license', t.context.dir), {message: /cp-file/, instanceOf: CpyError});
});

Copy link
Contributor Author

@brandon93s brandon93s Sep 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are checking for proper handling of exceptions thrown by dependencies. Previously, the test were implemented with the contrived scenario of a no-access directory which would force these modules to fail: fs.mkdirSync(t.context.EPERM, 0); on *nix systems. This has been replaced with mocking of the dependencies to fail immediately. With this, the additional cp-file + glob test also becomes redundant.

While a similarly contrived example could have been created for Windows ( e.g. writing to a known folder ) successful test execution would have been dependent on the environment the test was run in and whether the shell had elevated privileges.

return path.join(destination, dirname, basename);
const dirname = path.dirname(source);
const parsedDirectory = path.parse(dirname);
return path.join(destination, dirname.replace(parsedDirectory.root, path.sep), basename);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

destination and dirname can both be absolute paths. When this occurs you end up with the following:

# MacOS & Linux
/tmp/example + /tmp/example/cwd => /tmp/example/tmp/example/cwd

# Windows
C:\\tmp\\example + C:\\tmp\\example\\cwd => C:\\tmp\\example\\C:\\tmp\\example\\cwd

The resulting Windows path is invalid. This strips the root ( C:\\ ) from the directory path before joining by replacing it with the path seperator. This will be a NOOP on non-Windows.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Would you be able to add a test for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is covered by the 'path structure' test which was failing prior to this fix.

@sindresorhus sindresorhus changed the title Windows compatibility Fix Windows compatibility Sep 2, 2020
@sindresorhus sindresorhus merged commit fdcae2f into sindresorhus:master Sep 2, 2020
@sindresorhus
Copy link
Owner

Thanks for fixing this :)

@brandon93s brandon93s deleted the windows branch September 3, 2020 16:58
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

Successfully merging this pull request may close these issues.

Fix tests on Windows
2 participants