cmorten / superoak

HTTP assertions for Oak made easy via SuperDeno. 🐿 🦕
https://cmorten.github.io/superoak/
MIT License
121 stars 8 forks source link

ReferenceError: Access to "location", run again with --location <href> #17

Closed Schoude closed 3 years ago

Schoude commented 3 years ago

Issue

Setup:

When running the tests with deno test --allow-net app.test.ts I get the above error message.

Details

Following the example I set up the tests and ran deno test --allow-net app.test.ts but this error occurs.

λ deno test --allow-net app.test.ts 
running 2 tests
test GET "/" route ... Listening on: http://127.0.0.1:30162
FAILED (9ms)
test GET "/user/:id" ... Listening on: http://127.0.0.1:21887
FAILED (4ms)

failures:

GET "/" route
ReferenceError: Access to "location", run again with --location <href>.
    at get (deno:op_crates/web/12_location.js:376:17)
    at Function.request.getXHR (https://dev.jspm.io/npm:superagent@5.3.1/lib/client.dew.js:91:39)
    at Test.Request._end (https://dev.jspm.io/npm:superagent@5.3.1/lib/client.dew.js:753:24)
    at Test.Request.end (https://dev.jspm.io/npm:superagent@5.3.1/lib/client.dew.js:736:10)
    at Test.end (test.ts:443:9)
    at https://dev.jspm.io/npm:superagent@5.3.1/lib/request-base.dew.js:291:14
    at new Promise (<anonymous>)
    at Test.RequestBase.then (https://dev.jspm.io/npm:superagent@5.3.1/lib/request-base.dew.js:273:33)

GET "/user/:id"
ReferenceError: Access to "location", run again with --location <href>.
    at get (deno:op_crates/web/12_location.js:376:17)
    at Function.request.getXHR (https://dev.jspm.io/npm:superagent@5.3.1/lib/client.dew.js:91:39)
    at Test.Request._end (https://dev.jspm.io/npm:superagent@5.3.1/lib/client.dew.js:753:24)
    at Test.Request.end (https://dev.jspm.io/npm:superagent@5.3.1/lib/client.dew.js:736:10)
    at Test.end (test.ts:443:9)
    at https://dev.jspm.io/npm:superagent@5.3.1/lib/request-base.dew.js:291:14
    at new Promise (<anonymous>)
    at Test.RequestBase.then (https://dev.jspm.io/npm:superagent@5.3.1/lib/request-base.dew.js:273:33)

failures:

        GET "/" route
        GET "/user/:id"

test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out (14ms)

Hack to get the tests run again

Passing in any random "valid" URL like deno test --allow-net --location http://anything app.test.ts makes the tests run again.

deno test --allow-net --location http://anything app.test.ts 
running 2 tests
test GET "/" route ... Listening on: http://127.0.0.1:17370
ok (18ms)
test GET "/user/:id" ... Listening on: http://127.0.0.1:26924
ok (7ms)

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out (29ms)

It even runs when I just pass in --location http://a. I hope this only has to do with the Deno update to 1.7.2.

Thanks in advance for looking into it. :)

cmorten commented 3 years ago

Hi @Schoude 👋

Thanks for raising this - the issue was the use of globalThis.location in superagent which this library wraps ( well... it wraps superdeno which wraps superagent ).

Before the introduction of the the --location <href> flag, globalThis.location used to just be undefined. Now it throws if access is attempted without the flag, hence your issue.

I have side-stepped the issue upstream and pulled down the latest deps into this module, so please give https://deno.land/x/superoak@3.1.0 a go, and re-open if you find you still have issues!

Schoude commented 3 years ago

HI @cmorten,

I just updated the version and everything works now without the --location <href> hack mentioned in the issue.

Thanks for resolving this so fast! 😃