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

Add getTemplateData caching test #991

Merged
merged 1 commit into from
Mar 5, 2020
Merged

Conversation

samuelpath
Copy link
Contributor

@samuelpath samuelpath commented Mar 3, 2020

In PR #967, I tried to refactor the getTemplateData function in EleventyFiles.js by replacing the if and return by a ternary operator.

My refactor broke the caching but all the tests passed nonetheless.

On closing the PR, @zachleat said:

Would be very interested in a PR that adds a test around this!

So here is the PR that adds a test around this.

What it does is simply call the getTemplateData function twice in a row and compares the return values.

Since the getTemplateData function returns an object, we can compare the object reference by using the is test.

I've been successfully able to break my test by removing the caching mechanism. In that case, the test result says:

Values are deeply equal to each other, but they are not the same

image

Which is what we would expect without caching.

@zachleat zachleat merged commit 7a27dc5 into 11ty:master Mar 5, 2020
@zachleat zachleat added this to the Eleventy v0.11.0 milestone Mar 5, 2020
@zachleat
Copy link
Member

zachleat commented Mar 5, 2020

Thank you!!

@samuelpath samuelpath deleted the patch-4 branch March 6, 2020 12:12
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.

2 participants