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

Proposal: Vendor whatwg-fetch #293

Closed
samselikoff opened this issue Feb 13, 2020 · 12 comments
Closed

Proposal: Vendor whatwg-fetch #293

samselikoff opened this issue Feb 13, 2020 · 12 comments

Comments

@samselikoff
Copy link
Contributor

Pretender uses the whatwg-fetch package in order to intercept fetch calls.

Even though whatwg-fetch is explicitly imported here (and used here), Pretender is actually relying implicitly on whatwg-fetch's internals to get the fetch intercepting behavior working correctly.

The reason is because the fetch implementation that whatwg-fetch provides actually delegates to window.XMLHTTPRequest under the hood. Since Pretender also monkey patches window.XMLHTTPRequest, it is able to intercept fetch calls equally as well. But it's only due to those internals – due to the fact that the whatwg-fetch polyfill happens to use XMLHTTPRequest under the hood. This is not part of whatwg-fetch's public API, even though it is unlikely the change.

The reason this bit us recently is because some folks are trying to use Mirage with Next.js. Next performs some build-time optimizations to ensure apps don't include multiple or heavy versions of popular polyfills, whatwg-fetch being one of them. So, they actually swap out the package that whatwg-fetch resolves to, meaning when Pretender tries to import * from 'whatwg-fetch', it ends up with a different polyfill entirely, and one that does not happen to use XMLHTTPRequest under the hood. Therefore, Pretender (and thus Mirage) don't work.

We asked about how to opt-out of this optimizing behavior here, but as of right now the Zeit team doesn't have any plans to make the behavior configurable.

In any case, regardless of whether Next.js chooses to expose such an option, it is still true that today, Pretender is relying on internals of whatwg-fetch, and that poses a risk to Pretender in the event those internals ever change.

I'm proposing that we vendor the latest version of whatwg-fetch into Pretender directly, since we are relying on observable but undocumented behavior of its current implementation. This would give us total control over the code, and would also address the Next.js issue since whatwg-fetch would no longer be an external dependency that could be hoisted or replaced.

@stefanpenner
Copy link
Contributor

It's likely ok to bundle whatwg-fetch as part of a dev time build step and presenting them as one bundle to consumers.

But I am not super enthusiastic about actually copying whatwg-fetch code & tests into this repo. It seems like keeping it simple to upgrade if we want to is important, and having the code copied seems like a hazard.

I can be convinced, these are only my first thoughts.

@samselikoff
Copy link
Contributor Author

Ya. I think we would just copy this file: https://github.com/github/fetch/blob/master/fetch.js. So 500 lines of code. The last release of whatwg-fetch was 1 year ago.

If there were updates to whatwg-fetch, it's true we wouldn't know about them (at least right away). But again we should compare that to the current situation, in which we're relying on internals, which means whatwg-fetch could push out a patch version that refactors away from their reliance on XMLHTTPRequest and that would break Pretender. Is that likely to happen? Not sure. There are other newer polyfills of fetch that don't use XMLHTTPRequest, so maybe. In any case I do think it's strange for us to be relying on the internals of an external dependency.

I don't think we'd need whatwg-fetch's tests, I think our tests cover Pretender's public API and that's sufficient.

An alternative would be to update Pretender's code to "properly" support intercepting fetch, i.e. actually proxy the fetch APIs to Pretender's. But that would effectively involve bringing in a fetch implementation, and pointing it to our APIs, which effectively would boil down to something that looks a lot like bringing in whatwg-fetch and using it as the boundary layer to redirect fetch APIs to our own.

So ultimately I think vendoring whatwg-fetch is a lot like adding a "proper" fetch adapter to Pretender.

@xg-wang
Copy link
Member

xg-wang commented Feb 14, 2020

I haven't digged into how next.js resolves import * from 'whatwg-fetch', I would +1 to Stef's suggestion to do this at build time and make sure the scoped xhr is used.
Not sure about proxying fetch. It seems like building another polyfill, which whatwg-fetch already did the work.

@samselikoff
Copy link
Contributor Author

Ohh I see – I don't think I fully understood.

Are you all saying we could keep whatwg-fetch as a dependency here in package.json, but for Pretender's publishing step, go ahead and pull it in + make it into an internal dependency? So there's no chance of it being overridden, hoisted or something else?

@samselikoff
Copy link
Contributor Author

Another point @ryanto raised is that, currently Pretender is not importable in node, due to whatwg-fetch assuming a browser-like environment. This is another headache for us because even though Mirage doesn't yet work in Node, it needs to be importable so it doesn't break setups like Gatsby that expect isomorphic app code.

This led us needing to create some polyfills and use them like this: https://github.com/miragejs/miragejs/blob/23fb9fe3278af513e1a95c8a09c669e4a47fcd45/lib/server.js#L3. This ensure our polyfill code runs before Pretender is imported (and thus before whatwg-fetch is imported). The code essentially just ensures self is defined, which is all whatwg-fetch needs to be importable (again, not functional, which is not what we're interested at this time).

So, if we were to copy the 500-line whatwg-fetch file directly into Pretender, we could also solve this issue and make sure Pretender doesn't break node apps if it's in the import path, by simply wrapping the code in an if global.self === 'undefined') block.

