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

Refactor lib/__tests__/standalone-cache.test.js #5311

Merged
merged 2 commits into from May 17, 2021

Conversation

ybiquitous
Copy link
Member

@ybiquitous ybiquitous commented May 17, 2021

Which issue, if any, is this issue related to?

Fix #5309
A part of #4881

Is there anything in the PR that needs further explanation?

This PR's base branch is v14.

- Reduce redundant callbacks via `async/await` syntax. (#4881)
- Use `fs.existsSync()` instead of `fs.access()`.
  See <https://nodejs.org/api/fs.html#fs_fs_existssync_path>
- Fix the disabled test. (#5309)
- Inline redundant local variables.
- Make expectations using `typeof` more accurate.
@ybiquitous ybiquitous linked an issue May 17, 2021 that may be closed by this pull request
fs.access(filePath, fsConstants.F_OK).then(
() => true,
() => false,
);
Copy link
Member Author

Choose a reason for hiding this comment

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

[note] I think it simple and enough to use fs.existsSync() for tests.

});
// Ensure cache file contains only linted css file
expect(typeof cache.getKey(validFile)).toBe('object');
expect(cache.getKey(validFile)).toBeTruthy();
Copy link
Member Author

Choose a reason for hiding this comment

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

[note] I've added the expectation .toBeTruthy() because of typeof null === 'object'. But it may be a bit ugly and is not DRY. 🤔


it("cache doesn't do anything if string is passed", async () => {
// Ensure no cache file
await removeFile(expectedCacheFilePath);
Copy link
Member Author

Choose a reason for hiding this comment

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

[note] This addition of removeFile() fixes #5309.

@ybiquitous ybiquitous marked this pull request as ready for review May 17, 2021 06:43
Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

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

Great, thanks!

@jeddy3 jeddy3 merged commit 2345a21 into v14 May 17, 2021
@jeddy3 jeddy3 deleted the refactor-standalone-cache.test.js branch May 17, 2021 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Fix cache
2 participants