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

Build Test feedback #1861

Merged
merged 1 commit into from
Dec 8, 2020
Merged

Build Test feedback #1861

merged 1 commit into from
Dec 8, 2020

Conversation

drwpow
Copy link
Collaborator

@drwpow drwpow commented Dec 7, 2020

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

@vercel
Copy link

vercel bot commented Dec 7, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pikapkg/snowpack/nscc3bhq9
✅ Preview: https://snowpack-git-drwpow-test-feedback.pikapkg.vercel.app

beforeAll(() => {
setupBuildTest(__dirname);
beforeAll(async () => {
await setupBuildTest(__dirname);
Copy link
Collaborator Author

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);
Copy link
Collaborator Author

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)

Copy link
Collaborator Author

@drwpow drwpow Dec 8, 2020

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, '');
}
Copy link
Collaborator Author

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)

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} = {}) {
Copy link
Collaborator Author

@drwpow drwpow Dec 7, 2020

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).

@@ -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\\"
Copy link
Owner

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.

@FredKSchott
Copy link
Owner

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

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