Files
medusa-store/www/apps/book/app/debugging-and-testing/tools/page.mdx
Shahed Nasser 4fe28f5a95 chore: reorganize docs apps (#7228)
* reorganize docs apps

* add README

* fix directory

* add condition for old docs
2024-05-03 17:36:38 +03:00

74 lines
2.0 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export const metadata = {
title: `${pageNumber} Debugging and Testing Tools`,
}
# {metadata.title}
In this chapter, youll learn about debugging and testing tools you can use.
<Note title="Tip">
Since the Medusa server is a Node.js server, you can use any Node.js testing tool you prefer, even if its not listed here.
</Note>
## Jest
[Jest](https://jestjs.io/) is a JavaScript testing framework. Your Medusa project is already configured with Jest; you can use it out-of-the-box.
For example, consider the following service created at `src/modules/hello/service.ts`:
```ts title="src/modules/hello/service.ts"
import { TransactionBaseService } from "@medusajs/medusa"
class HelloWorldService extends TransactionBaseService {
constructor(container) {
super(arguments[0])
}
getMessage(): string {
return "Hello, world!"
}
}
export default HelloWorldService
```
You can write a test for it in the file `src/modules/hello/__tests__/hello-world.ts`:
```ts title="src/modules/hello/__tests__/hello-world.ts"
import HelloWorldService from "../hello-world"
describe("HelloWorldService", () => {
const helloWorldService = new HelloWorldService()
it("should return hello world message", () => {
expect(helloWorldService.getMessage()).toBe("Hello, world!")
})
})
```
Then, run the following command in the root of your Medusa project to run the test:
```bash npm2yarn
npm run test
```
This command looks for TypeScript and JavaScript files under any directory named `__tests__` and runs them.
---
## 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 youre using VSCode, refer to [this guide](https://code.visualstudio.com/docs/nodejs/nodejs-debugging) to learn how to configure and use the debugger.
---
## Node.js Debugger
You can also use Node.jss Debugger API to debug your Medusa customizations.
Refer to [Node.jss documentation](https://nodejs.org/docs/latest-v18.x/api/debugger.html) for more details.