End-to-End (E2E) Testing
Relevant source files
The following files were used as context for generating this wiki page:
End-to-End (E2E) testing in the Resend Node.js SDK ensures that the library functions correctly across different runtime environments and build tools. The suite validates the SDK by building it locally, integrating it into real-world application structures like Next.js and esbuild projects, and verifying successful builds. This process confirms that package exports, TypeScript definitions, and module resolutions operate as expected in a production-like pipeline.
Sources: e2e/e2e.spec.ts:7-77, package.json:50-60
E2E Test Workflow
The E2E testing system uses a multi-stage process to verify the SDK. It first generates a fresh build of the SDK and then injects this build into isolated temporary projects.
Environment Preparation
The test runner executes pnpm build to generate the dist folder. It then creates temporary copies of integration projects found in the e2e/ directory. This isolation prevents module resolution conflicts with the main repository's devDependencies.
Sources: e2e/e2e.spec.ts:10-33
Dependency Injection
The suite modifies the package.json of the temporary integration copy. It replaces the standard resend dependency with an absolute path to the local SDK directory. This forces the test application to use the newly built code instead of a version from an external registry.
Sources: e2e/e2e.spec.ts:44-55
Build Verification
The runner executes a full installation and build command within the temporary project. It specifically uses npm install --install-links to ensure the local path dependency is handled correctly by the package manager.
Sources: e2e/e2e.spec.ts:60-77
The diagram above illustrates the sequence of operations performed for each framework integration (Next.js and esbuild) during a test run.
Sources: e2e/e2e.spec.ts:10-77
Integration vs E2E Testing
The project distinguishes between E2E tests (framework compatibility) and Integration tests (API functionality). While E2E tests focus on build-time success, Integration tests focus on run-time API interactions.
Integration Testing Architecture
Integration tests utilize the Polly.js framework to manage HTTP requests. This allows tests to run against a real API (recording mode) or against saved snapshots (replay mode), ensuring consistent results without requiring live network access in CI environments.
Sources: src/segments/segments.integration.spec.ts:1-12, src/api-keys/api-keys.integration.spec.ts:1-12
Resource Testing Scope
Integration tests cover various API modules, performing CRUD operations to verify the SDK's internal logic and endpoint mapping.
| Module | Operations Tested | Verification Logic |
|---|---|---|
| Segments | Create, List, Get, Remove | Validates ID existence and object type 'segment'. |
| Contacts | Create, List, Get, Update, Remove | Verifies field mapping and audience associations. |
| API Keys | Create, Remove | Checks token generation and permission scopes. |
| Audiences | Create, List, Get, Remove | Confirms object mapping for audience resources. |
Sources: src/segments/segments.integration.spec.ts:14-135, src/contacts/contacts.integration.spec.ts:25-460, src/api-keys/api-keys.integration.spec.ts:17-68, src/segments/audiences.integration.spec.ts:14-125
Test Execution Scripts
The package.json defines specific scripts to manage the testing lifecycle.
| Script | Command | Purpose |
|---|---|---|
test | vitest run --exclude e2e | Runs unit and integration tests, excluding E2E. |
test:e2e | vitest run e2e | Executes the E2E suite defined in e2e/e2e.spec.ts. |
test:record | cross-env TEST_MODE=record vitest... | Records new Polly.js snapshots for integration tests. |
build | tsdown src/index.ts --format esm,cjs --dts | Compiles the SDK for all supported formats. |
Sources: package.json:49-59
Build Tool Integrations
The E2E suite explicitly targets modern development stacks to ensure broad compatibility.
Next.js Integration
The test validates that the SDK can be bundled within a Next.js environment. It specifically executes a build using the Turbopack engine when applicable.
Sources: e2e/e2e.spec.ts:58-69, package.json:51
esbuild Integration
The suite confirms that the SDK's CJS and ESM exports are compatible with esbuild, which is commonly used in serverless and edge computing environments.
Sources: e2e/e2e.spec.ts:71-82
The sequence diagram shows the interaction between the test runner and the system environment to isolate the integration tests.
Sources: e2e/e2e.spec.ts:35-55
The E2E testing framework provides high confidence that the local SDK builds are functional and ready for deployment across diverse Node.js ecosystems. By isolating the environment and automating framework builds, the project prevents regression in package distribution and module resolution.