I understand the purist argument about leaving whatwg-fetch in package.json, but Pretender's build file + logic is already pretty messy + hard to read/maintain, and whatwg-fetch's last release was over a year ago, so I think pragmatically the simplest way to solve this problem today is to just create a new file in Pretender, copy the 500 lines, make a comment at the top of the file and be done with it. And I also think the risk is very low.

Just some more of my thoughts!

@stefanpenner
Copy link
Contributor

@samselikoff I don't have strong feelings either way, but am happy to support your calls here. They seem perfectly reasonable.

@samselikoff
Copy link
Contributor Author

Right, thanks man. If we do pull the trigger on this, it will be quite easy to undo if it causes any issues.

Thanks a lot Stef!

@GriffinSauce
Copy link

Really appreciate the effort here guys! 🙌

@samselikoff
Copy link
Contributor Author

Any trick to getting Pretender's test suite running locally? I started work on this but master is failing on my machine for a bunch of reasons...

yarn test
➜  pretender git:(vendor-whatwg-fetch) ✗ yarn test
yarn run v1.21.1
$ bower install
$ npm run lint && npm run eslint && npm run tests-only
npm WARN lifecycle The node binary used for scripts is /var/folders/v5/5bs4trnx5v7bly3f0cg4_sc40000gn/T/yarn--15824094412
85-0.3022276787043625/node but npm is using /Users/samselikoff/.nodenv/versions/12.16.0/bin/node itself. Use the `--scrip
ts-prepend-node-path` option to include the path for the node binary npm was executed with.

> [email protected] lint /Users/samselikoff/Projects/oss/pretender
> jshint test

npm WARN lifecycle The node binary used for scripts is /var/folders/v5/5bs4trnx5v7bly3f0cg4_sc40000gn/T/yarn--15824094412
85-0.3022276787043625/node but npm is using /Users/samselikoff/.nodenv/versions/12.16.0/bin/node itself. Use the `--scrip
ts-prepend-node-path` option to include the path for the node binary npm was executed with.

> [email protected] eslint /Users/samselikoff/Projects/oss/pretender
> eslint src/**/*.ts test

npm WARN lifecycle The node binary used for scripts is /var/folders/v5/5bs4trnx5v7bly3f0cg4_sc40000gn/T/yarn--15824094412
85-0.3022276787043625/node but npm is using /Users/samselikoff/.nodenv/versions/12.16.0/bin/node itself. Use the `--scrip
ts-prepend-node-path` option to include the path for the node binary npm was executed with.

> [email protected] tests-only /Users/samselikoff/Projects/oss/pretender
> karma start --single-run

22 02 2020 17:10:44.445:INFO [karma]: Karma v1.7.1 server started at http://0.0.0.0:9876/
22 02 2020 17:10:44.447:INFO [launcher]: Launching browsers Chrome, PhantomJS with unlimited concurrency
22 02 2020 17:10:44.451:INFO [launcher]: Starting browser Chrome
22 02 2020 17:10:44.457:INFO [launcher]: Starting browser PhantomJS
22 02 2020 17:10:45.453:INFO [Chrome 80.0.3987 (Mac OS X 10.15.3)]: Connected on socket VCT2Nx9PjwzfYoIfAAAA with id 2170
2188
22 02 2020 17:10:45.557:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket oRy3yOMfjOk2sBphAAAB with id 2755994
5
..........................................
Chrome 80.0.3987 (Mac OS X 10.15.3) pretender invoking async requests with `onprogress` upload events in the upload  trig
ger a progress event each 50ms FAILED
        ProgressEvent has total of requestBody byte size
        Expected: 9
        Actual: 300
            at EventedObject.xhr.upload.onprogress (test/calling_test.js:423:16)
            at EventedObject.<anonymous> (node_modules/fake-xml-http-request/fake_xml_http_request.js:137:18)
            at EventedObject.dispatchEvent (node_modules/fake-xml-http-request/fake_xml_http_request.js:181:24)
            at EventedObject._progress (node_modules/fake-xml-http-request/fake_xml_http_request.js:199:12)
            at dist/pretender.js:9:16177

        ProgressEvent has total of requestBody byte size
        Expected: 9
        Actual: 300
            at EventedObject.xhr.upload.onprogress (test/calling_test.js:423:16)
            at EventedObject.<anonymous> (node_modules/fake-xml-http-request/fake_xml_http_request.js:137:18)
            at EventedObject.dispatchEvent (node_modules/fake-xml-http-request/fake_xml_http_request.js:181:24)
            at EventedObject._progress (node_modules/fake-xml-http-request/fake_xml_http_request.js:199:12)
            at dist/pretender.js:9:16177

        ProgressEvent has total of requestBody byte size
        Expected: 9
        Actual: 300
            at EventedObject.xhr.upload.onprogress (test/calling_test.js:423:16)
            at EventedObject.<anonymous> (node_modules/fake-xml-http-request/fake_xml_http_request.js:137:18)
            at EventedObject.dispatchEvent (node_modules/fake-xml-http-request/fake_xml_http_request.js:181:24)
            at EventedObject._progress (node_modules/fake-xml-http-request/fake_xml_http_request.js:199:12)
            at dist/pretender.js:9:16177

        ProgressEvent has total of requestBody byte size
        Expected: 9
        Actual: 300
            at EventedObject.xhr.upload.onprogress (test/calling_test.js:423:16)
            at EventedObject.<anonymous> (node_modules/fake-xml-http-request/fake_xml_http_request.js:137:18)
            at EventedObject.dispatchEvent (node_modules/fake-xml-http-request/fake_xml_http_request.js:181:24)
            at EventedObject._progress (node_modules/fake-xml-http-request/fake_xml_http_request.js:199:12)
            at dist/pretender.js:9:16177

        ProgressEvent has total of requestBody byte size
        Expected: 9
        Actual: 300
            at EventedObject.xhr.upload.onprogress (test/calling_test.js:423:16)
            at EventedObject.<anonymous> (node_modules/fake-xml-http-request/fake_xml_http_request.js:137:18)
            at EventedObject.dispatchEvent (node_modules/fake-xml-http-request/fake_xml_http_request.js:181:24)
            at EventedObject._progress (node_modules/fake-xml-http-request/fake_xml_http_request.js:199:12)
            at dist/pretender.js:9:16177

