javascript - Gitlab CI 打破单元测试
问题描述
我的两个测试在本地通过,但在 GitlabCI 上没有通过,对于我来说,我无法弄清楚为什么。
我在这里读到macOS 不区分大小写,而 ci 可能是,所以我仔细检查了所有的拼写,一切看起来都很好。
这是文件系统布局:
src/
App.jsx
App.test.jsx
components/
A/
index.js
B/
C/
CContainer.jsx
CContainer.test.jsx
下面是错误代码:
FAIL src/components/A/B/C/CContainer.test.jsx
● Test suite failed to run
Cannot find module './CContainer' from 'CContainer.test.jsx'
at Resolver.resolveModule (../../../tmp/node_modules/jest-resolve/build/index.js:179:17)
at Object.<anonymous> (src/components/A/B/C/CContainer.test.jsx:3:29)
我的代码来自CContainer.test.jsx
:
import React from 'react';
import { shallow } from 'enzyme';
import { CContainer } from './CContainer';
const props = {
saveTempUser: () => '',
history: {},
user: {},
};
it('renders without crashing', () => {
shallow(<CContainer {...props} />);
});
这两个文件是兄弟姐妹,CContainer
很简单:
...
export class CContainer extends Component {
...
}
...
export default connect(mapStateToProps, mapDispatchToProps)(CContainer)
奇怪的是在顶层App.test.js
,同一个文件会导致问题:
FAIL src/App.test.js
● Test suite failed to run
Cannot find module './B/C/CContainer' from 'index.js'
at Resolver.resolveModule (../../../tmp/node_modules/jest-resolve/build/index.js:179:17)
at Object.<anonymous> (src/components/A/index.js:4:29)
而且index.js
只是:
import ConnectedCContainer, { CContainer} from './B/C/CContainer'
...
export {
...
ConnectedCContainer,
CContainer
}.
有任何想法吗?我目前正在配置一个本地运行器来尝试调试,当我有一些信息时会回来提供更多信息。
解决方案
事实证明,文件的情况与 git 中的不同。从 git 中删除文件并添加具有所需案例的新文件解决了问题。
推荐阅读
- php - PHP:尝试在多维数组中按值查找键,但不能正常工作
- ruby-on-rails - 如何推理枚举的级别
- git - 忽略整个目录树中所有扩展名为 .aux、.log 的文件
- excel - Excel VBA中的合并和总计
- c# - 使用 ASP.Net Core DI 的策略模式
- visual-studio - 使用 Microsoft.VisualStudio.TestTools.UnitTesting;
- angular6 - 通过点击事件上的选择器将数据从父级传递给子级
- java - 初始化复杂过滤器时出错。从 Kotlin 运行 ffmpeg 时出现无效参数错误
- node.js - 如何让函数在 Node Js 和 MySQL 中同时退出触发?
- elixir - 如何解析子字段以便将可选参数添加到 HTTP 查询?