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

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

Closed
raleigh9123 opened this issue Apr 5, 2021 · 5 comments · Fixed by #882
Closed

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

raleigh9123 opened this issue Apr 5, 2021 · 5 comments · Fixed by #882
Assignees

Comments

@raleigh9123
Copy link

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.

@raleigh9123
Copy link
Author

Continued on to part 6. Testing with Prisma, and basically got the same terminal response back after running npm run test command. I have never used jest before. Just learning how to use these tools, and I have no idea where to start to fix this issue.

@gatherKnowledge
Copy link

me either.

@ruheni
Copy link
Contributor

ruheni commented 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.

@ruheni ruheni self-assigned this Apr 6, 2021
@raleigh9123
Copy link
Author

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.

@jasonkuhrt
Copy link
Contributor

Going to keep this open until you've updated the tutorial @ruheni, thanks!

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