Chrome 80.0.3987 (Mac OS X 10.15.3) pretender invoking `onprogress` upload events don't keep firing once the request has 
ended FAILED
        ProgressEvent has total of requestBody byte size
        Expected: 9
        Actual: 210
            at EventedObject.xhr.upload.onprogress (test/calling_test.js:460:14)
            at EventedObject.<anonymous> (node_modules/fake-xml-http-request/fake_xml_http_request.js:137:18)
            at EventedObject.dispatchEvent (node_modules/fake-xml-http-request/fake_xml_http_request.js:181:24)
            at EventedObject._progress (node_modules/fake-xml-http-request/fake_xml_http_request.js:199:12)
            at dist/pretender.js:9:16177
            at callTimer (node_modules/sinon/pkg/sinon.js:7096:20)

        ProgressEvent has total of requestBody byte size
        Expected: 9
        Actual: 210
            at EventedObject.xhr.upload.onprogress (test/calling_test.js:460:14)
            at EventedObject.<anonymous> (node_modules/fake-xml-http-request/fake_xml_http_request.js:137:18)
            at EventedObject.dispatchEvent (node_modules/fake-xml-http-request/fake_xml_http_request.js:181:24)
            at EventedObject._progress (node_modules/fake-xml-http-request/fake_xml_http_request.js:199:12)
            at dist/pretender.js:9:16177
            at callTimer (node_modules/sinon/pkg/sinon.js:7096:20)

        ProgressEvent has total of requestBody byte size
        Expected: 9
        Actual: 210
            at EventedObject.xhr.upload.onprogress (test/calling_test.js:460:14)
            at EventedObject.<anonymous> (node_modules/fake-xml-http-request/fake_xml_http_request.js:137:18)
            at EventedObject.dispatchEvent (node_modules/fake-xml-http-request/fake_xml_http_request.js:181:24)
            at EventedObject._progress (node_modules/fake-xml-http-request/fake_xml_http_request.js:199:12)
            at dist/pretender.js:9:16177
            at callTimer (node_modules/sinon/pkg/sinon.js:7096:20)

        ProgressEvent has total of requestBody byte size
        Expected: 9
        Actual: 210
            at EventedObject.xhr.upload.onprogress (test/calling_test.js:460:14)
            at EventedObject.<anonymous> (node_modules/fake-xml-http-request/fake_xml_http_request.js:137:18)
            at EventedObject.dispatchEvent (node_modules/fake-xml-http-request/fake_xml_http_request.js:181:24)
            at EventedObject._progress (node_modules/fake-xml-http-request/fake_xml_http_request.js:199:12)
            at dist/pretender.js:9:16177
            at callTimer (node_modules/sinon/pkg/sinon.js:7096:20)

Chrome 80.0.3987 (Mac OS X 10.15.3) pretender invoking no progress upload events are fired after the request is aborted FAILED
        ProgressEvent has total of requestBody byte size
        Expected: 8
        Actual: 210
            at EventedObject.xhr.upload.onprogress (test/calling_test.js:495:14)
            at EventedObject.<anonymous> (node_modules/fake-xml-http-request/fake_xml_http_request.js:137:18)
            at EventedObject.dispatchEvent (node_modules/fake-xml-http-request/fake_xml_http_request.js:181:24)
            at EventedObject._progress (node_modules/fake-xml-http-request/fake_xml_http_request.js:199:12)
            at dist/pretender.js:9:16177
            at callTimer (node_modules/sinon/pkg/sinon.js:7096:20)

