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

Cached file is empty using NodeFs store. #3

Closed
nocodehummel opened this issue Apr 18, 2024 · 3 comments
Closed

Cached file is empty using NodeFs store. #3

nocodehummel opened this issue Apr 18, 2024 · 3 comments
Labels

Comments

@nocodehummel
Copy link
Contributor

nocodehummel commented Apr 18, 2024

The cached file is empty using NodeFs store. The filename is incomplete with myurll[headers.

The below function does not render a valid filename.

async idFromResponse(request: Request): Promise<string> {
  let filename = filenamifyUrl(request.url);
  if (Array.from(request.headers.keys()).length > 0) {
    const headersHash = await this.hashFromHeaders(request.headers, 7);
    filename += `[headers:${headersHash}]`;
  }
  return filename + ".json";
}

A solution would be to only render the filename with filenamifyUrl and let the calling code add query string to make cached files unique for specific test cases. That approach would also allow for meaningful filenames.

@nocodehummel
Copy link
Contributor Author

A minor code change fixes the problem with the filename.

filename += `[headers:${headersHash}]`;

filename += `[headers=${headersHash}]`;

nocodehummel added a commit to nocodehummel/jest-fetch-mock-cache that referenced this issue Apr 18, 2024
@gadicc
Copy link
Owner

gadicc commented Apr 19, 2024

Great find & fix, thanks, I may have made some assumptions about being on Linux 😅

@gadicc gadicc closed this as completed in d047caf Apr 19, 2024
Copy link

🎉 This issue has been resolved in version 1.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants