Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: test(next-drupal): add tests for builds #593

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/next-drupal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
16 changes: 16 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -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 = "<rootDir>/packages/next-drupal/dist/index.modern.js"
break
case "cjs":
mappedModule = "<rootDir>/packages/next-drupal/dist/index.cjs"
break
default:
mappedModule = "<rootDir>/packages/next-drupal/src/index.ts"
}

const config: Config.InitialOptions = {
preset: "ts-jest/presets/js-with-ts",
testEnvironment: "node",
setupFiles: ["dotenv/config"],
setupFilesAfterEnv: ["<rootDir>/jest.setup.ts"],
testMatch: ["**/tests/**/*.test.{ts,tsx}"],
moduleNameMapper: {
"^next-drupal-build-testing$": mappedModule,
},
testPathIgnorePatterns: [
"/node_modules/",
"/fixtures/",
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/next-drupal/tests/client.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/next-drupal/tests/crud.test.ts
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
2 changes: 1 addition & 1 deletion packages/next-drupal/tests/utils.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Loading