|
| 1 | +import { spawnSync } from 'node:child_process'; |
| 2 | +import fs from 'node:fs'; |
| 3 | +import os from 'node:os'; |
| 4 | +import path from 'node:path'; |
| 5 | + |
| 6 | +describe('integrations', () => { |
| 7 | + const sdkPath = path.resolve(__dirname, '..'); |
| 8 | + |
| 9 | + beforeAll(() => { |
| 10 | + const build = spawnSync('pnpm build', { |
| 11 | + stdio: 'inherit', |
| 12 | + cwd: path.resolve(__dirname, '..'), |
| 13 | + shell: true, |
| 14 | + }); |
| 15 | + if (build.status !== 0) { |
| 16 | + throw new Error('SDK build failed'); |
| 17 | + } |
| 18 | + }); |
| 19 | + |
| 20 | + /** |
| 21 | + * Create an extra temporary copy of the given integration so that there's no `@react-email/render` module resolution from the resend-node's devDependencies |
| 22 | + * |
| 23 | + * Also modifies the package.json to point to the SDK with an absolute path. |
| 24 | + */ |
| 25 | + async function prepareTemporaryIntegrationCopy(integrationPath: string) { |
| 26 | + const temporaryIntegrationPath = await fs.promises.mkdtemp( |
| 27 | + path.join( |
| 28 | + os.tmpdir(), |
| 29 | + `resend-node-integration-${path.basename(integrationPath)}`, |
| 30 | + ), |
| 31 | + ); |
| 32 | + await fs.promises.cp( |
| 33 | + path.resolve(__dirname, integrationPath), |
| 34 | + temporaryIntegrationPath, |
| 35 | + { |
| 36 | + recursive: true, |
| 37 | + }, |
| 38 | + ); |
| 39 | + |
| 40 | + const testingLockPackageJson: { dependencies: Record<string, string> } = |
| 41 | + JSON.parse( |
| 42 | + await fs.promises.readFile( |
| 43 | + path.resolve(temporaryIntegrationPath, 'package.json'), |
| 44 | + 'utf8', |
| 45 | + ), |
| 46 | + ); |
| 47 | + testingLockPackageJson.dependencies.resend = sdkPath; |
| 48 | + await fs.promises.writeFile( |
| 49 | + path.resolve(temporaryIntegrationPath, 'package.json'), |
| 50 | + JSON.stringify(testingLockPackageJson, null, 2), |
| 51 | + ); |
| 52 | + |
| 53 | + return temporaryIntegrationPath; |
| 54 | + } |
| 55 | + |
| 56 | + test('nextjs', { timeout: 30_000 }, async () => { |
| 57 | + const temporaryNextAppPath = |
| 58 | + await prepareTemporaryIntegrationCopy('./nextjs'); |
| 59 | + |
| 60 | + const buildInstall = spawnSync( |
| 61 | + 'npm install --install-links && npm run build', |
| 62 | + { |
| 63 | + stdio: 'inherit', |
| 64 | + cwd: temporaryNextAppPath, |
| 65 | + shell: true, |
| 66 | + }, |
| 67 | + ); |
| 68 | + if (buildInstall.status !== 0) { |
| 69 | + throw new Error('next.js build failed'); |
| 70 | + } |
| 71 | + }); |
| 72 | + |
| 73 | + test('esbuild', { timeout: 30_000 }, async () => { |
| 74 | + const temporaryEsbuildAppPath = |
| 75 | + await prepareTemporaryIntegrationCopy('./esbuild'); |
| 76 | + |
| 77 | + const buildInstall = spawnSync( |
| 78 | + 'npm install --install-links && npm run build', |
| 79 | + { |
| 80 | + stdio: 'inherit', |
| 81 | + cwd: temporaryEsbuildAppPath, |
| 82 | + shell: true, |
| 83 | + }, |
| 84 | + ); |
| 85 | + if (buildInstall.status !== 0) { |
| 86 | + throw new Error('esbuild build failed'); |
| 87 | + } |
| 88 | + }); |
| 89 | +}); |
0 commit comments