Tag: jestjs

如何使用Jest使用节点debuggingcli?

我怎样才能用Jest使用简单的节点cli / repldebugging器? Jest文档使用节点检查器 ,但是从6.3节开始已经过时/不推荐使用。 我在节点7.7.4上尝试了推荐的命令: node –debug-brk ./node_modules/.bin/jest –runInBand –no-cache [your_test_file] 但是,这只是挂在下面(假设等待节点检查员): (node:13452) DeprecationWarning: node –debug is deprecated. Please use node –inspect instead. Debugger listening on 127.0.0.1:5858 我添加了 – 警告指定的,但即使如此,执行不会停止在我的debugger语句在Chrome开发工具。 这对于一个非常简单的用例似乎过于复杂。

意外的令牌导入native-base-shoutem-theme / index.js:1可能是native-base / react-native

)我有一个很大的问题,我花了整整一天的时间来解决这个问题,并在几个软件包的依赖关系之间find了共识 我在运行testing时遇到问题: Users/P/Projects/react-native/node_modules/native-base-shoutem-theme/index.js:1 ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import connectStyle from './src/connectStyle'; ^^^^^^ SyntaxError: Unexpected token import at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/ScriptTransformer.js:289:17) at Object.<anonymous> (node_modules/native-base/dist/src/index.js:1:1133) at Object.<anonymous> (app/index.js:18:96) 现在我search反应的好版本,react-native,react-dom,native-base和react-test-renderer。 我尝试了新的和旧的,但有时我有这个错误,有时其他人..我决定修复这一个,因为它的一些最新版本的问题。 我的NPM: “babel-cli”:“6.24.1”,“react-native”:“0.44.0”,“native-base”:“2.1.2”,“react”:“16.0.0-alpha.3” “react-test-renderer”:“16.0.0-alpha.3” 节点版本7.7.2 npm版本4.1.2 如果你有其他WORKING的可选版本,请通过我这些或帮助解决这个错误;)我认为我将能够解决它与react-native init比较,有testing正在为我工​​作,但不是在我的项目..我不知道什么是错的: 我知道这有点棘手,但请帮助我;) 编辑:在版本react-native 0.45.0我有这个错误💃 ● Test suite failed to run TypeError: Cannot read property 'ReactCurrentOwner' of undefined at Object.<anonymous> (node_modules/react-native/Libraries/Renderer/src/renderers/shared/ReactGlobalSharedState.js:18:33) at Object.<anonymous> (node_modules/react-native/Libraries/Renderer/src/renderers/shared/ReactDebugTool.js:18:1) at Object.<anonymous> (node_modules/react-native/Libraries/Renderer/src/renderers/shared/ReactInstrumentation.js:19:20) […]

用Jesttesting文件系统?

我正在使用mock-fs来testing我编写的Webpack插件,它修改了我的文件系统上的一个文件。 这是testing: test('writes chunks to build/assets.json if no json file present', () => { mockFs({ [buildDir]: {}, }); const stats = new Stats({ assetsByChunkName: { main: 'main.somecrazyhash12341213445345.js', }, }); const compiler = new Compiler(stats); const plugin = new ChunksToJsonPlugin(config); expect(fs.existsSync(assetFilePath)).toBe(false); plugin.apply(compiler); compiler.execHandler(); expect(fs.existsSync(assetFilePath)).toBe(true); expect(fs.readFileSync(assetFilePath, 'utf-8')).toEqual( JSON.stringify({ main: 'main.somecrazyhash12341213445345.js', }) ); mockFs.restore(); }); 它运行的很好,当我自己运行它,但是当我作为一个套件的一部分运行时,其他testing(不使用mock-fs )rest。 ss […]

嘲笑节点模块

我正在使用superagent在反应应用程序中支持一些XHR服务。 我在superagent上写了一个很薄的包装器,使configuration更容易。 试图testing这个薄层已被certificate是相当头痛的。 我知道,有jest和节点核心依赖的问题,我可以通过dontMock superagent的依赖项来工作。 但是我更喜欢在没有默认的情况下嘲笑superagent 。 结果是在我的package.json中有一个非常详细的testing介绍或unMockedModulePatterns入口,有没有更好的方法? // my-module.js 'use strict'; var request = require('superagent'); module.exports = function () { return request.get('http://stackoverflow.com/questions/tagged/jestjs'); }; 一个示例testing: // __tests__/my-module-test.js 'use strict'; jest.dontMock('../'); // T_T jest.dontMock('superagent'); jest.dontMock('debug'); jest.dontMock('tty'); jest.dontMock('util'); jest.dontMock('stream'); jest.dontMock('fs'); jest.dontMock('delayed-stream'); jest.dontMock('mime'); jest.dontMock('path'); describe('mymodule', function () { var myModule, request; beforeEach(function () { myModule = require('../'); request […]

React Jest示例不起作用

试图运行JesttestingReact代码的示例(从https://github.com/facebook/jest/tree/master/examples/react ),我得到以下错误: > @ test /home/aizquier/jest/examples/react > jest Using Jest CLI v0.7.1 FAIL __tests__/CheckboxWithLabel-test.js ● Runtime Error SyntaxError: /home/aizquier/jest/examples/react/__tests__/CheckboxWithLabel-test.js: Unexpected token (15:6) npm ERR! Test failed. See above for more details. testing在文件CheckboxWithLabel-test.js的第15行失败: jest.dontMock('../CheckboxWithLabel'); import React from 'react'; import ReactDOM from 'react-dom'; import TestUtils from 'react-addons-test-utils'; const CheckboxWithLabel = require('../CheckboxWithLabel'); describe('CheckboxWithLabel', function() { it('changes the text […]

在CircleCI上运行Jest时出错:“npmtesting意外死亡”

在CircleCI上运行我的Jesttesting套件与本地相比要慢得多,导致CircleCI出现错误,说npm test died unexpectedly 。 为了让您了解CircleCI与本地testing持续时间的差异(MacBook Air 2012,fwiw): CircleCI: 97 tests passed (97 total in 25 test suites, run time 123.918s) npm test died unexpectedly 本地: 97 tests passed (97 total in 25 test suites, run time 13.601s) 我发现与Jest和CircleCI有关的唯一半相关信息是关于控制内存使用情况的问题 ,但是我不认为我遇到的问题是相关的,但是如果我知道这个问题,在这里:) 任何想法可能会发生在这里,或debugging提示?

如何在Jenkins服务器上运行Jesttesting

我试图在Jenkins部署期间运行我的Jesttesting。 如果我SSH入服务器,我可以sudo到jenkins用户ans成功运行testing从工作区。 但是,当我尝试从GUI构build项目时出现错误。 这是我的项目设置: 我已经安装了nodejs插件,它在全球安装gulp,jest-cli和babel。 然后在构build步骤中: testing失败,出现此错误: TypeError: Cannot read property 'getResourceByPath' of null at Loader.getDependenciesFromPath (/var/lib/jenkins/workspace/PHPStaging/node_modules/jest-cli/src/HasteModuleLoader/HasteModuleLoader.js:570:39) at /var/lib/jenkins/workspace/PHPStaging/node_modules/jest-cli/src/TestRunner.js:250:22 at process._tickCallback (node.js:368:9) Running 6 test suites… FAIL resources/__tests__/myTest.js` 看来Node在testing中遇到了需要模块的麻烦,但我并不完全确定。 任何帮助或方向将不胜感激。

使用Jest模拟Es6类

我试图用接收参数的构造函数来模拟一个ES6类,然后在类上模拟不同的类function,继续使用Jest进行testing。 问题是我找不到任何文件如何解决这个问题。 我已经看过这篇文章 ,但是这并不能解决我的问题,因为OP实际上甚至不需要模拟这个类。 在这篇文章中的另一个答案也没有详细说明,没有指出任何在线文档,不会导致可复制的知识,因为它只是一个代码块。 所以说我有以下课程: //socket.js; module.exports = class Socket extends EventEmitter { constructor(id, password) { super(); this.id = id; this.password = password; this.state = constants.socket.INITIALIZING; } connect() { // Well this connects and so on… } }; //__tests__/socket.js jest.mock('./../socket'); const Socket = require('./../socket'); const socket = new Socket(1, 'password'); expect(Socket).toHaveBeenCalledTimes(1); socket.connect() expect(Socket.mock.calls[0][1]).toBe(1); expect(Socket.mock.calls[0][2]).toBe('password'); […]

在IO.js 1.4.3中使用require()时Jest(JS)分段错误11

我使用IO.js 1.4.3和Jest来运行我的testing套件。 我需要更新版本的V8,因为我使用了Promise等ES6function。 如果我尝试最简单的testing: describe('the truth', function() { it('is true', function() { expect(true).toBeTruthy(); }); }); 它工作(谢天谢地)。 但是,如果我包含一个require() (我必须testing自己的代码)的调用,我会得到: Using Jest CLI v0.4.0 Waiting on 1 test…Segmentation fault: 11 无论我包含哪个模块,以及是否先打电话给jest.dontMock() , jest.dontMock()发生这种情况。 这并不是真的告诉我很多的错误信息,并require真的似乎是问题。 有没有任何解决scheme,而不是恢复到1.0之前的node.js?

babel-jest ES2015import报表

有没有人使用es2015语法编写茉莉花/笑话testing? 它需要多less匀场/ polyfill / gerrymandering? 我无法正确导入function。 我有一个模块: … / utils / TweetUtils.js 'use strict'; export function getListOfTweetIds (tweets) { return Object.keys(tweets); }; 和一个testing套件: … ./__testing__ / TweetUtils-test.js 'use strict'; jest.dontMock('../TweetUtils'); import * as TweetUtils from '../TweetUtils'; describe('Tweet utilities module', () => { it('has access to the TweetUtils methods', () => { let testObj = {a:'a',b:'b',c:'c'}; […]