PhantomJS 2.1.1 (Mac OS X 0.0.0) pretender invoking async requests with `onprogress` upload events in the upload  trigger a progress event each 50ms FAILED
        ProgressEvent has total of requestBody byte size
        Expected: 9
        Actual: 300
        onprogress@test/calling_test.js:423:21
        node_modules/fake-xml-http-request/fake_xml_http_request.js:137:22
        dispatchEvent@node_modules/fake-xml-http-request/fake_xml_http_request.js:181:28
        _progress@node_modules/fake-xml-http-request/fake_xml_http_request.js:199:25
        dist/pretender.js:9:18046

        ProgressEvent has total of requestBody byte size
        Expected: 9
        Actual: 300
        onprogress@test/calling_test.js:423:21
        node_modules/fake-xml-http-request/fake_xml_http_request.js:137:22
        dispatchEvent@node_modules/fake-xml-http-request/fake_xml_http_request.js:181:28
        _progress@node_modules/fake-xml-http-request/fake_xml_http_request.js:199:25
        dist/pretender.js:9:18046

        ProgressEvent has total of requestBody byte size
        Expected: 9
        Actual: 300
        onprogress@test/calling_test.js:423:21
        node_modules/fake-xml-http-request/fake_xml_http_request.js:137:22
        dispatchEvent@node_modules/fake-xml-http-request/fake_xml_http_request.js:181:28
        _progress@node_modules/fake-xml-http-request/fake_xml_http_request.js:199:25
        dist/pretender.js:9:18046

        ProgressEvent has total of requestBody byte size
        Expected: 9
        Actual: 300
        onprogress@test/calling_test.js:423:21
        node_modules/fake-xml-http-request/fake_xml_http_request.js:137:22
        dispatchEvent@node_modules/fake-xml-http-request/fake_xml_http_request.js:181:28
        _progress@node_modules/fake-xml-http-request/fake_xml_http_request.js:199:25
        dist/pretender.js:9:18046

        ProgressEvent has total of requestBody byte size
        Expected: 9
        Actual: 300
        onprogress@test/calling_test.js:423:21
        node_modules/fake-xml-http-request/fake_xml_http_request.js:137:22
        dispatchEvent@node_modules/fake-xml-http-request/fake_xml_http_request.js:181:28
        _progress@node_modules/fake-xml-http-request/fake_xml_http_request.js:199:25
        dist/pretender.js:9:18046

PhantomJS 2.1.1 (Mac OS X 0.0.0) pretender invoking `onprogress` upload events don't keep firing once the request has ended FAILED
        ProgressEvent has total of requestBody byte size
        Expected: 9
        Actual: 210
        onprogress@test/calling_test.js:460:19
        node_modules/fake-xml-http-request/fake_xml_http_request.js:137:22
        dispatchEvent@node_modules/fake-xml-http-request/fake_xml_http_request.js:181:28
        _progress@node_modules/fake-xml-http-request/fake_xml_http_request.js:199:25
        dist/pretender.js:9:18046
        callTimer@node_modules/sinon/pkg/sinon.js:7096:25
        tick@node_modules/sinon/pkg/sinon.js:7319:30
        test/calling_test.js:466:15
        runTest@node_modules/qunit/qunit/qunit.js:3041:34
        run@node_modules/qunit/qunit/qunit.js:3027:13
        node_modules/qunit/qunit/qunit.js:3258:15
        processTaskQueue@node_modules/qunit/qunit/qunit.js:2614:28
        node_modules/qunit/qunit/qunit.js:2618:24
        invokeCallback@node_modules/qunit/qunit/qunit.js:1699:25
        node_modules/qunit/qunit/qunit.js:1467:30
        flush@node_modules/qunit/qunit/qunit.js:1419:15

        ProgressEvent has total of requestBody byte size
        Expected: 9
        Actual: 210
        onprogress@test/calling_test.js:460:19
        node_modules/fake-xml-http-request/fake_xml_http_request.js:137:22
        dispatchEvent@node_modules/fake-xml-http-request/fake_xml_http_request.js:181:28
        _progress@node_modules/fake-xml-http-request/fake_xml_http_request.js:199:25
        dist/pretender.js:9:18046
        callTimer@node_modules/sinon/pkg/sinon.js:7096:25
        tick@node_modules/sinon/pkg/sinon.js:7319:30
        test/calling_test.js:466:15
        runTest@node_modules/qunit/qunit/qunit.js:3041:34
        run@node_modules/qunit/qunit/qunit.js:3027:13
        node_modules/qunit/qunit/qunit.js:3258:15
        processTaskQueue@node_modules/qunit/qunit/qunit.js:2614:28
        node_modules/qunit/qunit/qunit.js:2618:24
        invokeCallback@node_modules/qunit/qunit/qunit.js:1699:25
        node_modules/qunit/qunit/qunit.js:1467:30
        flush@node_modules/qunit/qunit/qunit.js:1419:15

        ProgressEvent has total of requestBody byte size
        Expected: 9
        Actual: 210
        onprogress@test/calling_test.js:460:19
        node_modules/fake-xml-http-request/fake_xml_http_request.js:137:22
        dispatchEvent@node_modules/fake-xml-http-request/fake_xml_http_request.js:181:28
        _progress@node_modules/fake-xml-http-request/fake_xml_http_request.js:199:25
        dist/pretender.js:9:18046
        callTimer@node_modules/sinon/pkg/sinon.js:7096:25
        tick@node_modules/sinon/pkg/sinon.js:7319:30
        test/calling_test.js:466:15
        runTest@node_modules/qunit/qunit/qunit.js:3041:34
        run@node_modules/qunit/qunit/qunit.js:3027:13
        node_modules/qunit/qunit/qunit.js:3258:15
        processTaskQueue@node_modules/qunit/qunit/qunit.js:2614:28
        node_modules/qunit/qunit/qunit.js:2618:24
        invokeCallback@node_modules/qunit/qunit/qunit.js:1699:25
        node_modules/qunit/qunit/qunit.js:1467:30
        flush@node_modules/qunit/qunit/qunit.js:1419:15

        ProgressEvent has total of requestBody byte size
        Expected: 9
        Actual: 210
        onprogress@test/calling_test.js:460:19
        node_modules/fake-xml-http-request/fake_xml_http_request.js:137:22
        dispatchEvent@node_modules/fake-xml-http-request/fake_xml_http_request.js:181:28
        _progress@node_modules/fake-xml-http-request/fake_xml_http_request.js:199:25
        dist/pretender.js:9:18046
        callTimer@node_modules/sinon/pkg/sinon.js:7096:25
        tick@node_modules/sinon/pkg/sinon.js:7319:30
        test/calling_test.js:466:15
        runTest@node_modules/qunit/qunit/qunit.js:3041:34
        run@node_modules/qunit/qunit/qunit.js:3027:13
        node_modules/qunit/qunit/qunit.js:3258:15
        processTaskQueue@node_modules/qunit/qunit/qunit.js:2614:28
        node_modules/qunit/qunit/qunit.js:2618:24
        invokeCallback@node_modules/qunit/qunit/qunit.js:1699:25
        node_modules/qunit/qunit/qunit.js:1467:30
        flush@node_modules/qunit/qunit/qunit.js:1419:15

