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

Add high-level tests #92

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Add high-level tests #92

wants to merge 3 commits into from

Conversation

mcmire
Copy link
Contributor

@mcmire mcmire commented Jun 3, 2022

This commit adds tests which exercise the behavior of the script that
powers the majority of this action. It does this by using real Git repos
and testing the contents of real files instead of mocking out commands
and access to the filesystem.

The tests in this commit should cover all of the happy paths provided
directly by this action, as well as some behavior offered by
@metamask/auto-changelog is also covered, because it seemed to make
sense when thinking about how this action "should" work from a high
level.


The new file that this introduces, high-level.test.ts, has a lot of tests in it, and so it can be quite intimidating to review. That said, a lot of the tests repeat themselves. I would recommend running yarn test and looking at the describes and its to get an idea of the structure. For more help, however, here are some of the high points:

  • The behavior for a polyrepo is very simple compared to a monorepo, as we only need update the version and the changelog. So the behavior mentioned below is only for monorepos.
  • There are different ways to release (you can specify an exact version, or you can specify a diff (major, minor, patch), and the new version can either be within 0.x or past 0.x. These affect the behavior in that if the new version is 1.x or greater and is a minor or patch bump away from the current version, then only the packages in the monorepo will get bumped and have their changelogs updated which have changed since their last release, whereas if the version is within 0.x or is a major bump from the current version, all packages will get bumped and have their changelogs updated, regardless of whether they've changed.

@mcmire mcmire changed the base branch from main to compile-ts-to-cjs June 3, 2022 20:04
@mcmire mcmire marked this pull request as ready for review June 3, 2022 20:27
@mcmire mcmire requested a review from a team as a code owner June 3, 2022 20:27
[InputKeys.ReleaseVersion]: string;
}
}
interface ActionEnv extends NodeJS.ProcessEnv {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was changed because we access process.env in some of the setup code the new tests and these ambient types were confusing TypeScript. We don't need to modify the global ProcessEnv type; we just need to get TypeScript to see process.env in a certain light when we are accessing it in this file.

@@ -21,5 +21,5 @@ module.exports = {
restoreMocks: true,
testEnvironment: 'node',
testRegex: ['\\.test\\.(ts|js)$'],
testTimeout: 2500,
testTimeout: 5000,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've raised the timeout globally because many of the high level tests may take more than 2.5s to run (due to the fact that we are shelling out and because the main script itself takes about a half a second to run).

@@ -0,0 +1,128 @@
import path from 'path';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried to leave comments describing what each thing does, but here is a high level:

  • To set up a test, we need to create two repos. We will use one repo to run the action script, but we also need another repo that the first one can talk to so that the action script can run git fetch --tags.
  • The collection of these repos is called an environment and are kept in a directory within a temporary location. The environment is cleared and recreated before each test.
  • There are two types of Environment classes, one which is specialized to initialize a polyrepo and one to initialize a monorepo. These have different characteristics, so there are two kinds of Repo classes as well.

@mcmire mcmire force-pushed the add-high-level-tests branch 2 times, most recently from a196974 to 6b1556b Compare June 23, 2022 21:15
Base automatically changed from compile-ts-to-cjs to main June 24, 2022 16:31
This commit adds tests which exercise the behavior of the script that
powers the majority of this action. It does this by using real Git repos
and testing the contents of real files instead of mocking out commands
and access to the filesystem.

The tests in this commit should cover all of the happy paths provided
directly by this action, as well as some behavior offered by
`@metamask/auto-changelog` is also covered, because it seemed to make
sense when thinking about how this action "should" work from a high
level.
legobeat
legobeat previously approved these changes Sep 1, 2023
Copy link
Contributor

@legobeat legobeat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs conflict-resolution of yarn.lock; LGTM otherwise from a quick look!

package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@mcmire
Copy link
Contributor Author

mcmire commented Sep 1, 2023

Done!

@socket-security
Copy link

New dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
ts-node 10.9.1 filesystem, environment +13 1.84 MB cspotcode
deepmerge 4.3.1 None +0 31.2 kB tehshrike

@socket-security
Copy link

socket-security bot commented Sep 1, 2023

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

Ignoring: ts-node@10.9.1, acorn-walk@8.2.0, yn@3.1.1, @cspotcode/source-map-support@0.8.1, arg@4.1.3, v8-compile-cache-lib@3.0.1, create-require@1.1.1, @tsconfig/node10@1.0.8

Next steps

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of package-name@version specifiers. e.g. @SocketSecurity ignore foo@1.0.0 bar@* or ignore all packages with @SocketSecurity ignore-all

@legobeat

This comment was marked as resolved.

@legobeat

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants