如果您遇到缺少console.log
输出的问题,请尝试 Jest 24
从问题 #2441 分支
@cpojer我没有看到使用此设置(macOS)的任何 console.log 输出:
$ node --version
v7.4.0
package.json
:
{
"dependencies": {
"@types/jest": "19.2.4",
"jest": "20.0.4",
"ts-jest": "20.0.6",
"typescript": "2.3.4"
}
}
__tests__/jestconfig.json
:
{
"rootDir": "../",
"globals": {
"__TS_CONFIG__": {}
},
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json"
],
"transform": {
"\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest/preprocessor.js"
},
"testRegex": "__tests__/.*test_.*\\.(ts|tsx|js)$"
__tests__/test_foo.ts
:
import {} from 'jest';
console.log('CONSOLE before test');
test('fail', () => {
console.log('CONSOLE inside test');
expect(true).toEqual(false);
console.log('CONSOLE end of test');
})
__tests__/test_bar.js
:
console.log('BAR CONSOLE before test');
test('fail', () => {
console.log('BAR CONSOLE inside test');
expect(true).toEqual(false);
console.log('BAR CONSOLE end of test');
})
$ jest -c __tests__/jestconfig.json
FAIL __tests__/test_foo.ts
● fail
expect(received).toEqual(expected)
Expected value to equal:
false
Received:
true
at Object.<anonymous> (__tests__/test_foo.ts:6:16)
at Promise.resolve.then.el (node_modules/p-map/index.js:42:16)
FAIL __tests__/test_bar.js
● fail
expect(received).toEqual(expected)
Expected value to equal:
false
Received:
true
at Object.<anonymous>.test (__tests__/test_bar.js:4:16)
at Promise.resolve.then.el (node_modules/p-map/index.js:42:16)
Test Suites: 2 failed, 2 total
Tests: 2 failed, 2 total
Snapshots: 0 total
Time: 1.379s
Ran all test suites.
单JS测试:
$ jest -c __tests__/jestconfig.json __tests__/test_bar.js
FAIL __tests__/test_bar.js
● fail
expect(received).toEqual(expected)
Expected value to equal:
false
Received:
true
at Object.<anonymous>.test (__tests__/test_bar.js:4:16)
at Promise.resolve.then.el (node_modules/p-map/index.js:42:16)
✕ fail (7ms)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 0.596s, estimated 1s
Ran all test suites matching "__tests__/test_bar.js".
单TS测试:
$ jest -c __tests__/jestconfig.json __tests__/test_foo.ts
FAIL __tests__/test_foo.ts
● fail
expect(received).toEqual(expected)
Expected value to equal:
false
Received:
true
at Object.<anonymous> (__tests__/test_foo.ts:6:16)
at Promise.resolve.then.el (node_modules/p-map/index.js:42:16)
✕ fail (116ms)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 1.27s
Ran all test suites matching "__tests__/test_foo.ts".
@thymikee知道为什么会这样吗?
不知道,但我会尽量减少这个例子,例如通过删除打字稿
我可以在没有 Typescript 的情况下进行复制
可以确认 Node 7.4 吃控制台日志,但它适用于 Node 7.5.0、7.10.0、8.0.0 和 8.1.2。
请升级您的节点版本。 结束
@thymikee目前的 LTS 版本 Node 6 怎么样? (看起来我也遇到了这个问题,虽然还没有充分调试它。但是,我现在仅限于 LTS 版本,所以无法升级)。
在 v6.11.0 上测试,仍然显示console.log
s。
啊,我可能遇到了其他问题。 谢谢, @thymikee ,我会再回去调试一下。
我在不知不觉中运行 Node 7.3.0(通过 n 的错误版本)并且它没有记录。 切换到 8.1.1 并再次记录。
@thymikee - 我不明白这是怎么解决的? ...我无法升级我的节点版本
我想我有点困惑这怎么会被认为是一个 Node 错误,至少与 Jest 本身无关。 使用 Node v7.4.0 和 Jest v19.0.2 我从我的测试中看到控制台日志记录。 简单地将 Jest 更新到 v20.0.4(不对任何其他配置进行任何更改)会导致控制台日志记录不再出现。 有什么我想念的吗?
@thymikee所以,我升级了我的节点版本,我在节点 8.2.1 Winx64 + Jest 20.0.4 上看不到控制台日志。 我现在必须使用后备
console.log = s => {
process.stdout.write(s + "\n");
};
而且我很确定它应该在 Jest 中修复,因为以前的版本没有这个问题。
@nowherenone你可以测试它是否发生在最新的 alpha 版本jest@test
上?
@thymikee刚刚在节点8.2.1
$ 上尝试使用jest@test
#$ 但结果相同。 console.log
语句总是被吞掉。
我认为这里的问题是 Jest 会缓冲消息,但有些东西会导致退出(或无限循环等)。 您需要使用--verbose
将消息直接打印到输出流。
这太荒谬了——我被@cpojer的大量无用回复(在我去的每一期和公关中)和试图把一切都放在其他人身上,就像我们不够聪明一样。
不要使用 Jest - 如果您想知道,这就是我的答案。 寻找新的测试框架。
describe('index', () => {
it('doesnt print anything', () => {
console.log('Hellllooo');
expect(true).toBe(true);
});
});
$ yarn test -- src/__tests__/index.spec.js --verbose
yarn test v0.27.5
warning package.json: No license field
$ jest "src/__tests__/index.spec.js" "--verbose"
PASS src/__tests__/index.spec.js
Index
✓ doesnt print anything (2ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 0.969s, estimated 2s
$ jest "--version"
v20.0.4
$ node --version
v7.4.0
我相信我只会被告知安装更新版本的 Node Lmao - 真是个笑话😂😂😂
@nf071590无法复制,可在 repl.it 上使用完全相同的 Jest 和 Node 版本: https ://repl.it/KYLc/0
在抱怨项目维护者之前,请拿出一个严肃的再现。
干杯!
不知道该怎么做。 我确实将您的示例粘贴到了一个文件中,然后运行了 Jest,它就像我的 Mac 上宣传的那样工作,并且在一分钟前使用了最新的 Jest 主版本。 看:
因为我在 Windows 上(节点 8.4,开玩笑 21.0.0-alpha.2),所以如果你不使用--verbose
console.log
s _sometimes_ 是隐藏的,但似乎一直显示用它。 当我得到一分钟时,很高兴使用节点 7 和稳定的笑话更新结果。
这里同样的问题。
describe('index', () => {
it('doesnt print anything', () => {
console.log('Hellllooo');
expect(true).toBe(true);
});
});
$ node --version
v7.4.0
$ jest "--version"
v21.1.0
目前在节点 v8.7.0 (npm v5.4.2) 上遇到同样的问题。
这仍然是一个问题
你能提供一个复制品吗?
FWIW,我最终来到这里是因为我遇到了完全相同的问题。 节点 v7.4.0。 升级了我的 Node 版本,并且console.log
现在按预期打印,即使没有--verbose
。 V7.4.0 可能不是唯一存在此问题的版本,但它似乎与版本相关,并且对于某些 Node 版本来说不是问题。 我现在在 Node v8.3.0 上,这似乎可以工作。
也就是说,在升级之前,我的版本与@nf071590相同,并且存在相同的问题。 我不确定为什么它不会在 repl.it 上发生,但这并不是只发生在他的电脑上的奇怪事情。
我可以用节点 8.9.0 和 jest 21.2.1、macOS 10.12.6 (16G1036) 重现这个
@SimenB我可以,但看起来这个问题在这里和其他地方已经被讨论到死了。 jest 的多(子)进程性质意味着它将覆盖console.logs
,并且不会进行不会改变的大规模重写。 任何来到这个线程并希望避免使用--verbose
标志不允许使用console.log
进行调试的问题的人,都应该使用--watch
标志。 这将避免子工作进程被覆盖,并允许您使用控制台日志查看详细输出。 --watch
非常快,并且通过将注意力集中在已更改的测试和代码上,通过仅运行保存时更改的那些测试来增加更多价值。
就我而言,我发现冗长的消息会吃掉一些但不是所有的console.log
消息。 我删除了详细选项,它似乎有点工作!
我刚刚将我的节点版本从 v6 升级到 v9,我的一个测试文件正在安慰。
几个星期以来,我一直在与这个问题作斗争。 我很高兴它现在有效
--verbose
与--forceExit
结合使用时,问题仍然存在 - 我认为原因是console.log
输出到stdout
而 jest 写入stderr
并且当--forceExit
可能仍然有stdout
中的内容不会被刷新
我找到了以下解决方案(不需要--verbose
)来修复 console.log 不显示和/或 console.log 被缓冲而不是实时显示
命令jest .... --forceExit --setupTestFrameworkScriptFile ./src/tests/jestShim.js
jestShim.js
的内容
const { Console } = require('console');
global.console = new Console(process.stderr, process.stderr);
同样的问题 - 永远不会看到 console.log 输出。
Node 9.80
Jest 22.4.2
Mac OS 10.13.3
这里建议的解决方法中没有一种对我有用。
与往常一样,请创建一个我们可以下拉测试的复制品。 我还没有遇到这个问题,所以我不知道如何开始修复它
@ledbit的解决方法对我有用
NPM 5.3.0
开玩笑 22.4.3
我仍然处于需要复制的地步。
--forceExit
似乎有点坏了,但是我在不使用该标志时没有遇到它
[使用react-scripts
forked 使用最新的 Jest v23.0.0, node v8.11.2]
我终于通过使用特定字符串(例如@@@
)标记每个日志并运行来显示日志:
yarn test --verbose | grep '@@@'
这是一个可怕的 hack(您失去了所有控制台着色,但您仍然看到测试失败和最终测试摘要),但这是迄今为止唯一有效的方法。 我在上面的评论中尝试了其他所有内容。 请注意,此解决方案需要--verbose
参数(并且它通过react-scripts
与--watch
隐式结合)。
这仍然是一个问题。 我在节点 10.1.0 上使用 jest v22.4.3,我只看到我的应用程序的第一个 console.log 语句,其余的都被忽略了。 当我将日志库设置为流式传输到标准输出时,我可以看到一些日志,但它们没有以正确的顺序出现。
Jest 作为测试运行者的工作是帮助我们调试和修复我们的代码。 如果没有日志,那根本无法实现。
@thymikee请重新打开这个问题
@thanpolas随时使用显示错误的存储库创建一个新问题,以便我们进行调查:)。 另外,请使用 Jest 23,因为这是最新的。
我发现了我的问题,日志记录是通过流式传输到标准输出的记录器进行的,当重定向到 console.log 时,我忘记调用流写入器回调,因此流停止发送日志。
对于它的价值,我已经看到了 Terminal 和 iTerm2 之间的差异。
我认为指示 jest 不要在标准输出和控制台上施展魔法的选项对每个人都非常有益
这是我设法重现的错误的一个实例。 不确定是否有多个来源:
https://github.com/spion/jest-logging-repro
yarn install; yarn repro
设置:Jest 处于监视模式,详细标志打开,至少有两个测试文件正在运行。
理论:一名工作人员的输出将控制台光标移动到错误的位置,覆盖错误的内容。
在控制台中观察:
RUNS tests2/other-tests.js
RUNS lib/example.spec.js
PASS tests2/other-tests.js
bar
✓ always is true (17ms)
PASS lib/example.spec.js
foo
✓ adds 5 (5ms)
Test Suites: 2 passed, 2 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 1.673s
Ran all test suites.
Watch Usage: Press w to show more.
如果我删除控制台日志,视觉上“RUNS”会按预期被覆盖:
PASS lib/example.spec.js
foo
✓ adds 5 (5ms)
PASS tests2/other-tests.js
bar
✓ always is true (5ms)
Test Suites: 2 passed, 2 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 1.597s
Ran all test suites.
Watch Usage: Press w to show more.
如果我添加 3 个控制台日志:
PASS lib/example.spec.js
foo
✓ adds 5 (5ms)
RUNS tests2/other-tests.js
Test Suites: 1 passed, 1 of 2 total
Tests: 1 passed, 1 total
Snapshots: 0 total
console.log tests2/other-tests.js:5
JEST
PASS tests2/other-tests.jsests.js:6
bar
✓ always is true (19ms)
Test Suites: 2 passed, 2 total
Tests: 2 passed, 2 total
Snapshots: 0 totalTime: 1.788sRan all test suites.
Watch Usage: Press w to show more.
节点版本:
30656 % node --version
v8.11.2
我认为@spion正在磨练它。 很容易复制。
可以确认这发生在 Node v8.11.1 LTS 上,并且仅发生在watch
和watchAll
模式下。 没有手表模式,没关系。
我对 Node v10.6.0 和 Jest 23.4.1 有同样的问题
我也是。 刚刚发现-w 1
使日志记录再次工作,这符合@spion的假设。
节点 8.11.3
开玩笑 23.4.0
当我打开文件正则表达式匹配(在watch
模式下按p
)时,我发现了这个问题,或者至少是一个类似的问题。 打开all
后,将按预期打印日志。 注意--verbose
不在此处。
it.only(`should display a ErrorMessage component if state.validated is 'error'`, () => {
const fV = shallow(<FormValidator/>);
console.log('r1');
console.error('r2');
console.error('r3');
...
观看all
(同时打印log
和error
:
PASS src/components/__tests__/FormValidator.js
● Console
console.log src/components/__tests__/FormValidator.js:56
r1
console.error src/components/__tests__/FormValidator.js:57
r2
console.error src/components/__tests__/FormValidator.js:58
r3
在file regex
模式下(只打印第一个log
而不是error
s):
Test Suites: 0 of 1 total
Tests: 0 total
Snapshots: 0 total
console.log src/components/__tests__/FormValidator.js:56
r1
PASS src/components/__tests__/FormValidator.jsidator.js:57
FormValidator
○ skipped 3 tests
FormValidator.displayMessage
✓ should display a ErrorMessage component if state.validated is 'error' (32ms)
○ skipped 5 tests
FormValidator.render
○ skipped 1 test
it.only(`should display a ErrorMessage component if state.validated is 'error'`, () => {
const fV = shallow(<FormValidator/>);
console.log('r1');
console.error('r3');
...
all
(按预期打印log
和error
):
PASS src/components/__tests__/FormValidator.js
● Console
console.log src/components/__tests__/FormValidator.js:56
r1
console.error src/components/__tests__/FormValidator.js:59
r3
watch
(上面的代码没有打印任何内容):
Snapshots: 0 total
PASS src/components/__tests__/FormValidator.jsator.js:56
FormValidator
○ skipped 3 tests
FormValidator.displayMessage
✓ should display a ErrorMessage component if state.validated is 'error' (20ms)
○ skipped 5 tests
FormValidator.render
○ skipped 1 test
Test Suites: 1 passed, 1 total
it.only(`should display a ErrorMessage component if state.validated is 'error'`, () => {
const fV = shallow(<FormValidator/>);
console.log('r1');
console.log('r2');
console.log('r3');
console.log('r4');
...
all
(打印所有四个log
预期):
PASS src/components/__tests__/FormValidator.js
● Console
console.log src/components/__tests__/FormValidator.js:56
r1
console.log src/components/__tests__/FormValidator.js:57
r2
console.log src/components/__tests__/FormValidator.js:58
r3
console.log src/components/__tests__/FormValidator.js:59
r4
watch
(只有前两个log
使用上面的代码打印):
Snapshots: 0 total
console.log src/components/__tests__/FormValidator.js:56
r1
console.log src/components/__tests__/FormValidator.js:57
r2
PASS src/components/__tests__/FormValidator.jsator.js:58
FormValidator
○ skipped 3 tests
FormValidator.displayMessage
✓ should display a ErrorMessage component if state.validated is 'error' (31ms)
○ skipped 5 tests
FormValidator.render
○ skipped 1 test
Test Suites: 1 passed, 1 total
我不确定我做了什么,但我认为你设置笑话的顺序很重要。 我认为某些配置可能会相互覆盖。 我得到了测试和日志输出。
node -v
v8.11.2
jest -v
23.4.0
下面是我在 package.json 中的笑话配置
```
“开玩笑”:{
“转换忽略模式”:[
"
],
“设置文件”:[
"
],
"testEnvironment": "jsdom",
“详细”:是的,
“项目”:[
{
"displayName": "组件",
“设置文件”:[
"
],
“模块路径”:[”
“测试匹配”:[“减速器",“设置文件”:["
},
{
" displayName ": "动作",
“设置文件”:[
"
],
“模块路径”:[”
“测试匹配”:[“
}
]
},
Here are my dependencies
“依赖”:{
"babel-core": "^6.26.3",
"babel-jest": "^23.4.0",
"babel-loader": "^7.1.5",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"dotenv": "^6.0.0",
“快递”:“^4.16.3”,
"笑话": "^23.4.0",
“反应”:“^16.4.1”,
“反应域”:“^16.4.1”,
"react-redux": "^5.0.7",
“反应脚本”:“1.1.4”,
"redux": "^4.0.0",
“再生器运行时”:“^0.12.0”
},
output from just running jest
通过减速器 src/reducers/__tests__/comments/ index.test.js
✓ 处理 SAVE_COMMENT 类型的操作 (4ms)
✓ 处理未知类型的动作
通过操作 src/actions/__tests__/ index.test.js
保存评论
✓ 具有正确的类型(1ms)
✓ 有正确的有效载荷 (1ms)
通过组件src/components/__tests__/App/index.test.js
✓ 应该显示一个 CommentList (5ms)
✓ 应该显示一个评论框 (1ms)
通过组件src/components/__tests__/CommentBox/index.test.js
✓ 有一个文本区域(23ms)
✓ 有一个按钮 (3ms)
文本区域
✓ 有一个用户可以输入的文本区域(9 毫秒)
✓ 当表单被提交时,文本区域被清空(5ms)
通过组件src/components/__tests__/CommentList/index.test.js
✓ 每条评论创建一个 LI (32ms)
测试套件:5 个通过,共 5 个
测试:11 通过,共 11
快照:共 0 个
时间:3.79s
在 3 个项目中运行所有测试套件。
console.log src/components/__tests__/CommentList/index.test.js:26
0
console.log src/components/__tests__/CommentList/index.test.js:27
测试
```
这个问题应该重新打开,控制台输出也被玩笑吞没了,我的环境是:
→ 节点--版本
v8.11.3
→ npx 笑话--版本
23.4.1
我尝试使用干净的设置,一切正常。
// console.test.js
describe('jest should console output', () => {
test('should console.log output be print', () => {
console.log('console.log')
expect(1).toBe(1)
})
test('should console.error output be print', () => {
console.error('console.error')
expect(1).toBe(1)
})
test('should console.info output be print', () => {
console.info('console.info')
expect(1).toBe(1)
})
})
输出:
所以我认为问题可能与我的笑话配置有关:
{
"globals": {
"API_SERVER_PLACEHOLDER": "SOME_API_ADDRESS"
},
"moduleFileExtensions": [
"js",
"jsx"
],
"transform": {
"^.+\\.jsx?$": "babel-jest"
},
"moduleNameMapper": {
"\\.(css|less|sass|scss|png)$": "<rootDir>/__mocks__/styleMock.js",
"\\.(gif|ttf|eot|svg|png)$": "<rootDir>/__mocks__/fileMock.js"
}
}
我的直觉告诉我检查verbose
并删除它后一切都很好。
配置verbose
设置为true
的玩笑版本 23.4.1 会导致控制台输出被吞没。
建议将默认输出流更改为stdout
: https ://github.com/noscripter/jest/pull/1
又坏了?! 为什么这个一直断?
我已经解决了这个问题:
expect(str).toBe("not this");
😬
如果您的 package.json 中有 verbose: true
,或者您正在运行带有--verbose
标志的玩笑(或两者都有?),请尝试删除它们。
没关系,这不再有帮助了。
我经常可以在完整的测试摘要打印到控制台之前看到一瞬间的日志输出。 我必须连续console.log
大约 4-5 次才能显示输出,即使这样最后一个日志也会被砍掉一半(例如,当打印一个大对象时,只有前半部分会在最后打印的日志中可见)。
这也很难预测。 有时一两个console.log
就足够了,而其他时候我必须连续放置三到五个。 我的日志是在我正在测试的代码中还是在测试用例本身中也没关系。
似乎开玩笑正在打印日志,然后在打印完整的测试摘要之前清除输出,而实际上它应该保留这些日志。
我已经接受了我必须多次复制粘贴日志才能在控制台中看到它们。
如果您只运行特定的测试文件, console.log
确实有效
yarn test <your-test-file-name>
例如yarn test FormValidator
仅供参考,我使用以下命令运行我的复制:
script -qfc 'yarn repro' /dev/null > raw.log
这就是 zsh - 你可能想要script -qfce
在 bash
然后我用cat -vet raw.log
查看了日志。 结果如下:
^[[2K^[[1G^[[1myarn run v1.7.0^[[22m^M$
^[[2K^[[1G^[[2m$ jest --watch^[[22m^M$
^[[2J^[[3J^[[H^[[1m^[[2mDetermining test suites to run...^[[1m^[[22m^[[999D^[[K^M$
^M$
^[[1mTest Suites: ^[[22m0 of 2 total^M$
^[[1mTests: ^[[22m0 total^M$
^[[1mSnapshots: ^[[22m0 total^M$
^[[1mTime:^[[22m 0s, estimated 1s^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mtests2/^[[22m^[[1mother-tests.js^[[22m^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mlib/^[[22m^[[1mexample.spec.js^[[22m^M$
^M$
^[[1mTest Suites: ^[[22m0 of 2 total^M$
^[[1mTests: ^[[22m0 total^M$^[[1mSnapshots: ^[[22m0 total^M$
^[[1mTime:^[[22m 0s, estimated 1s^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^[[0m^[[7m^[[1m^[[32m PASS ^[[39m^[[22m^[[27m^[[0m ^[[2mlib/^[[22m^[[1mexample.spec.js^[[22m^M$
^M$^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mtests2/^[[22m^[[1mother-tests.js^[[22m^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mlib/^[[22m^[[1mexample.spec.js^[[22m^M$
^M$
^[[1mTest Suites: ^[[22m0 of 2 total^M$
^[[1mTests: ^[[22m0 total^M$
^[[1mSnapshots: ^[[22m0 total^M$
^[[1mTime:^[[22m 0s, estimated 1s^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A foo^M$
^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mtests2/^[[22m^[[1mother-tests.js^[[22m^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mlib/^[[22m^[[1mexample.spec.js^[[22m^M$
^M$
^[[1mTest Suites: ^[[22m0 of 2 total^M$
^[[1mTests: ^[[22m0 total^M$
^[[1mSnapshots: ^[[22m0 total^M$
^[[1mTime:^[[22m 0s, estimated 1s^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A ^[[32mM-bM-^\M-^S^[[39m ^[[2madds 5 (4ms)^[[22m^M$
^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mtests2/^[[22m^[[1mother-tests.js^[[22m^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mlib/^[[22m^[[1mexample.spec.js^[[22m^M$
^M$
^[[1mTest Suites: ^[[22m0 of 2 total^M$
^[[1mTests: ^[[22m0 total^M$
^[[1mSnapshots: ^[[22m0 total^M$
^[[1mTime:^[[22m 0s, estimated 1s^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M$
^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mtests2/^[[22m^[[1mother-tests.js^[[22m^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mlib/^[[22m^[[1mexample.spec.js^[[22m^M$
^M$
^[[1mTest Suites: ^[[22m0 of 2 total^M$
^[[1mTests: ^[[22m0 total^M$
^[[1mSnapshots: ^[[22m0 total^M$
^[[1mTime:^[[22m 0s, estimated 1s^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mtests2/^[[22m^[[1mother-tests.js^[[22m^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mlib/^[[22m^[[1mexample.spec.js^[[22m^M$
^M$
^[[1mTest Suites: ^[[22m0 of 2 total^M$
^[[1mTests: ^[[22m0 total^M$
^[[1mSnapshots: ^[[22m0 total^M$
^[[1mTime:^[[22m 0s, estimated 1s^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mtests2/^[[22m^[[1mother-tests.js^[[22m^M$
^M$
^[[1mTest Suites: ^[[22m^[[1m^[[32m1 passed^[[39m^[[22m, 1 of 2 total^M$
^[[1mTests: ^[[22m^[[1m^[[32m1 passed^[[39m^[[22m, 1 total^M$
^[[1mSnapshots: ^[[22m0 total^M$
^[[1mTime:^[[22m 1s^[[999D^[[K ^[[2mconsole.log^[[22m ^[[2mtests2/other-tests.js:5^[[22m^M$
JEST^M$
^M$
^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^[[0m^[[7m^[[1m^[[32m PASS ^[[39m^[[22m^[[27m^[[0m ^[[2mtests2/^[[22m^[[1mother-tests.js^[[22m^M$
^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mtests2/^[[22m^[[1mother-tests.js^[[22m^M$
^M$
^[[1mTest Suites: ^[[22m^[[1m^[[32m1 passed^[[39m^[[22m, 1 of 2 total^M$
^[[1mTests: ^[[22m^[[1m^[[32m1 passed^[[39m^[[22m, 1 total^M$
^[[1mSnapshots: ^[[22m0 total^M$
^[[1mTime:^[[22m 1s^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A bar^M$
^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mtests2/^[[22m^[[1mother-tests.js^[[22m^M$
^M$
^[[1mTest Suites: ^[[22m^[[1m^[[32m1 passed^[[39m^[[22m, 1 of 2 total^M$
^[[1mTests: ^[[22m^[[1m^[[32m1 passed^[[39m^[[22m, 1 total^M$
^[[1mSnapshots: ^[[22m0 total^M$
^[[1mTime:^[[22m 1s^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A ^[[32mM-bM-^\M-^S^[[39m ^[[2malways is true (15ms)^[[22m^M$
^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mtests2/^[[22m^[[1mother-tests.js^[[22m^M$
^M$
^[[1mTest Suites: ^[[22m^[[1m^[[32m1 passed^[[39m^[[22m, 1 of 2 total^M$
^[[1mTests: ^[[22m^[[1m^[[32m1 passed^[[39m^[[22m, 1 total^M$
^[[1mSnapshots: ^[[22m0 total^M$
^[[1mTime:^[[22m 1s^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M$
^M$
^[[0m^[[7m^[[33m^[[1m RUNS ^[[22m^[[39m^[[27m^[[0m ^[[2mtests2/^[[22m^[[1mother-tests.js^[[22m^M$
^M$
^[[1mTest Suites: ^[[22m^[[1m^[[32m1 passed^[[39m^[[22m, 1 of 2 total^M$
^[[1mTests: ^[[22m^[[1m^[[32m1 passed^[[39m^[[22m, 1 total^M$
^[[1mSnapshots: ^[[22m0 total^M$
^[[1mTime:^[[22m 1s^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^M^[[K^M^[[1A^[[999D^[[K^[[1mTest Suites: ^[[22m^[[1m^[[32m2 passed^[[39m^[[22m, 2 total^M$
^[[1mTests: ^[[22m^[[1m^[[32m2 passed^[[39m^[[22m, 2 total^M$
^[[1mSnapshots: ^[[22m0 total^M$
^[[1mTime:^[[22m 1.128s^M$
^[[2mRan all test suites^[[22m^[[2m related to changed files^[[22m^[[2m.^[[22m^M$
^M$
^[[1mWatch Usage^[[22m^M$
^[[2m M-bM-^@M-: Press ^[[22ma^[[2m to run all tests.^[[22m^M$
^[[2m M-bM-^@M-: Press ^[[22mf^[[2m to run only failed tests.^[[22m^M$
^[[2m M-bM-^@M-: Press^[[22m p ^[[2mto filter by a filename regex pattern.^[[22m^M$
^[[2m M-bM-^@M-: Press^[[22m t ^[[2mto filter by a test name regex pattern.^[[22m^M$
^[[2m M-bM-^@M-: Press^[[22m q ^[[2mto quit watch mode.^[[22m^M$
^[[2m M-bM-^@M-: Press ^[[22mEnter^[[2m to trigger a test run.^[[22m^M$
希望这可以帮助。 看起来在某个点上控制代码计数错误。
最终结果如下所示:
PASS lib/example.spec.js
foo
✓ adds 5 (4ms)
RUNS tests2/other-tests.js
PASS tests2/other-tests.js2 total
bar
✓ always is true (15ms)
Test Suites: 2 passed, 2 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 1.128s
Ran all test suites related to changed files.
Watch Usage
› Press a to run all tests.
› Press f to run only failed tests.
› Press p to filter by a filename regex pattern.
› Press t to filter by a test name regex pattern.
› Press q to quit watch mode.
› Press Enter to trigger a test run.
缺少控制台行,并且 pass 写得太远了两行,可能是由于与 console.log 交织在一起,在上显示“PASS”时没有考虑到
编辑:在要点中添加了此摘要,以便于搜索和操作: https ://gist.github.com/spion/bbb34c5abc1230a37ad5f4f01336b8df
ps 要使用当前的 master 重现它,可能需要一些强制。 当您进入手表模式时,按住“a”一会儿 - console.logs 会在某个时候开始失控(出现在意想不到的地方和时间)
我也忘记了 - 我在 ubuntu 仿生上,如果这对 WRT 终端行为有任何影响:
% lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.1 LTS
Release: 18.04
Codename: bionic
我也是。 @spion已经确定了我所看到的。 我之所以发现它,是因为我对慢速异步代码进行了测试。 我看到控制台输出,然后它被测试结果摘要覆盖。
对于它的价值,我已经恢复到[email protected]
并且这样做解决了我在[email protected]
中的控制台输出上写入测试摘要输出时遇到的问题。
更新 - 我相信我找到了一个可以取得一些进展的最小补丁,但我花了一段时间才了解 Jest 记者和状态生成器之间的交互
Jest monkey 用自己的 writer 修补进程 stderr 和 stdout 流的写入方法。 该作者写下 jest-cli Status.js 的输出,其中包含正在进行的测试数量、进度条、经过的时间等。
每当该流上有一条写指令时,该指令就会被“删除”状态指令(使用 ANSI 控制代码向上)、原始写指令和“再次写状态”指令替换。 因此,状态始终位于屏幕底部,而文本在其上方滚动的错觉。
(当然,它比这更聪明一点 - 写入被缓冲,缓冲的数据仅每 100ms 与状态一起真正写入一次)
但是,并行测试运行程序(用于监视模式,将runInBand
设置为 false)运行其他工作程序。 这些工作人员被设置为“继承”原始进程的 stdio 流。 不幸的是,这并不意味着他们继承了更新状态的补丁版本! 如果这些写入发生,它们将是
为了确保修补版本接收到这些 tty 写入,有必要将子进程流从“继承”模式切换到“管道”模式。 这样,进程输出可以作为子进程中的流使用,而不是直接转到主 stdout/stderr。 我们还需要手动管道流:
diff --git a/packages/jest-runner/src/index.js b/packages/jest-runner/src/index.js
index 2f4dd724..618a8cbf 100644
--- a/packages/jest-runner/src/index.js
+++ b/packages/jest-runner/src/index.js
@@ -97,11 +97,14 @@ class TestRunner {
// $FlowFixMe: class object is augmented with worker when instantiating.
const worker: WorkerInterface = new Worker(TEST_WORKER_PATH, {
exposedMethods: ['worker'],
- forkOptions: {stdio: 'inherit'},
+ forkOptions: {stdio: 'pipe'},
maxRetries: 3,
numWorkers: this._globalConfig.maxWorkers,
});
+ worker.getStdout().pipe(process.stdout);
+ worker.getStderr().pipe(process.stderr);
+
const mutex = throat(this._globalConfig.maxWorkers);
// Send test suites to workers continuously instead of all at once to track
手动管道流确保猴子补丁写入确实被节点调用。
这破坏了许多集成测试,但它们主要是由于缺少颜色而被破坏。 正在做
diff --git a/packages/jest-worker/src/worker.js b/packages/jest-worker/src/worker.js
index 5eee64af..5e5126eb 100644
--- a/packages/jest-worker/src/worker.js
+++ b/packages/jest-worker/src/worker.js
@@ -94,6 +94,8 @@ export default class {
{
cwd: process.cwd(),
env: Object.assign({}, process.env, {
+ // $FlowFixMe: Does not know about isTTY
+ FORCE_COLOR: process.stdout.isTTY,
JEST_WORKER_ID: this._options.workerId,
}),
// Suppress --debug / --inspect flags while preserving others (like --harmony).
显着降低了这个数字,但仍然很高:
Test Suites: 51 failed, 232 passed, 283 total
Tests: 149 failed, 7 skipped, 2706 passed, 2862 total
Snapshots: 19 failed, 17 obsolete, 996 passed, 1015 total
我认为没有办法解决这个问题 - 输出发生了巨大变化,因为现在有更多的写入最终添加了状态更新。
编辑:在某些情况下,在子进程向父进程发送成功消息很久之后,还存在节点刷新输出流的问题。
请修复,这真的会开玩笑地伤害生产力
降级到[email protected]会恢复控制台日志输出。 必须设置 --env 节点才能使其工作。 请解决这个问题。
目前看来,我能让控制台日志记录可靠的唯一方法是连续记录同一件事 3-4 次。 Jest 只会阻止其中的一部分。 还是很烦。
有这方面的更新吗? 我正在运行 jest 23.4.1 和节点 9.11.1,有时会得到控制台日志输出,有时没有。
两年没有控制台日志让我成为了一个更好的开发者。 感谢 Jest 团队!
我不敢相信这仍然是一个问题。 为什么关闭问题?
我的意思是,谁会想要调试他们失败的测试,对吧?
就像@jonogilmour提到的那样,如果我在没有显示的情况下记录某些内容,但将内容记录两次,我会让其中一个显示出来。
FWIW, --verbose=false 解决方法对我有用。 在我的package.json
中:
"scripts": {
...
"test": "react-scripts test --env=jsdom --verbose=false",
其他一些观察:
你好男孩/女孩,
在 --watch 模式下运行测试时,我还遇到了著名的 jest 控制台日志问题。
解决方案是使用--watchAll 而不是--watch。 测试摘要变得更丑陋,但日志显示如预期。
macOS 高山脉
节点 v8.11.3
开玩笑:23.6.0
ts-笑话:23.10.4
对我来说,这在beforeAll
console.log = s => {
process.stdout.write(s + "\n");
};
这在shell中完成了工作:
yarn test > test.log
对我来说,切换到mocha
解决了这个问题。 切换非常简单,因为 DSL 非常相似。 你甚至可以继续使用 JEST 的期望库: https ://www.npmjs.com/package/expect
这几乎就像删除jest
和安装mocha
一样简单。
编辑:垃圾邮件与否,这是最简单的解决方案。
这个问题真的很伤人,希望维护者能尽快解决这个问题,因为 Jest 是为了提高生产力,而不是反过来对吧?
无论如何,以下是我现在使用的写法:
export const log = (s: any) => {
console.log(s);
console.log(s);
console.log(s);
process.stdout.write(s + "\n");
};
你必须发送垃圾邮件出去。
确认--verbose=false
解决了这个问题。
--verbose=false
不适用于我的版本23.6.0
天哪,这很痛苦:/ 2018 年 11 月
请重新打开此问题
尝试在jest.config.js
中设置silent: false
$ ...在我的情况下它对我有帮助
任何解决方案都不起作用。
节点JS:v8.12.0
笑话:v23.4.1
我已经使用 Jest 几个月了,它很棒,虽然这个错误是 _super 烦人_ ,但我一直使用的解决方法是进行垃圾断言,因为它每次都会记录到控制台。
例如,当尝试注销模拟呼叫时:
expect('hello').toEqual(childFunc.mock.calls[0])
打印出:
这并不理想,但它可以完成工作并让我完成编写测试。
使用 --watch 标志运行 Jest。
笑话版本 23.5.0
节点版本 8.11.3
这是一个很好的例子,说明引擎盖下发生了“太多魔法”,以及出现问题时的后果。 我不相信将 console.log 输出分组值得一年半丢失的 console.log 语句。 😕
同意上述观点——这不是一个很好的选择,但它让 Jest 痛苦,这是完全没有必要的。
我的“解决方法”是大部分逻辑都使用log4js
,所以对于我将 Jest 弯曲到服务器端代码的地方我很好。 可悲的是,我有大量的客户端代码,我通常在其中复制并粘贴每个console.log
的四个副本,因为最终其中一个似乎出现了。
如果您从测试中记录,使用expect
记录信息是一个不错的解决方法(特别是因为您可以在编辑器中使用logjest
之类的关键字为其创建片段),但是每当您需要更深入地挖掘并从测试调用的实际函数中记录时,它就不足了。
CI=true yarn run test
怎么样?
抱歉我之前说过的话,但是如果没有测试用例的标题,它可以很好地工作,我的意思是,没有“--verbose”选项,我认为--verbose 会进行某种格式化并替换标准输出流。
所以,对我来说,我已经有 2 个月的时间了,一切都运行良好。
如果有人想使用该选项,那么只需将其附加到您的 npm 命令中,如下所示: npm run test:integration -- --watchAll --verbose --coverage --etc
有问题的人可以测试[email protected]
吗? 它包括#6871
@jamesta696嗨,我认为您需要在这里使用“jest”标签在 StackOverflow 上发布此类问题,因为这里的讨论是针对“问题”的,不过,我知道有人可以帮助您,但这里的问题可能被关闭,因为主要问题没有被讨论。
现在,我无法回答这个问题,因为我没有为 react 和前端开发一些东西,而且,我不是 jest 的成员,但让我们试着遵守规则。
@SimenB我已经更新了 jest(到你提到的版本)并尝试在我的项目中放置一些console.log
语句有问题。 到目前为止,它似乎已修复:所有console.log
都出现了。 我会继续使用它,如果我再次遇到该问题,我会通知您。
仅供参考:我曾经(现在仍然)使用jest --watchAll
@tobyhinloopen很酷,看到提到@SimenB的进展证明。
太棒了@tobyhinloopen!
我还可以确认[email protected]工作正常,并且您可以在没有 --verbose=false 的情况下查看所有控制台日志。
我还可以确认[email protected]工作正常,并且您可以在没有 --verbose=false 的情况下查看所有控制台日志。
+1。 也可以确认。 很高兴看到这是有效的。 干得好,开玩笑的人! 😄
我也可以确认! 这就像圣诞节。 🎅
😃
不需要等到 create-react-app 更新
我正在运行开玩笑版本24.0.0
,但我仍然看不到console.log
或console.error
。 想知道我可能做错了什么。
确保他们没有被嘲笑
这真的很奇怪。 异步处理似乎存在问题。 我无法显示错误。 即使包装到try/catch
块,我也看不到错误。
参数generator
肯定是正确的,如果我删除异步函数调用,那么它会正确记录。 当它在 for 循环之外时,它也会返回正确的字符串。
笑话版本是24.0.0
,节点是10.5
@tiborsaas您的测试可能会在console.log
运行之前完成。
如果您想等待changedGenerators
的迭代,您将需要类似
await Promise.all(changedGenerators.map(async (generator) => {/* ... */}))
感谢您的回复,但事实并非如此,某些错误阻止了console.log
的显示。 如果我在forEach
回调中调用它,还有另一个异步函数可以与console.log
一起正常工作。
编辑:实际上通过逐行调试我知道问题出在
const archives = await fs.readdir(archiveDir);
然而,这个笑话问题是关于记录事情的。 我不想破坏谈话。
您可能仍然遇到错误,只是想指出(不知道您的确切代码),一般来说,在不等待它们的情况下分叉一堆这样的承诺通常是一个坏主意,因为它们可能会在您的测试完成后拒绝: )
我同意,但我想在forEach
中运行expect
调用,因为我事先不知道我必须处理多少更改。
不幸的是, Promise.all
方法没有解决任何问题。
您是否使用map
而不是forEach
? 关键是将一组承诺返回给Promise.all
@SimenB是的,我知道。
如果有错误,我看不到它。
@tiborsaas您没有等待Promise.all
完成:使用await Promise.all(...)
也这样做了,结果一样。 :(
如果您在 $ promise.all
await new Promise((resolve) => setTimeout(resolve, 1000))
#$ 怎么办?
你能打开一个复制的新问题吗? 我相信当您看到另一个问题时,OP 报告的问题已得到解决(无论您是否正确处理异步,您仍然应该看到日志语句)
是的,这确实很奇怪,就像
test('stuff', () => {
setTimeout(() => console.log('hi', 500));
})
通常仍以某种方式打印
他使用回调函数作为Promise.all([...], callback)
的第二个参数。 他应该使用Promise.all([...]).then(callback)
。 也许这解决了他的问题,我认为.all
的第二个参数被忽略并且永远不会执行(所以你的日志永远不会被执行)。 @tiborsaas
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all
是的,那是错误的,但日志语句仍应显示
@SimenB不,第二个参数被忽略。
> Promise.all([Promise.resolve(true)], () => console.log("hi")).then(console.log, console.error);
Promise {
<pending>,
domain:
Domain {
domain: null,
_events: { error: [Function: debugDomainError] },
_eventsCount: 1,
_maxListeners: undefined,
members: [] } }
// output:
// [ true ]
是的,弄糊涂了,抱歉。 谢谢@tobyhinloopen
const lol = await Promise.all(versions);
按预期工作。
在这种情况下,日志语句可能会丢失,因为该函数从未被调用,但您仍然应该在原始forEach
案例中看到日志语句,因为节点将在退出进程之前等待承诺完成。 所以它仍然是一个错误,即使它是一个用户错误
公关:#7731
我使用https://www.npmjs.com/package/debug进行日志记录。 这对 Jest 有用吗?
不,直到我们做#6524。
我建议在您的测试中模拟debug
并使用console.log
如果您想查看它们
作为参考,如果在测试完成后打印控制台消息,它们可能会丢失,请参阅 #7731 底部的注释。 这可能是一些原因,但可能不是这里报告的所有丢失的控制台消息。
--verbose 对我有用。 在使用 --verbose 之前,一些但不是所有的消息都丢失了。 我正在使用节点 v10.15.3 和 jest v21.2.1
对我来说仍然是个问题,控制台日志不会在 Jest 中显示
尽管博客中最新宣布问题终于解决了,但问题仍然存在,我的控制台日志有时不会再次出现,我正在使用jest v24.8.0
。
我的作品还不错🤷♂️。 请发布我们可以调查的复制品。 我们不是向导,我们看不到您无法记录输出的代码。
实际上,经过调查,与 API 测试相关的日志(如 supertest)不起作用。 预期的 :/
@thymikee这种情况不一致,因此很难重现它。 例子:
通过从测试中选择单个文件来运行以下运行(选项 p )
现在我尝试复制相同的步骤,结果不一致。
在它不起作用的地方提供一个示例 repo,以便 JEST 人员可以帮助调试它。 @kresli
也有很多用户错误的可能性,主要是缺少await
或其他异步console.log
。
我会试着找时间重现这个。 在那之前,我发现我的日志被结果吃掉了,你可以从下面看到。 在 FAIL 出现之前,您可以在那里看到我的 2 个日志。 值得一提的是,仅删除了 2 条日志。 如果我在彼此下方添加 10 个日志,则会显示 8 个。 我认为这是一个好的开始:)
同时,如果你需要一个包罗万象的修复程序,你可以使用类似winston
的东西来登录文件和控制台。 即使您的控制台消息未显示,它们也会写入文件。
使用winston
您可以配置您想要记录的内容,它支持多种传输,并且您可以自己实现传输。
const logger = winston.createLogger({
level: "verbose",
format: winston.format.json(),
defaultMeta: {},
transports: [
new winston.transports.Console(),
new winston.transports.File({ filename: "combined.log" }),
],
});
logger.error(stuff)
也许您甚至可以做一些肮脏的事情,例如将console.*
全局覆盖到winston的记录器。
@kresli你的笑话是什么版本? 这看起来像 v23 行为
这一直发生在我身上jest v^24.6.0
和node v10.14.2
。 知道为什么吗?
@yaelz这是一个顽固的问题,通常由用户错误引起,但也有难以重现的错误历史。
我认为通过提供示例 repo 或提供另一种重现问题的方式,它确实会帮助贡献者提供可重现的案例。
感谢您及时的回复!
这将很难,因为当前的回购在我的组织中是私有的......如果我得到它,我会告诉你:)
这一直发生在我身上
jest v^24.6.0
和node v10.14.2
。 知道为什么吗?
我最近在一个项目中升级了一些依赖项,我没有任何问题,我在一个月前遇到过这个问题,但我相信它在较新的版本中得到了解决......
你能分享一下你现在正在使用的版本,当它解决后?
2019 年 8 月 5 日星期一下午 12:43 Norman Enmanuel [email protected]
写道:
感谢您及时的回复!
这会很难,因为当前的 repo 在我的组织中是私有的......我会让
你知道我是否明白了:)我最近在一个项目中升级了一些依赖项,但我没有任何依赖项
问题,我在一个月前遇到过这个问题,但我在较新的版本中得到了解决
相信...—
你收到这个是因为你被提到了。
直接回复此邮件,在 GitHub 上查看
https://github.com/facebook/jest/issues/3853?email_source=notifications&email_token=AB6F4PAE3CHUMEBP7IYXRPLQC7Y2DA5CNFSM4DPZ3JSKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3RI3PY#issuecomment-518163903
或使线程静音
https://github.com/notifications/unsubscribe-auth/AB6F4PFXDSRHBW5CMTT2DKDQC7Y2DANCNFSM4DPZ3JSA
.
你能分享一下你现在正在使用的版本,当它解决后?
当然:
笑话
^24.8.0
节点-v
v10.16.0
这是我用来运行 e2e、集成、单元和验收的一些 npm 脚本:
"scripts": {
"test": "NODE_ENV=test npm run test:unit && npm run test:integration:both",
"test:unit": "NODE_ENV=test jest --config test/jest.config.unit.js --detectOpenHandles",
"test:integration": "NODE_ENV=test MOCK=false jest --config test/jest.config.integration.js --runInBand --detectOpenHandles",
"test:integration:mock": "NODE_ENV=test MOCK=true jest --config test/jest.config.integration.js --runInBand --detectOpenHandles",
"test:integration:both": "NODE_ENV=test npm run test:integration:mock -- --coverage; npm run db:migration:test; npm run test:integration -- --coverage;",
"test:report": "open docs/test/report/index.html",
"test:report:coverage": "open docs/test/coverage/lcov-report/index.html"
}
这是 jest.config:
"use strict";
module.exports = {
"bail": true,
"verbose": false,
"collectCoverage": false,
"expand": true,
"testURL": "http://localhost:3000/",
"coverageDirectory": "./docs/test/coverage",
"testEnvironment": "node",
"rootDir": "../",
"setupFilesAfterEnv": [
"./test/jest.setup.js"
],
"jest.showCoverageOnLoad": true,
"watchPathIgnorePatterns": ["node_modules"],
"transform": {
"^.+\\.js$": "babel-jest",
'^.+\\.tsx?$': 'ts-jest',
},
"reporters": [
"default",
["./node_modules/jest-html-reporter", {
"pageTitle": "...",
"outputPath": "./docs/test/report/index.html",
"includeFailureMsg": true,
"sort": "titleAsc",
"dateFormat": "yyyy-mm-dd HH:MM:ss"
}]
]
};
希望能帮助到你。
我会试着找时间重现这个。 在那之前,我发现我的日志被结果吃掉了,你可以从下面看到。 在 FAIL 出现之前,您可以在那里看到我的 2 个日志。 值得一提的是,仅删除了 2 条日志。 如果我在彼此下方添加 10 个日志,则会显示 8 个。 我认为这是一个好的开始:)
@kresli您在这里的状态栏和时间输出是什么? 当我运行我的测试套件时,我看到 _RUN HARNESS test-harness/index.js_ 并且没有其他任何东西,直到一切运行。 然后我会在最后看到我的 console.log 消息,并且带有 _RUN HARNESS..._ 的行更改为 _
更新:请忽略,原来是我的代码中的一个问题
仍然在 MacOS 上使用 node v12.16.1、jest 25.5.4、typescript 3.8.3 来面对这个问题。 尝试了使用 --runInBand、禁用/启用详细、使用 --silent=true 的建议,但没有帮助。
最有用的评论
两年没有控制台日志让我成为了一个更好的开发者。 感谢 Jest 团队!