7.2. Debugging and Testing Tools

In this chapter, you’ll learn about debugging and testing tools you can use.

Tip

Since the Medusa server is a Node.js server, you can use any Node.js testing tool you prefer, even if it’s not listed here.

Jest#

Jest is a JavaScript testing framework. Your Medusa project is already configured with Jest; you can use it out-of-the-box.

Note

Refer to Jest's documentation to learn how to install and configure it.

For example, consider the following service created at src/modules/hello/service.ts:

src/modules/hello/service.ts
1class HelloModuleService {2  getMessage(): string {3    return "Hello, world!"4  }5}6
7export default HelloModuleService

You can write a test for it in the file src/modules/hello/__tests__/hello-world.spec.ts:

src/modules/hello/__tests__/hello-world.spec.ts
1import HelloModuleService from "../service"2
3describe("HelloModuleService", () => {4  const helloModuleService = new HelloModuleService()5
6  it("should return hello world message", () => {7    expect(helloModuleService.getMessage()).toBe("Hello, world!")8  })9})

IDE Debugging Tools#

Your IDE may provide a debugging tool for Node.js. In that case, you can use that tool to debug your Medusa customizations.

For example, if you’re using VSCode, refer to this guide to learn how to configure and use the debugger.


Node.js Debugger#

You can also use Node.js’s Debugger API to debug your Medusa customizations.

Refer to Node.js’s documentation for more details.

Was this chapter helpful?