question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nexus Tutorial Part 4. Testing your API fails npm run test

See original GitHub issue

I’m working through the Nexus tutorial and encounter an error when running the command “npm run test”. I have included a screenshot of the terminal output of the command and can’t seem to figure out the problem.

I have the following versions installed in my package.json

"dependencies": {
    "apollo-server": "^2.22.2",
    "graphql": "^15.5.0",
    "nexus": "^1.0.0"
  },
  "devDependencies": {
    "@types/jest": "^26.0.22",
    "get-port": "^5.1.1",
    "graphql-request": "^3.4.0",
    "jest": "^26.6.3",
    "ts-jest": "^26.5.4",
    "ts-node-dev": "^1.1.6",
    "typescript": "^4.2.3"
  }
Screen Shot 2021-04-05 at 2 14 15 PM

Perhaps an important note, the tutorial also misses including an export statement in the server.ts file located in /api/server.ts. The export statement was not included in any of the previous tutorial chapters but is imported as a module in tests/__helper.ts on line 4.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
raleigh9123commented, Apr 6, 2021

This did solve the problem I encountered! Thank you.

When running the command again, I did receive an error that Jest could not find the node module “Prettier” Installing prettier as a dev dependency cleared this error and the test runs successfully.

1reaction
ruhenicommented, Apr 6, 2021

Hi @raleigh9123 👋🏾

Thank you for creating this issue. I tested it locally and ran into the same issue.

Perhaps an important note, the tutorial also misses including an export statement in the server.ts file located in /api/server.ts.

You are right, this is one of the fixes to the tutorial.

I updated the tutorial recently and I have a hunch it broke the tests.

Update your server.ts file to resemble this:

import { ApolloServer } from 'apollo-server'
import { schema } from './schema'
import { context } from './context'

export const server = new ApolloServer({ schema, context })

Create app.ts file in the api folder and import server as follows:

 import { server } from "./server";

server.listen().then(({ url }) => {
  console.log(`🚀 Server ready at ${url}`)
})

Lastly, update your package.json scripts to point the dev script to app.ts:

  "scripts": {
    "dev": "ts-node-dev --transpile-only --no-notify api/app.ts",
    "build": "tsc",
    "generate": "ts-node --transpile-only api/schema",
    "test": "npm run generate && jest"
  },

Re-run your tests and let me know if you run into any issues. 🙂

We’ll update the tutorial soon fixing this error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

4. Testing your API - GraphQL Nexus
System testing means tests that will run operations against your API just ... During this tutorial, you'll use the Jest testing framework to...
Read more >
start-server-and-test - npm
Start using start-server-and-test in your project by running `npm i ... then runs test command; when the tests end, shuts down server. NPM....
Read more >
Fullstack part4 | Testing the backend
Let's use the supertest package to help us write our tests for testing the API. We will install the package as a development...
Read more >
Build a Node.js and React app with npm - Jenkins
This tutorial shows you how to use Jenkins to orchestrate building a simple Node.js and React application with the Node Package Manager (npm)....
Read more >
Getting Started - Node Tap
A command-line interface for running tests and reporting on their success or failure. Support for test-coverage, including coverage of child processes spawned ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found