PhantomJS 2.1.1 (Mac OS X 0.0.0) pretender invoking no progress upload events are fired after the request is aborted FAILED
        ProgressEvent has total of requestBody byte size
        Expected: 8
        Actual: 210
        onprogress@test/calling_test.js:495:19
        node_modules/fake-xml-http-request/fake_xml_http_request.js:137:22
        dispatchEvent@node_modules/fake-xml-http-request/fake_xml_http_request.js:181:28
        _progress@node_modules/fake-xml-http-request/fake_xml_http_request.js:199:25
        dist/pretender.js:9:18046
        callTimer@node_modules/sinon/pkg/sinon.js:7096:25
        tick@node_modules/sinon/pkg/sinon.js:7319:30
        test/calling_test.js:502:15
        runTest@node_modules/qunit/qunit/qunit.js:3041:34
        run@node_modules/qunit/qunit/qunit.js:3027:13
        node_modules/qunit/qunit/qunit.js:3258:15
        processTaskQueue@node_modules/qunit/qunit/qunit.js:2614:28
        node_modules/qunit/qunit/qunit.js:2618:24
        invokeCallback@node_modules/qunit/qunit/qunit.js:1699:25
        node_modules/qunit/qunit/qunit.js:1467:30
        flush@node_modules/qunit/qunit/qunit.js:1419:15

