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

Test/browser env #94

Merged
merged 7 commits into from
Nov 16, 2022
Merged

Test/browser env #94

merged 7 commits into from
Nov 16, 2022

Conversation

cjpillsbury
Copy link
Contributor

This PR updates upchunk tests to run in a browser. To stay consistent with other projects (e.g. Open Elements, Media Chrome we've migrated to using web-test-runner. This also required some updates to tests and test dependencies that were either explicitly designed for node (nock vs. xhr-mock as a replacement) and dependencies that implicitly assumed node without an appropriate build step (e.g. xhr, which only has a published package using cjs modules).

A few callouts:

  • The primary motivation for this PR is based on the ongoing effort to migrate upchunk to use ReadableStreams for memory optimization purposes, since this is unavailable (with Files) for node.
  • There is one test that is currently commented out, due to some apparent assumptions in how progress events can be triggered when using xhr-mock (mentioned in code comment for further details).
  • To make one test permutation easier, a read only getter for paused was added to upchunk. This feels like a low risk refactor that is also plausibly useful for non-testing cases.
  • The rebuild of the ESM-equivalent modules (xhr & xhr-mock) for compatibility in the new test env currently happens before each run of test. Since these dependencies should never change, they plausibly only need to be built once after a (local/dev) install. Since the build of these modules is very fast, solving this felt like a lower priority.

// expect(isNumberArraySorted(progressPercentageArray)).toBeTruthy();
// done();
// });
// }, 10000);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not feeling good about losing this test.

tbh I think we should figure out how to keep it before this gets merged

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dylanjha cool I think that's reasonable. I'll do some additional investigation. Hopefully it doesn't entail another replacement for nock.

@gkatsev
Copy link

gkatsev commented Nov 14, 2022

An alternative to building xhr/xhr-mock each time is to check in vendored files for the tests and then have a script we can use to update them. xhr-mock was last updated in 2019 and xhr was last updated in 2020, so, incredibly unlikely they'll change.

…R eval easier (DO NOT MERGE WITHOUT REVERTING).
export default {
nodeResolve: true,
files: ['test/**/*.spec.js', 'test/**/*.spec.ts'],
// files: ['src/**/*.spec.js'],
Copy link

Choose a reason for hiding this comment

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

nit: can be removed

@@ -1,333 +1,322 @@
import * as nock from 'nock';

import { expect } from '@open-wc/testing';
Copy link

Choose a reason for hiding this comment

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

you're using expect to match what was here as closely as possible, right?

Copy link
Contributor Author

@cjpillsbury cjpillsbury Nov 14, 2022

Choose a reason for hiding this comment

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

yessir, jest uses bdd/expect by default (much more obvious in other test module diff).

scopes.forEach((scope) => {
if (!scope.isDone()) {
done('All scopes not completed');
/** @TODO Figure out how to best handle progress testing. See: https://www.npmjs.com/package/xhr-mock#upload-progress (CJP) */
Copy link

Choose a reason for hiding this comment

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

unfortunately, xhr-mock's progress events may not be fully-fleshed out enough for our needs here. jameslnewell/xhr-mock#82

An alternative is https://github.com/berniegp/mock-xmlhttprequest/#simulating-progress

const fileBytes = 1048576;
const upload = createUploadFixture(
{
headers: {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's the at least slightly dirty way of getting progress events working for xhr-mock in the same conditions as the previous test implementation using nock.


const scopes = [
nock('https://example.com')
.matchHeader('content-range', `bytes 0-${fileBytes / 4 - 1}/${fileBytes}`)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NOTE: I dropped these assertions/expectations from this particular test, since they weren't descriptive of what was being tested here and are already tested in a separate test specifically for these assertions/expectations (See test described as "a file is uploaded using the correct content-range headers")

Copy link

@gkatsev gkatsev left a comment

Choose a reason for hiding this comment

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

Approving, don't forget the test/web-test-runner.config.mjs changes.

@cjpillsbury cjpillsbury merged commit 1810751 into muxinc:master Nov 16, 2022
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.

3 participants