gitlab-ci 在 monorepo 中与 interdependencies 开玩笑
gitlab-ci jest in monorepo with interdependencies
我正在使用 jest 在我的 monorepo 中进行 运行 测试。
这些测试与 monorepo 的其他子包相互依赖ci。
本地一切正常。
但是 gitlab-ci 管道失败了,因为它无法解决 interdependencies...
简化的项目结构:
packages
-core
--src
---core.js
--package.json
-advanced
--src
---advanced.js
---advanced.test.js
--package.json
.gitlab-ci.yml
jest.config.js
package.json
简化jest.config.js:
module.exports = {
projects: ['packages/*'],
rootDir: __dirname,
roots: ['<rootDir>/packages'],
testMatch: ['**/*.test.js'],
}
简化core/package.json:
{
"name": "@myProject/core",
"version": "1.0.0"
}
简化advanced/package.json:
{
"name": "@myProject/advanced",
"version": "1.0.0",
"dependencies": {
"@myProject/core": "^1.0.0"
}
}
简化advanced.test.js:
import thisthat from 'randomBibX'
import others from 'randomBibY'
import core from '@myproject/core'
//doTests
简化package.json:
{
"scripts": {
"test": "jest"
}
"devDependencies": {
"randomBibX": "^1.0.0",
"randomBibY": "^1.0.0"
}
}
简化.gitlab-ci.yml:
image: node:10
stages:
- setup
- test
setup:
stage: setup
script:
- yarn config set cache-folder /cache/.yarn
- yarn install --non-interactive --frozen-lockfile
artifacts:
expire_in: 1hour
paths:
- node_modules
- "packages/*/node_modules"
jest:
stage: test
dependencies:
- setup
script:
- "[ ! -d node_modules/ ] && yarn install --non-interactive --frozen-lockfile"
- yarn test
错误:
FAIL packages/advanced/src/advanced.test.js
● Test suite failed to run
Cannot find module '@myProject/core' from 'advanced.test.js'
解决方案是,在测试之前构建项目
改进.gitlab-ci.yml:
image: node:10
stages:
- setup
- test
installAndBuild:
stage: setup
script:
- yarn config set cache-folder /cache/.yarn
- yarn install --non-interactive --frozen-lockfile
- yarn lerna run build --stream
artifacts:
expire_in: 1hour
paths:
- node_modules
- "packages/*/node_modules"
jest:
stage: test
dependencies:
- installAndBuild
script:
- "[ ! -d node_modules/ ] && yarn install --non-interactive --frozen-lockfile"
- yarn test
我正在使用 jest 在我的 monorepo 中进行 运行 测试。 这些测试与 monorepo 的其他子包相互依赖ci。
本地一切正常。 但是 gitlab-ci 管道失败了,因为它无法解决 interdependencies...
简化的项目结构:
packages
-core
--src
---core.js
--package.json
-advanced
--src
---advanced.js
---advanced.test.js
--package.json
.gitlab-ci.yml
jest.config.js
package.json
简化jest.config.js:
module.exports = {
projects: ['packages/*'],
rootDir: __dirname,
roots: ['<rootDir>/packages'],
testMatch: ['**/*.test.js'],
}
简化core/package.json:
{
"name": "@myProject/core",
"version": "1.0.0"
}
简化advanced/package.json:
{
"name": "@myProject/advanced",
"version": "1.0.0",
"dependencies": {
"@myProject/core": "^1.0.0"
}
}
简化advanced.test.js:
import thisthat from 'randomBibX'
import others from 'randomBibY'
import core from '@myproject/core'
//doTests
简化package.json:
{
"scripts": {
"test": "jest"
}
"devDependencies": {
"randomBibX": "^1.0.0",
"randomBibY": "^1.0.0"
}
}
简化.gitlab-ci.yml:
image: node:10
stages:
- setup
- test
setup:
stage: setup
script:
- yarn config set cache-folder /cache/.yarn
- yarn install --non-interactive --frozen-lockfile
artifacts:
expire_in: 1hour
paths:
- node_modules
- "packages/*/node_modules"
jest:
stage: test
dependencies:
- setup
script:
- "[ ! -d node_modules/ ] && yarn install --non-interactive --frozen-lockfile"
- yarn test
错误:
FAIL packages/advanced/src/advanced.test.js
● Test suite failed to run
Cannot find module '@myProject/core' from 'advanced.test.js'
解决方案是,在测试之前构建项目
改进.gitlab-ci.yml:
image: node:10
stages:
- setup
- test
installAndBuild:
stage: setup
script:
- yarn config set cache-folder /cache/.yarn
- yarn install --non-interactive --frozen-lockfile
- yarn lerna run build --stream
artifacts:
expire_in: 1hour
paths:
- node_modules
- "packages/*/node_modules"
jest:
stage: test
dependencies:
- installAndBuild
script:
- "[ ! -d node_modules/ ] && yarn install --non-interactive --frozen-lockfile"
- yarn test