diff --git a/e2e/nx-heroku-e2e/tests/nx-heroku.spec.ts b/e2e/nx-heroku-e2e/tests/nx-heroku.spec.ts index 84310cc..658c957 100644 --- a/e2e/nx-heroku-e2e/tests/nx-heroku.spec.ts +++ b/e2e/nx-heroku-e2e/tests/nx-heroku.spec.ts @@ -62,7 +62,45 @@ describe('nx-heroku e2e', () => { expect(project.targets?.deploy?.options?.email).toEqual(HEROKU_EMAIL); }, 120000); - it('should create target and deploy the app successfully', async () => { + it('should create target and deploy an app with simple configuration successfully', async () => { + const { projectName, getProjectConfig, updateProjectConfig } = + await createProject(); + + projects.push(projectName); + // restore the environment variables to be expanded by the executor + process.env.HEROKU_API_KEY = process.env.HEROKU_API_KEY_PREV; + process.env.HEROKU_EMAIL = process.env.HEROKU_EMAIL_PREV; + // configure the target + await runNxCommandAsync( + `generate @getlarge/nx-heroku:deploy ${projectName} --appNamePrefix=aloes` + ); + const project = getProjectConfig(); + project.targets!.deploy.options = { + ...(project.targets!.deploy.options || {}), + procfile: `web: node dist/apps/${projectName}/main.js`, + buildPacks: ['heroku/nodejs'], + apiKey: HEROKU_API_KEY, + email: HEROKU_EMAIL, + variables: { + // used in postbuild.js + PROJECT_NAME: projectName, + }, + useForce: true, + serviceUser: 'edouard@aloes.io', + debug: true, + }; + updateProjectConfig(project); + prepareProjectForDeployment(projectName); + // run the target + const { stderr, stdout } = await runNxCommandAsync( + `deploy ${projectName} --verbose`, + { silenceError: true } + ); + console.warn(stdout, stderr); + expect(stdout).toContain('Deployment successful.'); + }, 100000); + + it('should create target and deploy the app with complex configuration successfully', async () => { const { projectName, getProjectConfig, updateProjectConfig } = await createProject(); diff --git a/e2e/nx-heroku-e2e/tests/tools.ts b/e2e/nx-heroku-e2e/tests/tools.ts index 59c9925..14d9fe2 100644 --- a/e2e/nx-heroku-e2e/tests/tools.ts +++ b/e2e/nx-heroku-e2e/tests/tools.ts @@ -1,6 +1,7 @@ import { NxJsonConfiguration, ProjectConfiguration, + logger, serializeJson, } from '@nx/devkit'; import { @@ -169,9 +170,18 @@ function patchPackageJson() { } function commitPackageJson() { - execSync( - `git add package*.json && git commit -m "chore: update package*.json" -n --no-gpg-sign` - ); + try { + execSync( + `git add package*.json && git commit -m "chore: update package*.json" -n --no-gpg-sign` + ); + } catch (e) { + if (e['stdout']?.toString().includes('no changes added to commit')) { + return; + } else { + logger.error(e); + throw e; + } + } } function setPackageJsonForHeroku() { diff --git a/packages/nx-heroku/src/executors/common/heroku/drains.ts b/packages/nx-heroku/src/executors/common/heroku/drains.ts index 43a25d0..aaf6252 100644 --- a/packages/nx-heroku/src/executors/common/heroku/drains.ts +++ b/packages/nx-heroku/src/executors/common/heroku/drains.ts @@ -34,7 +34,7 @@ export async function addDrain(options: { password?: string; }; }): Promise<'found' | 'created'> { - const { appName, drain = { url: '' } } = options; + const { appName, drain = null } = options; if (!drain?.url || !isURL(drain.url)) return; let url: string = drain.url; if (drain.user && drain.password) { diff --git a/packages/nx-heroku/src/executors/common/heroku/webhooks.ts b/packages/nx-heroku/src/executors/common/heroku/webhooks.ts index 86ea640..19380cb 100644 --- a/packages/nx-heroku/src/executors/common/heroku/webhooks.ts +++ b/packages/nx-heroku/src/executors/common/heroku/webhooks.ts @@ -62,15 +62,7 @@ export async function addWebhook(options: { secret?: string; }; }): Promise<'created' | 'updated' | 'found'> { - const { - appName, - webhook = { - url: '', - include: ['api:build', 'api:release', 'dyno'], - level: 'sync', - secret: '', - }, - } = options; + const { appName, webhook = null } = options; if (!webhook?.url || !isURL(webhook.url)) return; const { url, level, secret } = webhook; const include = webhook.include.join(','); diff --git a/packages/nx-heroku/src/executors/deploy/executor.spec.ts b/packages/nx-heroku/src/executors/deploy/executor.spec.ts index 2d89fd6..54a6155 100644 --- a/packages/nx-heroku/src/executors/deploy/executor.spec.ts +++ b/packages/nx-heroku/src/executors/deploy/executor.spec.ts @@ -172,4 +172,21 @@ describe('Deploy Executor', () => { expect(herokuDeployService.run).toBeCalled(); expect(output.success).toBe(false); }); + + it('can run with the minimum required options and return true', async () => { + const opts: DeployExecutorSchema = { + config: ['development'], + org: 'my-org', + buildPacks: [], + apiKey: 'heroku-user-api-key', + email: 'heroku-user-email', + watchDelay: 0, + }; + herokuDeployService.run = jest.fn(); + // + const output = await executor(opts, context); + // + expect(herokuDeployService.run).toBeCalled(); + expect(output.success).toBe(true); + }); }); diff --git a/packages/nx-heroku/src/executors/deploy/schema.json b/packages/nx-heroku/src/executors/deploy/schema.json index c8432c1..c71cf44 100644 --- a/packages/nx-heroku/src/executors/deploy/schema.json +++ b/packages/nx-heroku/src/executors/deploy/schema.json @@ -142,7 +142,8 @@ "description": "Webhook secret to override the one autogenerated by Heroku during webhook registration" } }, - "required": ["url", "include", "level"] + "$comment": "https://github.com/nrwl/nx/issues/23153", + "shouldBeRequired": ["url", "include", "level"] }, "drain": { "description": "Log drain to register on Heroku, see https://devcenter.heroku.com/articles/log-drains", @@ -163,7 +164,8 @@ "type": "string" } }, - "required": ["url"] + "$comment": "https://github.com/nrwl/nx/issues/23153", + "shouldBeRequired": ["url"] }, "branch": { "description": "The branch that you would like to deploy to Heroku. Defaults to 'HEAD'",