Skip to content

Commit

Permalink
Add tests and automated publishing the package to NPM (#96)
Browse files Browse the repository at this point in the history
* Add Jest tests

* Address comments by Joel Denning

* Add more tests

* Fix setDocumentAndLoadScript

* Add tests for external maps

* Add automated release workflow

* Adapt changeset config

* Fix access for changeset config

* Address comments

* Revert addition of an empty line

* Revert fix on build error

---------

Co-authored-by: Roberto Mosca <[email protected]>
  • Loading branch information
robmosca and Roberto Mosca authored Oct 18, 2023
1 parent 3b1308b commit cd137ce
Show file tree
Hide file tree
Showing 19 changed files with 8,322 additions and 1,655 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
14 changes: 14 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": [
"@changesets/changelog-github",
{ "repo": "single-spa/import-map-overrides" }
],
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "origin/main",
"updateInternalDependencies": "patch",
"ignore": []
}
5 changes: 5 additions & 0 deletions .changeset/fast-chairs-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"import-map-overrides": patch
---

Add tests on API and automate release flow
83 changes: 83 additions & 0 deletions .github/workflows/build-test-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Build, Test, Release

on:
push:
branches: main
pull_request:
branches: "*"

jobs:
build_lint_test:
name: Build, Lint, and Test
runs-on: ubuntu-latest

steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
# check out full history
fetch-depth: 0

- name: Install Pnpm
uses: pnpm/[email protected]
with:
version: 8.8.0

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Validate
run: |
pnpm run lint
pnpm run check-format
pnpm exec changeset status --since=origin/main
- name: Test
run: pnpm run test

- name: Build
run: pnpm run build

release:
name: Release
needs: build_lint_test
permissions:
contents: write # To push release tags
pull-requests: write # To create release pull requests
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/main' }}
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Install Pnpm
uses: pnpm/[email protected]
with:
version: 8.8.0

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: pnpm

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build
run: pnpm run build

- name: Create Release Pull Request or Publish to NPM
id: changesets
uses: changesets/action@v1
with:
publish: pnpm run release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 2 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
. "$(dirname "$0")/_/husky.sh"

pnpm exec concurrently pnpm:lint "pretty-quick --staged"
pnpm run test --coverage --watchAll=false

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ The UI for import-map-overrides works in evergreen browsers (web components supp
- [Installation](/docs/installation.md#node)
- [API](/docs/api.md#node)

## Contributing

Make sure you commit a changeset with `pnpm changeset` before you open a PR.
This will allow to automatically bump the version and maintain the CHANGELOG
once released.
8 changes: 8 additions & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('jest').Config} */
module.exports = {
collectCoverageFrom: ["src/**/*.js", "!src/api/local-storage-mock.js"],
resetMocks: true,
restoreMocks: true,
setupFiles: ["./jest.setup.js"],
testEnvironment: "jsdom",
};
3 changes: 3 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import jestFetchMock from "jest-fetch-mock";

jestFetchMock.enableMocks();
31 changes: 21 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@
"scripts": {
"build": "pnpm run clean && cross-env NODE_ENV=production rollup -c",
"build:dev": "pnpm run clean && cross-env NODE_ENV=development rollup -c",
"clean": "rimraf dist",
"check-format": "prettier --check src",
"clean": "rimraf dist",
"watch": "cross-env NODE_ENV=development rollup -c --watch",
"copy-test-files": "copyfiles test/**/* dist -f",
"test-serve": "serve .",
"test-embed-serve": "serve . -l 3333",
"test": "concurrently pnpm:watch pnpm:copy-test-files pnpm:test-serve pnpm:test-embed-serve",
"serve": "serve . -l 5050",
"embed-serve": "serve . -l 3333",
"test": "jest",
"lint": "eslint src",
"prepublishOnly": "pnpm run build",
"prepare": "husky install"
"prepare": "husky install",
"changeset": "changeset",
"release": "changeset publish"
},
"exports": {
"node": "./dist/import-map-overrides-server.js",
Expand All @@ -41,27 +43,36 @@
"@babel/plugin-proposal-class-properties": "^7.14.5",
"@babel/plugin-transform-react-jsx": "^7.14.5",
"@babel/preset-env": "^7.14.8",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-node-resolve": "^13.0.2",
"@testing-library/jest-dom": "^6.0.0",
"babel-jest": "^29.6.2",
"concurrently": "^6.2.0",
"copyfiles": "^2.3.0",
"cross-env": "^7.0.2",
"copyfiles": "^2.4.1",
"cross-env": "^7.0.3",
"eslint": "^7.31.0",
"eslint-config-important-stuff": "^1.1.0",
"eslint-plugin-es5": "^1.5.0",
"husky": "^7.0.0",
"husky": "^7.0.1",
"jest": "^29.5.0",
"jest-cli": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"jest-fetch-mock": "^3.0.3",
"postcss": "^8.3.5",
"preact": "^10.5.14",
"prettier": "^2.3.2",
"pretty-quick": "^3.1.1",
"regenerator-runtime": "^0.13.11",
"rimraf": "^3.0.2",
"rollup": "^2.53.2",
"rollup-plugin-postcss": "^4.0.0",
"rollup-plugin-terser": "^7.0.2",
"serve": "^12.0.0"
"serve": "^14.2.1"
},
"dependencies": {
"cookie": "^0.4.1"
},
"packageManager": "pnpm@8.4.0"
"packageManager": "pnpm@8.8.0"
}
Loading

0 comments on commit cd137ce

Please sign in to comment.