diff --git a/www/apps/book/app/debugging-and-testing/testing-tools/integration-tests/api-routes/page.mdx b/www/apps/book/app/debugging-and-testing/testing-tools/integration-tests/api-routes/page.mdx index 08cb0f7911..1dd095a969 100644 --- a/www/apps/book/app/debugging-and-testing/testing-tools/integration-tests/api-routes/page.mdx +++ b/www/apps/book/app/debugging-and-testing/testing-tools/integration-tests/api-routes/page.mdx @@ -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). + + ## 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 -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. --- diff --git a/www/apps/book/app/debugging-and-testing/testing-tools/integration-tests/page.mdx b/www/apps/book/app/debugging-and-testing/testing-tools/integration-tests/page.mdx index 0116a1ce34..ecfdd62559 100644 --- a/www/apps/book/app/debugging-and-testing/testing-tools/integration-tests/page.mdx +++ b/www/apps/book/app/debugging-and-testing/testing-tools/integration-tests/page.mdx @@ -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. + + ## 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 +``` + + + +If you don't have a `test:integration` script in `package.json`, refer to the [Medusa Testing Tools chapter](../page.mdx#add-test-commands). + + + +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. diff --git a/www/apps/book/app/debugging-and-testing/testing-tools/integration-tests/workflows/page.mdx b/www/apps/book/app/debugging-and-testing/testing-tools/integration-tests/workflows/page.mdx index 905c7797f4..2b41dff11c 100644 --- a/www/apps/book/app/debugging-and-testing/testing-tools/integration-tests/workflows/page.mdx +++ b/www/apps/book/app/debugging-and-testing/testing-tools/integration-tests/workflows/page.mdx @@ -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). + + ## Write Integration Test for Workflow Consider you have the following workflow defined at `src/workflows/hello-world.ts`: diff --git a/www/apps/book/app/debugging-and-testing/testing-tools/modules-tests/module-example/page.mdx b/www/apps/book/app/debugging-and-testing/testing-tools/modules-tests/module-example/page.mdx index 606d7f8291..87a5b7791d 100644 --- a/www/apps/book/app/debugging-and-testing/testing-tools/modules-tests/module-example/page.mdx +++ b/www/apps/book/app/debugging-and-testing/testing-tools/modules-tests/module-example/page.mdx @@ -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). + + ## 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 -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. diff --git a/www/apps/book/app/debugging-and-testing/testing-tools/modules-tests/page.mdx b/www/apps/book/app/debugging-and-testing/testing-tools/modules-tests/page.mdx index b9b01e37d2..d8a4098b9a 100644 --- a/www/apps/book/app/debugging-and-testing/testing-tools/modules-tests/page.mdx +++ b/www/apps/book/app/debugging-and-testing/testing-tools/modules-tests/page.mdx @@ -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. + + ## 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 +``` + + + +If you don't have a `test:modules` script in `package.json`, refer to the [Medusa Testing Tools chapter](../page.mdx#add-test-commands). + + + +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.