actions / create-github-app-token

GitHub Action for creating a GitHub App Installation Access Token
https://github.com/marketplace/actions/create-github-app-token
MIT License
344 stars 47 forks source link

Add integration tests for `main.js` #56

Closed smockle closed 11 months ago

smockle commented 11 months ago

Part of https://github.com/actions/create-github-app-token/issues/43

This PR adds tests for main.js, similar to the tests that already exist for post.js.

Specifically, it tests that:

Architecturally, in order to keep individual tests concise, this PR adds tests/main.js, which:

The tests/main-token-get-*.test.js test files run tests/main.js with various scenario-specific callback functions.

smockle commented 11 months ago

I prefer we don't use any module mocking…

👍 Cool; removed esmock and tests using module mocks, in https://github.com/smockle/create-github-app-token/pull/56/commits/60504269230a68706c8bf9ed9e40ced513146235.

…instead mock all requests and capture and snapshot all logs / thrown errors.…

I added a happy path test (that mocks requests and validates stdout), in https://github.com/smockle/create-github-app-token/pull/56/commits/43f24998742aeb378c1e91e0fe6a0d790a0a6b92. @gr2m, is that what you had in mind?

gr2m commented 11 months ago

I added a happy path test (that mocks requests and validates stdout), in 43f2499. @gr2m, is that what you had in mind?

Yes, I just looked at it, looks good 👍🏼 Thank you!

smockle commented 11 months ago

This PR is in draft, but as a quick update: After rebasing, npm test exits with an error. I’m working on debugging that.

smockle commented 11 months ago

🤔 I’m not sure why the test / Integration (pull_request) check is failing; npm test passes on my machine.

Update: Ah, I now suspect the issue is that @actions/core performs differently in the Actions runner environment, vs locally, i.e. logs different things.

Update: Yup, that was indeed the root of the issue. Fixed in https://github.com/actions/create-github-app-token/pull/56/commits/10b4ea239df850e8fb91ed8e44cfca3c2a3ecd89.

Excerpt from the logs: ``` Run npm test > create-github-app-token@1.4.0 test > ava tests/index.js ✔ post-token-unset.test.js (669ms) ✔ main-missing-repository.test.js (823ms) ✔ main-missing-owner.test.js (1s) ✔ post-token-skipped.test.js (1s) ✔ post-token-set.test.js (1.2s) ✘ [fail]: main-token-get-owner-set-repo-set-to-one.test.js stdout ✘ [fail]: main-token-get-owner-set-to-org-repo-unset.test.js stdout ✘ [fail]: main-token-get-owner-set-repo-set-to-many.test.js stdout ✘ [fail]: main-token-get-owner-set-to-user-repo-unset.test.js stdout ✘ [fail]: main-token-get-owner-unset-repo-set.test.js stdout ✘ [fail]: main-token-get-owner-unset-repo-unset.test.js stdout ─ main-token-get-owner-set-repo-set-to-one.test.js tests/index.js:12 11: t.snapshot(stderr, "stderr"); 12: t.snapshot(stdout, "stdout"); 13: }); stdout Difference (- actual, + expected): `owner and repositories set, creating token for repositories "actions/create-github-app-token" owned by "actions"␊ - ::add-mask::` + ::add-mask::␊ + ␊ + ::set-output name=token::␊ + ::save-state name=token::` › file://tests/index.js:12:7 ```
smockle commented 11 months ago

Update: Ah, I now suspect the issue is that @actions/core performs differently in the Actions runner environment, vs locally, i.e. logs different things.

That may be why some projects mock core in their tests, e.g. actions/checkout. Semi-related: https://github.com/actions/toolkit/issues/118.

smockle commented 11 months ago

Ah, no, actually, there’s a subtle bug with the code that returns an installation access token (it’s missing the response header that makes it an object). The runner warns about this; local does not. That’s probably the source of the error.

Update: Fixed this in https://github.com/actions/create-github-app-token/pull/56/commits/1174dffe76b61cd790fb19509a55798c3e502285 and https://github.com/actions/create-github-app-token/pull/56/commits/73aade40a73493ad1ca8464a050882453ed10b9e.

create-app-token-action-releaser[bot] commented 11 months ago

:tada: This PR is included in version 1.5.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: