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 Jest tests and publish automation with changesets #10

Closed
wants to merge 2 commits into from

Conversation

robmosca
Copy link

This PR addresses issues:

In particular:

  • I added Jest tests covering 100% of the code
  • I included automation for running Jest tests
  • I included a command for type checking with Typescript and fixed a minor type problem with the window object
  • I included changesets
  • I included automation of deployments through changesets and the changesets release action for GitHub

For this to work it is necessary that:

  1. The GITHUB_TOKEN is granted permissions to create and approve pull requests. This can be done in Settings -> Actions -> General -> Workflow permissions -> Allow GitHub Actions to create and approve pull requests
  2. The maintainers create an NPM_TOKEN secret with an NPM token with write permissions to the organization (or at least the corresponding package, for publishing).

See single-spa/single-spa-react#178 for a description of how this works.

The automated pipeline includes:

  • running the tests
  • checking the format
  • checking the types
  • running the linter

Current coverage:
Screenshot 2023-09-11 at 17 02 41

@robmosca robmosca changed the title Issue 4 automate tests Add Jest tests and publish automation with changesets Oct 12, 2023
@@ -31,7 +31,7 @@ injectorImportMaps.forEach((scriptEl) => {
return r.json();
} else {
throw Error(
`${errPrefix} import map at url '${scriptEl.src}' must respond with a success HTTP status, but responded with HTTP ${r.status} ${r.statusText}`,
`${errPrefix} Import map at url '${scriptEl.src}' must respond with a success HTTP status, but responded with HTTP ${r.status} ${r.statusText}`,
Copy link
Author

Choose a reason for hiding this comment

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

To harmonize the casing to the other error messages

@@ -69,8 +69,12 @@ const requiresMicroTick = importMapJsons.some(
(json) => json instanceof Promise,
);

const globalWindow = window as typeof window & {
Copy link
Author

Choose a reason for hiding this comment

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

Needed by Typescript (otherwise throws a type error)

@@ -112,3 +116,5 @@ function injectImportMap(importMaps: ImportMap[]): void {
finalImportMapScriptEl.textContent = JSON.stringify(finalImportMap);
document.head.appendChild(finalImportMapScriptEl);
}

export {};
Copy link
Author

Choose a reason for hiding this comment

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

Needed in order to be able to import the module in Jest. Otherwise, it complains the file is not a module.

Copy link
Member

@joeldenning joeldenning left a comment

Choose a reason for hiding this comment

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

Is it possible to make changesets automatically publish without creating another PR? I don't want changeset-bot to spam my Github notifications.

@robmosca
Copy link
Author

Is it possible to make changesets automatically publish without creating another PR? I don't want changeset-bot to spam my Github notifications.

I don’t know if it is possible to publish automatically when merging, I can investigate, but I would recommend against it.
Having the new PR being opened allows us to have some time to really check that the changes are OK and also allows to avoid republishing every minor change that we merge to main, making our releases more meaningful.
It is just one PR, not that many, and the only thing one has to do is to merge that PR when ready to publish. I wouldn’t consider that too much of a hassle, considering the advantage it gives in controlling your publishing strategy.

@robmosca robmosca requested a review from joeldenning October 20, 2023 07:33
@joeldenning
Copy link
Member

joeldenning commented Oct 24, 2023

I don’t know if it is possible to publish automatically when merging, I can investigate, but I would recommend against it.

I have significantly more Github notifications than I can manage already. Creating a new PR after every merged pull request will result in an extra notification every time I approve and merge anything. We should look into whether it can be done without an extra pull request. I never asked for autopublishes to be added to all the repos, and it has caused problems in other repos already. If I get more time later, I'll look into the changeset documentation to see if we can avoid adding busy work merging another PR to my Github queue.

@robmosca robmosca closed this Oct 25, 2023
@robmosca
Copy link
Author

robmosca commented Oct 25, 2023

I don’t know if it is possible to publish automatically when merging, I can investigate, but I would recommend against it.

I have significantly more Github notifications than I can manage already. Creating a new PR after every merged pull request will result in an extra notification every time I approve and merge anything. We should look into whether it can be done without an extra pull request. I never asked for autopublishes to be added to all the repos, and it has caused problems in other repos already. If I get more time later, I'll look into the changeset documentation to see if we can avoid adding busy work merging another PR to my Github queue.

It was not a PR for every merged pull request. It's just one PR for release, that is updated every time a new merge to main happens. This is a well-established flow defined by changeset.
In any case, closing this PR.

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

Successfully merging this pull request may close these issues.

2 participants