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 for api #87

Closed
wants to merge 5 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
28 changes: 28 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build and Test

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

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-node@v2
with:
node-version: "16"
- uses: pnpm/[email protected]
with:
version: 8.4.0
- run: git checkout main && git checkout $GITHUB_SHA
- run: pnpm install --frozen-lockfile
- run: pnpm run build
- run: pnpm run lint
robmosca marked this conversation as resolved.
Show resolved Hide resolved
- run: pnpm run check-format
- run: pnpm run test
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
10 changes: 10 additions & 0 deletions jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import('jest').Config} */
const config = {
resetMocks: true,
restoreMocks: true,
setupFiles: ["./jest.setup.js"],
testEnvironment: "jsdom",
collectCoverageFrom: ["src/**/*.js", "!src/api/localStorageMock.js"],
};

module.exports = config;
1 change: 1 addition & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("jest-fetch-mock").enableMocks();
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 is needed in order to safely mock fetch (for testing external maps)

18 changes: 12 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
"scripts": {
"build": "pnpm run clean && cross-env NODE_ENV=production rollup -c",
"build:dev": "pnpm run clean && cross-env NODE_ENV=development rollup -c",
"check-format": "prettier --check src",
"clean": "rimraf dist",
"check-format": "prettier --check src",
"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 .",
"embed-serve": "serve . -l 3333",
"test": "jest",
"lint": "eslint src",
"prepublishOnly": "pnpm run build",
"prepare": "husky install"
Expand Down Expand Up @@ -44,16 +45,21 @@
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-node-resolve": "^13.0.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",
Expand Down
Loading