Chrome 80.0.3987 (Mac OS X 10.15.3) pretender invoking async requests with `onprogress` events trigger a progress event each 50ms FAILED
        GET request has no requestBody
        Expected: 0
        Actual: 300
            at FakeRequest.xhr.onprogress (test/calling_test.js:528:14)
            at FakeRequest.<anonymous> (node_modules/fake-xml-http-request/fake_xml_http_request.js:137:18)
            at FakeRequest.dispatchEvent (node_modules/fake-xml-http-request/fake_xml_http_request.js:181:24)
            at FakeRequest._progress (node_modules/fake-xml-http-request/fake_xml_http_request.js:199:12)
            at dist/pretender.js:9:16264

        Expected: 300
        Actual: 51
            at FakeRequest.xhr.onprogress (test/calling_test.js:529:14)
            at FakeRequest.<anonymous> (node_modules/fake-xml-http-request/fake_xml_http_request.js:137:18)
            at FakeRequest.dispatchEvent (node_modules/fake-xml-http-request/fake_xml_http_request.js:181:24)
            at FakeRequest._progress (node_modules/fake-xml-http-request/fake_xml_http_request.js:199:12)
            at dist/pretender.js:9:16264

        GET request has no requestBody
        Expected: 0
        Actual: 300
            at FakeRequest.xhr.onprogress (test/calling_test.js:528:14)
            at FakeRequest.<anonymous> (node_modules/fake-xml-http-request/fake_xml_http_request.js:137:18)
            at FakeRequest.dispatchEvent (node_modules/fake-xml-http-request/fake_xml_http_request.js:181:24)
            at FakeRequest._progress (node_modules/fake-xml-http-request/fake_xml_http_request.js:199:12)
            at dist/pretender.js:9:16264

        Expected: 300
        Actual: 103
            at FakeRequest.xhr.onprogress (test/calling_test.js:529:14)
            at FakeRequest.<anonymous> (node_modules/fake-xml-http-request/fake_xml_http_request.js:137:18)
            at FakeRequest.dispatchEvent (node_modules/fake-xml-http-request/fake_xml_http_request.js:181:24)
            at FakeRequest._progress (node_modules/fake-xml-http-request/fake_xml_http_request.js:199:12)
            at dist/pretender.js:9:16264

        GET request has no requestBody
        Expected: 0
        Actual: 300
            at FakeRequest.xhr.onprogress (test/calling_test.js:528:14)
            at FakeRequest.<anonymous> (node_modules/fake-xml-http-request/fake_xml_http_request.js:137:18)
            at FakeRequest.dispatchEvent (node_modules/fake-xml-http-request/fake_xml_http_request.js:181:24)
            at FakeRequest._progress (node_modules/fake-xml-http-request/fake_xml_http_request.js:199:12)
            at dist/pretender.js:9:16264

        Expected: 300
        Actual: 157
            at FakeRequest.xhr.onprogress (test/calling_test.js:529:14)
            at FakeRequest.<anonymous> (node_modules/fake-xml-http-request/fake_xml_http_request.js:137:18)
            at FakeRequest.dispatchEvent (node_modules/fake-xml-http-request/fake_xml_http_request.js:181:24)
            at FakeRequest._progress (node_modules/fake-xml-http-request/fake_xml_http_request.js:199:12)
            at dist/pretender.js:9:16264

        GET request has no requestBody
        Expected: 0
        Actual: 300
            at FakeRequest.xhr.onprogress (test/calling_test.js:528:14)
            at FakeRequest.<anonymous> (node_modules/fake-xml-http-request/fake_xml_http_request.js:137:18)
            at FakeRequest.dispatchEvent (node_modules/fake-xml-http-request/fake_xml_http_request.js:181:24)
            at FakeRequest._progress (node_modules/fake-xml-http-request/fake_xml_http_request.js:199:12)
            at dist/pretender.js:9:16264

        Expected: 300
        Actual: 209
            at FakeRequest.xhr.onprogress (test/calling_test.js:529:14)
            at FakeRequest.<anonymous> (node_modules/fake-xml-http-request/fake_xml_http_request.js:137:18)
            at FakeRequest.dispatchEvent (node_modules/fake-xml-http-request/fake_xml_http_request.js:181:24)
            at FakeRequest._progress (node_modules/fake-xml-http-request/fake_xml_http_request.js:199:12)
            at dist/pretender.js:9:16264

        GET request has no requestBody
        Expected: 0
        Actual: 300
            at FakeRequest.xhr.onprogress (test/calling_test.js:528:14)
            at FakeRequest.<anonymous> (node_modules/fake-xml-http-request/fake_xml_http_request.js:137:18)
            at FakeRequest.dispatchEvent (node_modules/fake-xml-http-request/fake_xml_http_request.js:181:24)
            at FakeRequest._progress (node_modules/fake-xml-http-request/fake_xml_http_request.js:199:12)
            at dist/pretender.js:9:16264

        Expected: 300
        Actual: 260
            at FakeRequest.xhr.onprogress (test/calling_test.js:529:14)
            at FakeRequest.<anonymous> (node_modules/fake-xml-http-request/fake_xml_http_request.js:137:18)
            at FakeRequest.dispatchEvent (node_modules/fake-xml-http-request/fake_xml_http_request.js:181:24)
            at FakeRequest._progress (node_modules/fake-xml-http-request/fake_xml_http_request.js:199:12)
            at dist/pretender.js:9:16264

