You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Bitbucket Pipelines中Jest setupFiles配置无法找到模块求助

Bitbucket Pipelines运行Jest单元测试路径错误排查

问题现象

运行Jest单元测试时抛出路径错误:

Validation Error:
Module ..\test\EnvironmentalVars.ts in the setupFiles option was not found.
     <rootDir> is: /opt/atlassian/pipelines/agent/build/main

现有配置及尝试

初始Jest配置:

"setupFiles": [
    "..\\test\\EnvironmentalVars.ts"
]

已尝试的修改:

"setupFiles": [
    "<rootdir>\\test\\EnvironmentalVars.ts"
]

已知背景

  • 目标文件EnvironmentalVars.ts确实存在
  • 已尝试使用<rootDir>标记、切换正斜杠/反斜杠,均无效
  • 本地环境运行完全正常

解决方法

1. 修正路径语法与<rootDir>大小写

Bitbucket Pipelines基于Linux容器运行,仅识别正斜杠,且<rootDir>是大小写敏感的(必须大写D)。修改配置为:

"setupFiles": [
    "<rootDir>/../test/EnvironmentalVars.ts"
]

该路径从<rootDir>(即/opt/atlassian/pipelines/agent/build/main)向上跳转一级,再进入test目录,匹配文件实际位置。

2. 确认目录结构(可选)

若仍存疑,可在bitbucket-pipelines.yml中添加步骤打印目录结构,验证test与main的位置关系:

- step:
    name: 检查目录结构
    script:
        - ls -la /opt/atlassian/pipelines/agent/build

3. 检查文件大小写

Linux环境大小写敏感,需确保配置中的文件名、目录名与实际完全一致(比如EnvironmentalVars.ts不能写成environmentalvars.ts)。

内容的提问来源于stack exchange,提问作者meh93

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 10:12:15