Skip to content

Commit

Permalink
docs: add prerequisites link for test guides
Browse files Browse the repository at this point in the history
  • Loading branch information
shahednasser committed Sep 9, 2024
1 parent 32ebfa6 commit a5c6673
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Prerequisites } from "docs-ui"

export const metadata = {
title: `${pageNumber} Example: Write Integration Tests for API Routes`,
}
Expand All @@ -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`:
Expand Down Expand Up @@ -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.

---

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Prerequisites } from "docs-ui"

export const metadata = {
title: `${pageNumber} Write Integration Tests`,
}
Expand All @@ -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.
Expand Down Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Prerequisites } from "docs-ui"

export const metadata = {
title: `${pageNumber} Example: Write Integration Tests for Workflows`,
}
Expand All @@ -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`:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Prerequisites } from "docs-ui"

export const metadata = {
title: `${pageNumber} Example: Integration Tests for a Module`,
}
Expand All @@ -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:
Expand Down Expand Up @@ -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.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Prerequisites } from "docs-ui"

export const metadata = {
title: `${pageNumber} Write Tests for Modules`,
}
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit a5c6673

Please sign in to comment.