-
Notifications
You must be signed in to change notification settings - Fork 921
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
Build Test feedback #1861
Build Test feedback #1861
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/pikapkg/snowpack/nscc3bhq9 |
79f483f
to
6cbb132
Compare
6cbb132
to
447b170
Compare
beforeAll(() => { | ||
setupBuildTest(__dirname); | ||
beforeAll(async () => { | ||
await setupBuildTest(__dirname); |
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.
setupBuildTest()
is now async…
|
||
files = readFiles(['index.html'], {cwd}); | ||
files = await readFiles(cwd); |
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.
…as is readFiles()
(and it was changed to take an entire directory, and read UTF-8-friendly files)
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.
Unfortunately, I had to revert the “async” setup. Though it was working locally, it was consistently failing in CI.
I fought with it for a couple hours, trying to figure out what the issue is. I never got to the bottom of it, but I suspect async weirdness in Jest. Reason is that beforeAll(async()
was never originally supported; you’ll see older issues demanding this feature. Then when it was added, I’m seeing very weird behavior that I can’t really explain other than guessing that beforeAll(async()
doesn’t use proper Node.js promises and tries to use some weird implementation that works Most Of The Time™ but was failing for us. I can’t explain otherwise why it just would never truly wait for async functions to finish (I tried everything I could think of 😅)
But that said, I don’t think that having synchronous setup functions is necessarily slower. Jest spawns each individual test in its own child process on its own thread, so already this work is being parallelized. If my suspicions are correct, then I think the sync processes here are happening within the context of a child process, so it’s already optimized.
But also, I’m scared with this much difficulty of me or someone else fighting with beforeAll(async()
weirdness, so I’d rather just avoid it.
/** strip whitespace */ | ||
function stripWS(code) { | ||
return code.replace(STRIP_WHITESPACE, ''); | ||
} |
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.
Old utils from test/build/build.test.js
were added here (these were the only functions, but if we need any other inline logic we could always add that here too, as we need it)
test/test-utils.js
Outdated
function readFiles(files, {cwd}) { | ||
if (!cwd) throw new Error(`cwd option missing, ex: readFiles(files, { cwd: __dirname })`); | ||
/** take a folder of files, return contents of files (won’t read entire directory for performance) */ | ||
async function readFiles(directory, {ignore} = {}) { |
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.
As stated above, this now just reads all UTF-8-friendly files in a directory. But if you have a test file where a particular file is too large, you can always ignore
it from glob()
.
In other words, this assumes test directories are tiny by default and assume it’s OK to read the entire build directory (we were doing that anyway in build.test.js
before), but if that assumption isn’t correct you can always ignore individual files from being read into memory (which it should be noted that nothing currently broke build.test.js
which was doing this).
447b170
to
03291cf
Compare
03291cf
to
d40f0fd
Compare
d40f0fd
to
ceec16f
Compare
ceec16f
to
76170fd
Compare
76170fd
to
84b3360
Compare
84b3360
to
8fe2b0e
Compare
8fe2b0e
to
1b77ae7
Compare
1b77ae7
to
c462b61
Compare
c462b61
to
0793ee6
Compare
0793ee6
to
39b8c40
Compare
39b8c40
to
a15baa9
Compare
a15baa9
to
ad9446d
Compare
ad9446d
to
0d260f1
Compare
0d260f1
to
6f6bdbd
Compare
6f6bdbd
to
b8031bf
Compare
b8031bf
to
38791cc
Compare
38791cc
to
0559902
Compare
0559902
to
2cba4c6
Compare
2cba4c6
to
4e03262
Compare
4e03262
to
0671b80
Compare
@@ -7381,7 +7381,7 @@ exports[`create-snowpack-app app-template-minimal > build: package.json 1`] = ` | |||
\\"test\\": \\"echo \\\\\\"This template does not include a test runner by default.\\\\\\" && exit 1\\" | |||
}, | |||
\\"devDependencies\\": { | |||
\\"snowpack\\": \\"^2.18.1\\" |
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.
whoops forgot to regenerate these after publishing a couple of minutes ago, just updated snapshots on main to fix this.
0671b80
to
cd94242
Compare
cd94242
to
bda08af
Compare
man, jest is terrible. Thanks for digging into that, lets hold off for now and revisit in the future. Maybe a good chance to try out uvu |
Changes
Followup to comments in #1828. Broken out into a separate PR post-merge to limit disruption in making test suite changes.
Testing
Tests should pass
Docs
No documentation; all testing changes