diff --git a/.github/workflows/next-drupal.yml b/.github/workflows/next-drupal.yml index 477cd61e..dbda773a 100644 --- a/.github/workflows/next-drupal.yml +++ b/.github/workflows/next-drupal.yml @@ -14,7 +14,9 @@ jobs: - name: Install modules run: yarn - name: Run tests - run: yarn test packages/next-drupal + run: | + yarn test packages/next-drupal + yarn test:build env: DRUPAL_BASE_URL: ${{ secrets.DRUPAL_BASE_URL }} DRUPAL_USERNAME: ${{ secrets.DRUPAL_USERNAME }} diff --git a/jest.config.ts b/jest.config.ts index 3ab4fbfb..4ead956b 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -1,11 +1,27 @@ import type { Config } from "@jest/types" +let mappedModule: string +switch (process.env.TEST_ENV) { + // Depending on the TEST_ENV, we test the src or one of the builds. + case "esm": + mappedModule = "/packages/next-drupal/dist/index.modern.js" + break + case "cjs": + mappedModule = "/packages/next-drupal/dist/index.cjs" + break + default: + mappedModule = "/packages/next-drupal/src/index.ts" +} + const config: Config.InitialOptions = { preset: "ts-jest/presets/js-with-ts", testEnvironment: "node", setupFiles: ["dotenv/config"], setupFilesAfterEnv: ["/jest.setup.ts"], testMatch: ["**/tests/**/*.test.{ts,tsx}"], + moduleNameMapper: { + "^next-drupal-build-testing$": mappedModule, + }, testPathIgnorePatterns: [ "/node_modules/", "/fixtures/", diff --git a/package.json b/package.json index 2beab210..96e43fa7 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,9 @@ "cy:open": "turbo run cy:open --parallel", "test": "jest", "pretest": "yarn format:check && yarn lint", + "test:build": "yarn prepare && yarn test:build:esm && yarn test:build:cjs", + "test:build:esm": "TEST_ENV=esm jest", + "test:build:cjs": "TEST_ENV=cjs jest", "test:e2e": "turbo run test:e2e --parallel", "test:e2e:ci": "turbo run test:e2e:ci --parallel" }, diff --git a/packages/next-drupal/tests/client.test.ts b/packages/next-drupal/tests/client.test.ts index 011bfd35..50a7ccc1 100644 --- a/packages/next-drupal/tests/client.test.ts +++ b/packages/next-drupal/tests/client.test.ts @@ -1,6 +1,6 @@ import { expect } from "@jest/globals" import { GetStaticPropsContext } from "next" -import { DrupalClient } from "../src/client" +import { DrupalClient } from "next-drupal-build-testing" import type { Serializer, DrupalNode, diff --git a/packages/next-drupal/tests/crud.test.ts b/packages/next-drupal/tests/crud.test.ts index ed9a00b2..5dac72df 100644 --- a/packages/next-drupal/tests/crud.test.ts +++ b/packages/next-drupal/tests/crud.test.ts @@ -1,5 +1,5 @@ import { expect } from "@jest/globals" -import { DrupalClient } from "../src/client" +import { DrupalClient } from "next-drupal-build-testing" import type { DrupalNode } from "../src/types" import { BASE_URL, deleteTestNodes, toggleDrupalModule } from "./utils" diff --git a/packages/next-drupal/tests/utils.ts b/packages/next-drupal/tests/utils.ts index 762eb6ba..6def8dc0 100644 --- a/packages/next-drupal/tests/utils.ts +++ b/packages/next-drupal/tests/utils.ts @@ -1,4 +1,4 @@ -import { DrupalClient } from "../src/client" +import { DrupalClient } from "next-drupal-build-testing" // Run all tests against this env until we configure CI to setup a Drupal instance. // TODO: Bootstrap and expose the /drupal env for testing.