.............22 02 2020 17:10:46.565:WARN [web-server]: 404: /some/path
.
PhantomJS 2.1.1 (Mac OS X 0.0.0) pretender invoking async requests with `onprogress` events trigger a progress event each 50ms FAILED
        GET request has no requestBody
        Expected: 0
        Actual: 300
        onprogress@test/calling_test.js:528:19
        node_modules/fake-xml-http-request/fake_xml_http_request.js:137:22
        dispatchEvent@node_modules/fake-xml-http-request/fake_xml_http_request.js:181:28
        _progress@node_modules/fake-xml-http-request/fake_xml_http_request.js:199:25
        dist/pretender.js:9:18133

        Expected: 300
        Actual: 52
        onprogress@test/calling_test.js:529:19
        node_modules/fake-xml-http-request/fake_xml_http_request.js:137:22
        dispatchEvent@node_modules/fake-xml-http-request/fake_xml_http_request.js:181:28
        _progress@node_modules/fake-xml-http-request/fake_xml_http_request.js:199:25
        dist/pretender.js:9:18133

        GET request has no requestBody
        Expected: 0
        Actual: 300
        onprogress@test/calling_test.js:528:19
        node_modules/fake-xml-http-request/fake_xml_http_request.js:137:22
        dispatchEvent@node_modules/fake-xml-http-request/fake_xml_http_request.js:181:28
        _progress@node_modules/fake-xml-http-request/fake_xml_http_request.js:199:25
        dist/pretender.js:9:18133

        Expected: 300
        Actual: 103
        onprogress@test/calling_test.js:529:19
        node_modules/fake-xml-http-request/fake_xml_http_request.js:137:22
        dispatchEvent@node_modules/fake-xml-http-request/fake_xml_http_request.js:181:28
        _progress@node_modules/fake-xml-http-request/fake_xml_http_request.js:199:25
        dist/pretender.js:9:18133

        GET request has no requestBody
        Expected: 0
        Actual: 300
        onprogress@test/calling_test.js:528:19
        node_modules/fake-xml-http-request/fake_xml_http_request.js:137:22
        dispatchEvent@node_modules/fake-xml-http-request/fake_xml_http_request.js:181:28
        _progress@node_modules/fake-xml-http-request/fake_xml_http_request.js:199:25
        dist/pretender.js:9:18133

        Expected: 300
        Actual: 155
        onprogress@test/calling_test.js:529:19
        node_modules/fake-xml-http-request/fake_xml_http_request.js:137:22
        dispatchEvent@node_modules/fake-xml-http-request/fake_xml_http_request.js:181:28
        _progress@node_modules/fake-xml-http-request/fake_xml_http_request.js:199:25
        dist/pretender.js:9:18133

        GET request has no requestBody
        Expected: 0
        Actual: 300
        onprogress@test/calling_test.js:528:19
        node_modules/fake-xml-http-request/fake_xml_http_request.js:137:22
        dispatchEvent@node_modules/fake-xml-http-request/fake_xml_http_request.js:181:28
        _progress@node_modules/fake-xml-http-request/fake_xml_http_request.js:199:25
        dist/pretender.js:9:18133

        Expected: 300
        Actual: 208
        onprogress@test/calling_test.js:529:19
        node_modules/fake-xml-http-request/fake_xml_http_request.js:137:22
        dispatchEvent@node_modules/fake-xml-http-request/fake_xml_http_request.js:181:28
        _progress@node_modules/fake-xml-http-request/fake_xml_http_request.js:199:25
        dist/pretender.js:9:18133

        GET request has no requestBody
        Expected: 0
        Actual: 300
        onprogress@test/calling_test.js:528:19
        node_modules/fake-xml-http-request/fake_xml_http_request.js:137:22
        dispatchEvent@node_modules/fake-xml-http-request/fake_xml_http_request.js:181:28
        _progress@node_modules/fake-xml-http-request/fake_xml_http_request.js:199:25
        dist/pretender.js:9:18133

        Expected: 300
        Actual: 260
        onprogress@test/calling_test.js:529:19
        node_modules/fake-xml-http-request/fake_xml_http_request.js:137:22
        dispatchEvent@node_modules/fake-xml-http-request/fake_xml_http_request.js:181:28
        _progress@node_modules/fake-xml-http-request/fake_xml_http_request.js:199:25
        dist/pretender.js:9:18133

...22 02 2020 17:10:46.581:WARN [web-server]: 404: /some/path
.............22 02 2020 17:10:46.588:WARN [web-server]: 404: /some/path
..........22 02 2020 17:10:46.600:WARN [web-server]: 404: /some/otherpath
..22 02 2020 17:10:46.606:WARN [web-server]: 404: /some/otherpath
..
Chrome 80.0.3987 (Mac OS X 10.15.3) passthrough requests asynchronous request with pass-through and empty response FAILED
        response for real and fake xhr are both blank strings
        Expected: ""
        Actual: null
            at FakeRequest._onload (test/passthrough_test.js:332:14)
            at FakeRequest.dispatchEvent (node_modules/fake-xml-http-request/fake_xml_http_request.js:181:24)
            at dispatchEvent (dist/pretender.js:9:11588)
            at testXHR.xhr.<computed> [as onload] (dist/pretender.js:9:12162)
            at Object.apply (test/passthrough_test.js:316:15)
            at FakeRequest.send (dist/pretender.js:9:9275)

Chrome 80.0.3987 (Mac OS X 10.15.3) passthrough requests > the `.passthrough()` property allows a passthrough on an unhandledRequest FAILED
        Expected: 404
        Actual: 0
            at Object.error (test/passthrough_test.js:354:18)
            at j (bower_components/jquery-1/index.js:2:27309)
            at Object.fireWith [as rejectWith] (bower_components/jquery-1/index.js:2:28122)
            at x (bower_components/jquery-1/index.js:5:22136)
            at Function.ajax (bower_components/jquery-1/index.js:5:21607)
            at Object.<anonymous> (test/passthrough_test.js:351:9)

.
Chrome 80.0.3987 (Mac OS X 10.15.3) passthrough requests > the `.passthrough()` property returns a native xhr FAILED
        Died on test #1     at Object.<anonymous> (test/passthrough_test.js:360:5)
            at processModule (node_modules/qunit/qunit/qunit.js:1191:16)
            at module$1 (node_modules/qunit/qunit/qunit.js:1216:4)
            at Object.<anonymous> (test/passthrough_test.js:343:3)
            at processModule (node_modules/qunit/qunit/qunit.js:1191:16)
            at module$1 (node_modules/qunit/qunit/qunit.js:1216:4)
            at test/passthrough_test.js:5:1: request.passthrough is not a function
        TypeError: request.passthrough is not a function
            at Pretender.pretender.unhandledRequest (test/passthrough_test.js:385:37)
            at Pretender.handleRequest (dist/pretender.js:9:21831)
            at FakeRequest.send (dist/pretender.js:9:9397)
            at Object.<anonymous> (test/passthrough_test.js:390:11)
            at runTest (node_modules/qunit/qunit/qunit.js:3041:30)
            at Test.run (node_modules/qunit/qunit/qunit.js:3027:6)
            at node_modules/qunit/qunit/qunit.js:3258:12
            at processTaskQueue (node_modules/qunit/qunit/qunit.js:2614:24)
            at node_modules/qunit/qunit/qunit.js:2618:8

