I am trying to run jest for a monorepo project maintained by lerna in the github actions.
name: Run Unit Test
on:
push:
branches:
- master
- dev
pull_request:
branches:
- master
- dev
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Cache node modules
uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install Dependencies
run: npm -v && npm install
- name: Run Unit Test
run: npm run test
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
I got jest: not found
error when run test in github actions.
you can see the error logs here. But when I run npm install
and npm run test
in my own macOs, everything works fine.
and this is my package.json of root:
{
"private": true,
"description": "a progressive micro frontend library",
"workspaces": [
"packages/*"
],
"scripts": {
"postinstall": "lerna bootstrap",
"bootstrap": "lerna bootstrap",
"clean": "lerna clean",
"test": "lerna run test --stream",
"build": "lerna run build --stream",
"commit": "git cz",
"lint": "lerna run lint --stream",
"publish": "lerna publish",
"docs": "docsify serve docs"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ObviousJs/obvious.git"
},
"author": "Philip Lau",
"license": "MIT",
"bugs": {
"url": "https://github.com/ObviousJs/obvious/issues"
},
"homepage": "https://github.com/ObviousJs/obvious#readme",
"publishConfig": {
"access": "public"
},
"config": {
"commitizen": {
"path": "node_modules/cz-conventional-changelog"
}
},
"devDependencies": {
"@rollup/plugin-commonjs": "20.0.0",
"@rollup/plugin-node-resolve": "13.0.4",
"@typescript-eslint/eslint-plugin": "4.31.0",
"@typescript-eslint/parser": "4.31.0",
"commitizen": "4.2.4",
"cz-conventional-changelog": "3.3.0",
"docsify-cli": "4.4.3",
"eslint": "7.32.0",
"eslint-config-standard": "16.0.3",
"eslint-plugin-import": "2.24.2",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-promise": "5.1.0",
"husky": "4.3.8",
"lerna": "4.0.0",
"rollup": "2.56.3",
"rollup-plugin-typescript2": "0.30.0"
},
"husky": {
"hooks": {
"pre-commit": "npm run lint && npm run build && git add ./"
}
}
}
this is the package.json of sub project:
{
"name": "@obvious/core",
"version": "0.4.0",
"description": "a progressive micro front framework",
"main": "./dist/index.umd.js",
"module": "./dist/index.es.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "rollup -c rollup.config.js",
"lint": "eslint --fix --ext .ts,.js test",
"test": "jest --coverage"
},
"author": "Philip Lau",
"license": "MIT",
"dependencies": {
"@vue/reactivity": "3.2.10",
"tslib": "2.3.1"
},
"devDependencies": {
"@types/jest": "27.0.1",
"jest": "27.1.1",
"nock": "13.1.3",
"node-fetch": "2.6.2",
"ts-jest": "27.0.5",
"typescript": "4.4.3"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ObviousJs/obvious-core.git"
},
"bugs": {
"url": "https://github.com/ObviousJs/obvious-core/issues"
},
"homepage": "https://github.com/ObviousJs/obvious-core#readme"
}
my github repo address is https://github.com/ObviousJs/obvious-core.
sorry for my pool english but I really need some help (orz
I finally solved this problem by setting
useWorkspaces: false
in lerna.json
the reason is that npm6.x doesn't support workspace. And the npm version of github-action runner is just v6, so the workspaces
in package.json is useless, so we should set useWorkspaces
in lerna.json to false