Yarn test failing - Network request failed - reactjs

I created a react project using create-react-app however when ran yarn test to see if the initial tests pass I get
TypeError: Network request failed
at XMLHttpRequest.xhr.onerror (/home/ubuntu/wonderland/hackernews/node_modules/whatwg-fetch/fetch.js:436:16)
at XMLHttpRequest.callback.(anonymous function) (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:289:32)
at invokeEventListeners (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:219:27)
at invokeInlineListeners (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:166:7)
at EventTargetImpl._dispatch (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:122:7)
at EventTargetImpl.dispatchEvent (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:87:17)
at XMLHttpRequest.dispatchEvent (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:61:35)
at XMLHttpRequest.abort (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js:405:16)
at Object.abort (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/xhr-utils.js:315:13)
at RequestManager.close (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/living/nodes/Document-impl.js:146:21)
at Window.close (/home/ubuntu/wonderland/hackernews/node_modules/jsdom/lib/jsdom/browser/Window.js:362:29)
at JSDOMEnvironment.dispose (/home/ubuntu/wonderland/hackernews/node_modules/jest-environment-jsdom/build/index.js:44:19)
at Promise.resolve.then (/home/ubuntu/wonderland/hackernews/node_modules/jest-cli/build/runTest.js:102:17)
I'm working in Cloud9 editor using ssh connected to my dev server (Ubuntu) hosted in AWS. Tests are working fine in my local machine (Ubuntu).
Thanks for the help!

I already solve my problem. I'm following a book entitled "The Road to Learn React" and I think that the one causing my error is the part where I fetch data from an external API. The book forgot to include an import for fetch which is this one:
import fetch from 'isomorphic-fetch'
Then, it solves my problem like a charm.

Related

Jest integration Tests break on Pipeline

Hello im trying to find to build a application on my pipeline using integrations tests with Jest version 27.5.1 as well as jest-cli 27.5.1 all the tests work on my localhost however when my code runs through the Pipeline it shows the following Error
FetchError: request to http://localhost/callback?usid= failed, reason: connect ECONNREFUSED 127.0.0.1:80
and if i add a skip to this test the next test breaks as well
I've tried reading the documentation of jest to see if the root of the problem could be syntax i changed the Url where im doing the request for the API and also cleared added on the function afterEach() server.resetHandlers() as well as LocalStorage.clear() to clear up anything that might be considered Old data

cy.mockGraphql is not a function

Trying to run a test using cypress-graphql-mock in Next.js project but getting this error: cy.mockGraphql is not a function
Both cypress and cypress-graphql-mock are installed.
In the description of the library it says: "Adds commands for executing a mocked GraphQL server using only the client", But I have no idea why it is not adding a function.
Op was able to solve it by adding import "cypress-graphql-mock"; into the support/command.js file.

error trying to load the config "relay" for the macro imported from "babel-plugin-relay/macro"

We are trying to upgrade our react project to latest packages including relay (7.0.0). Our application builds and works but we are getting this error message in the console (during build) on every file where we import graphql from 'babel-plugin-relay/macro'. We are doing exactly like documented here adding relay
The error is "There was an error trying to load the config "relay" for the macro imported from "babel-plugin-relay/macro. Please see the error thrown for more information." It is coming from \node_modules\babel-plugin-macros\dist\index.js in getConfig( ).
To understand how other projects were configured, I downloaded another sample relay project / installed it and it had the same problem. Interesting enough there was this recent post in that app's issues list error loading config
The solution noted worked for me (adding that noted .babel-plugin-macrosrc.yml file with empty relay plugin?) but I am not understanding why this is needed or what was causing this seemingly benign error message?

Running Travis-CI using MochaJS, Supertest w/ Babel, Browserify, and Gulp

I've followed some tutorials and web casts on code school, mainly those on Node, ES2015, Angular, and Express. I've started a little project of my own and I've implemented all of the above. I'm also trying to get automated builds and testing working using Travis-CI and Mocha/Supertests for test driven development. The problem though is if I run npm test I get this error from Mocha
1) Uncaught error outside test suite:
Uncaught Error: listen EADDRINUSE :::3000
at Object.exports._errnoException (util.js:870:11)
at exports._exceptionWithHostPort (util.js:893:20)
at Server._listen2 (net.js:1236:14)
at listen (net.js:1272:10)
at Server.listen (net.js:1368:5)
at EventEmitter.listen (node_modules/express/lib/application.js:617:24)
at Object.<anonymous> (server/app.js:34:5)
at require (internal/module.js:12:17)
at Object.<anonymous> (test.js:6:11)
at require (internal/module.js:12:17)
at Array.forEach (native)
at node.js:962:3
I just noticed that I was missing module.exports = app at the end of my main app.js that might have helped but the tests still fail.
Here is a link to the latest push on GitHub.
Here is the failing build on Travis-CI.
Changing my server/app.js to listen if using
if (!module.parent) {
app.listen(port, () => {
console.log("Listening on port " + port);
});
}
Resolved my issue regarding testing not working on my local machine. The reason behind doing this can be found here.
Also adding
services:
- mongodb
like #ocean said worked, which reasoning can be referenced here.
The error you're currently getting on Travis CI is because NPM is trying to start your app with node server/app.js (as specified in line 9 of your package.json), but your app requires MongoDB to be running (as specified on line 13 of your app.js).
NPM has to start your app before it can run the tests.
MongoDB is available as a service on Travis CI. Have a look at the Travis CI Database Setup docs and see how you go.
Ok then, well the error is that this Express app is trying to use a network port on your machine which is already being used by something else (maybe another Node / Express app, as they often use 3000).
Try changing the var port declaration near the bottom of server/app.js to be something other than 3000.

Getting Angular Twitter API app working

I have been trying to get the following angular twitter API app to work out of the box but am running into an error on startup.
I am running node v0.10.36, npm 1.4.28
I just wanted to throw it out to the wider community to see if anyone could help me out.
I am trying to get the app working and am running into the error below. I tried a couple of things eg changing port, changing package.json to reflect a newer version of npm but I just don't seem to be able to get it to work. Any assistance would be appreciated. Thanks in advance.
It looks like all the node modules installed correctly.
/Users/billyjlennon/sample-angular-node/routes/tweets.js:36
var i = 0, len = tweets.length;
^
TypeError: Cannot read property 'length' of undefined
at /Users/billyjlennon/sample-angular-node/routes/tweets.js:36:28
at responseHandler (/Users/billyjlennon/sample-angular-node/node_modules/twit/lib/oarequest.js:362:14)
at passBackControl (/Users/billyjlennon/sample-angular-node/node_modules/twit/node_modules/oauth/lib/oauth.js:374:13)
at IncomingMessage.<anonymous> (/Users/billyjlennon/sample-angular-node/node_modules/twit/node_modules/oauth/lib/oauth.js:386:9)
at IncomingMessage.emit (events.js:117:20)
at _stream_readable.js:944:16
at process._tickCallback (node.js:442:13)
It would be such a handy app if I could get it to work!!!
Have you done this per the readme:
Create a config.js file using config.sample.js as a template. Fill in your Twitter App API Keys. You will need to create a Twitter application.
The fact that length is undefined indicates you aren't getting any data back.

Resources