docs: add prerequisites link for test guides (#9057)

- Add a prerequisites link to test guides pointing to how to setup the testing tools
- Add in the main http / module integration guides the command to run the tests
This commit is contained in:
Shahed Nasser
2024-09-09 16:58:42 +03:00
committed by GitHub
parent 2189ff2dc8
commit c091cf5868
5 changed files with 96 additions and 3 deletions

View File

@@ -1,3 +1,5 @@
import { Prerequisites } from "docs-ui"
export const metadata = {
title: `${pageNumber} Example: Write Integration Tests for API Routes`,
}
@@ -6,6 +8,15 @@ export const metadata = {
In this chapter, you'll learn how to write integration tests for API routes using the [medusaIntegrationTestRunner utility function](../page.mdx).
<Prerequisites
items={[
{
text: "Testing Tools Setup",
link: "/debugging-and-testing/testing-tools"
}
]}
/>
## Test a GET API Route
Consider the following API route created at `src/api/store/custom/route.ts`:
@@ -73,7 +84,7 @@ If you don't have a `test:integration` script in `package.json`, refer to the [M
</Note>
This runs your Medusa application and runs the tests available under the `src/integrations` directory.
This runs your Medusa application and runs the tests available under the `src/integrations/http` directory.
---

View File

@@ -1,3 +1,5 @@
import { Prerequisites } from "docs-ui"
export const metadata = {
title: `${pageNumber} Write Integration Tests`,
}
@@ -6,6 +8,15 @@ export const metadata = {
In this chapter, you'll learn about the `medusaIntegrationTestRunner` utility function used to write integration tests.
<Prerequisites
items={[
{
text: "Testing Tools Setup",
link: "/debugging-and-testing/testing-tools"
}
]}
/>
## medusaIntegrationTestRunner Utility
The `medusaIntegrationTestRunner` utility function is provided by the `medusa-test-utils` package to create integration tests in your Medusa project. It runs a full Medusa application, allowing you test API routes, workflows, or other customizations.
@@ -39,7 +50,27 @@ The `medusaIntegrationTestRunner` function accepts an object as a parameter. The
The tests in the `testSuite` function are written using [Jest](https://jestjs.io/).
### Other Options and Inputs
---
### Run Tests
Run the following command to run your tests:
```bash npm2yarn
npm run test:integration
```
<Note title="Tip">
If you don't have a `test:integration` script in `package.json`, refer to the [Medusa Testing Tools chapter](../page.mdx#add-test-commands).
</Note>
This runs your Medusa application and runs the tests available under the `src/integrations/http` directory.
---
## Other Options and Inputs
Refer to [this reference in the Learning Resources documentation](!resources!/test-tools-reference/medusaIntegrationTestRunner) for other available parameter options and inputs of the `testSuite` function.

View File

@@ -1,3 +1,5 @@
import { Prerequisites } from "docs-ui"
export const metadata = {
title: `${pageNumber} Example: Write Integration Tests for Workflows`,
}
@@ -6,6 +8,15 @@ export const metadata = {
In this chapter, you'll learn how to write integration tests for workflows using the [medusaIntegrationTestRunner utility function](../page.mdx).
<Prerequisites
items={[
{
text: "Testing Tools Setup",
link: "/debugging-and-testing/testing-tools"
}
]}
/>
## Write Integration Test for Workflow
Consider you have the following workflow defined at `src/workflows/hello-world.ts`:

View File

@@ -1,3 +1,5 @@
import { Prerequisites } from "docs-ui"
export const metadata = {
title: `${pageNumber} Example: Integration Tests for a Module`,
}
@@ -6,6 +8,15 @@ export const metadata = {
In this chapter, find an example of writing an integration test for a module using the [moduleIntegrationTestRunner utility function](../page.mdx).
<Prerequisites
items={[
{
text: "Testing Tools Setup",
link: "/debugging-and-testing/testing-tools"
}
]}
/>
## Write Integration Test for Module
Consider a `hello` module with a `HelloModuleService` that has a `getMessage` method:
@@ -67,4 +78,4 @@ If you don't have a `test:modules` script in `package.json`, refer to the [Medus
</Note>
This runs your Medusa application and runs the tests available in any `__tests__` directory under the `src` directory.
This runs your Medusa application and runs the tests available in any `__tests__` directory under the `src/modules` directory.

View File

@@ -1,3 +1,5 @@
import { Prerequisites } from "docs-ui"
export const metadata = {
title: `${pageNumber} Write Tests for Modules`,
}
@@ -6,6 +8,15 @@ export const metadata = {
In this chapter, you'll learn about the `moduleIntegrationTestRunner` utility function and how to use it to write integration tests for a module's main service.
<Prerequisites
items={[
{
text: "Testing Tools Setup",
link: "/debugging-and-testing/testing-tools"
}
]}
/>
## moduleIntegrationTestRunner Utility
The `moduleIntegrationTestRunner` utility function is provided by the `medusa-test-utils` package to create integration tests for a module. The integration tests run on a test Medusa application with only the specified module enabled.
@@ -47,6 +58,24 @@ The tests in the `testSuite` function are written using [Jest](https://jestjs.io
---
## Run Tests
Run the following command to run your module integration tests:
```bash npm2yarn
npm run test:modules
```
<Note title="Tip">
If you don't have a `test:modules` script in `package.json`, refer to the [Medusa Testing Tools chapter](../page.mdx#add-test-commands).
</Note>
This runs your Medusa application and runs the tests available in any `__tests__` directory under the `src/modules` directory.
---
## Pass Module Options
If your module accepts options, you can set them using the `moduleOptions` property of the `moduleIntegrationTestRunner`'s parameter.