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 tests and automated publishing the package to NPM #95

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/single-spa-react" }
],
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"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
5 changes: 5 additions & 0 deletions .changeset/plenty-nails-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"import-map-overrides": patch
---

Add automation to publish package
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.6.9

- 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.6.9

- 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: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ dist
/.idea

# VSCode IDE files
.vscode
/.vscode
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();
35 changes: 23 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "import-map-overrides",
"version": "3.0.0",
"version": "3.1.0",
"main": "dist/import-map-overrides-server.js",
"type": "module",
"repository": "https://github.com/joeldenning/import-map-overrides.git",
Expand All @@ -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"
"cookie": "^0.5.0"
},
"packageManager": "pnpm@8.4.0"
"packageManager": "pnpm@8.6.9"
}
Loading