22 02 2020 17:10:46.629:WARN [web-server]: 404: /some/path
.22 02 2020 17:10:46.644:WARN [web-server]: 404: /some/path
.................
Chrome 80.0.3987 (Mac OS X 10.15.3): Executed 78 of 78 (7 FAILED) (0.962 secs / 0.921 secs)
.............22 02 2020 17:10:46.671:WARN [web-server]: 404: /some/path
.22 02 2020 17:10:46.685:WARN [web-server]: 404: /some/path
....22 02 2020 17:10:46.701:WARN [web-server]: 404: /some/otherpath
.22 02 2020 17:10:46.708:WARN [web-server]: 404: /some/otherpath
.
PhantomJS 2.1.1 (Mac OS X 0.0.0) passthrough requests asynchronous request with pass-through and empty response FAILED
        response for real and fake xhr are both blank strings
        Expected: ""
        Actual: null
        _onload@test/passthrough_test.js:332:19
        dispatchEvent@node_modules/fake-xml-http-request/fake_xml_http_request.js:181:28
        dispatchEvent@dist/pretender.js:9:30958
        dist/pretender.js:9:31532
        apply@test/passthrough_test.js:316:21
        send@dist/pretender.js:9:19183
        test/passthrough_test.js:340:13
        runTest@node_modules/qunit/qunit/qunit.js:3041:34
        run@node_modules/qunit/qunit/qunit.js:3027:13
        node_modules/qunit/qunit/qunit.js:3258:15
        processTaskQueue@node_modules/qunit/qunit/qunit.js:2614:28
        node_modules/qunit/qunit/qunit.js:2618:24
        invokeCallback@node_modules/qunit/qunit/qunit.js:1699:25
        node_modules/qunit/qunit/qunit.js:1467:30
        flush@node_modules/qunit/qunit/qunit.js:1419:15

PhantomJS 2.1.1 (Mac OS X 0.0.0) passthrough requests > the `.passthrough()` property allows a passthrough on an unhandledRequest FAILED
        Expected: 404
        Actual: 0
        error@test/passthrough_test.js:354:23
        j@bower_components/jquery-1/index.js:2:27578
        fireWith@bower_components/jquery-1/index.js:2:55529
        x@bower_components/jquery-1/index.js:5:41346
        ajax@bower_components/jquery-1/index.js:5:21608
        test/passthrough_test.js:351:13
        runTest@node_modules/qunit/qunit/qunit.js:3041:34
        run@node_modules/qunit/qunit/qunit.js:3027:13
        node_modules/qunit/qunit/qunit.js:3258:15
        processTaskQueue@node_modules/qunit/qunit/qunit.js:2614:28
        node_modules/qunit/qunit/qunit.js:2618:24
        invokeCallback@node_modules/qunit/qunit/qunit.js:1699:25
        node_modules/qunit/qunit/qunit.js:1467:30
        flush@node_modules/qunit/qunit/qunit.js:1419:15

22 02 2020 17:10:46.738:WARN [web-server]: 404: /some/path
PhantomJS 2.1.1 (Mac OS X 0.0.0) passthrough requests > the `.passthrough()` property returns a native xhr FAILED
        Died on test #1 undefined: undefined is not a constructor (evaluating 'request.passthrough()')
        unhandledRequest@test/passthrough_test.js:385:48
        handleRequest@dist/pretender.js:9:23707
        send@dist/pretender.js:9:19313
        test/passthrough_test.js:390:15
        runTest@node_modules/qunit/qunit/qunit.js:3041:34
        run@node_modules/qunit/qunit/qunit.js:3027:13
        node_modules/qunit/qunit/qunit.js:3258:15
        processTaskQueue@node_modules/qunit/qunit/qunit.js:2614:28
        node_modules/qunit/qunit/qunit.js:2618:24
        invokeCallback@node_modules/qunit/qunit/qunit.js:1699:25
        node_modules/qunit/qunit/qunit.js:1467:30
        flush@node_modules/qunit/qunit/qunit.js:1419:15

.................
PhantomJS 2.1.1 (Mac OS X 0.0.0): Executed 78 of 78 (7 FAILED) (0.982 secs / 0.962 secs)
TOTAL: 14 FAILED, 142 SUCCESS
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] tests-only: `karma start --single-run`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] tests-only script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/samselikoff/.npm/_logs/2020-02-22T22_10_46_916Z-debug.log
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@GriffinSauce
Copy link

test does run successfully after running test-ci once, seems like the pretest task is missing in the test command, does that help?

@samselikoff
Copy link
Contributor Author

@GriffinSauce not sure but thanks for the suggestion, after Thomas' latest commit I have it working + can now get to work on this!

@xg-wang
Copy link
Member

xg-wang commented Mar 21, 2020

Closed by #296

@xg-wang xg-wang closed this as completed Mar 21, 2020
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 a pull request may close this issue.

4 participants