-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Jest + Supertest + Restify not working #977
Comments
Thank you for reporting this issue. Do you use mocking or is mocking disabled? If you'd like to test your modules/components "supertest" and "appServer" you'll have to unmock them first: jest.unmock('supertest').unmock('../appServer'); |
Oops, wrong button, reopening :) If you can't figure it out, can you provide a repository that points this issue out so I can take a closer look? Thank you :) |
I have "jest": {
"automock": false,
"bail": true,
"collectCoverage": true,
"moduleFileExtensions": [
"js"
],
"scriptPreprocessor": "./node_modules/babel-jest",
"testFileExtensions": [
"js"
],
"testPathDirs": [
"./client/src",
"./server"
],
"testPathIgnorePatterns": [
"/node_modules/",
"/client/build/",
"/docs/",
"/logs/",
"/coverage/"
]
} |
@cpojer Have you reopened? It still says closed. |
I boarded a long distance flight and my internet was cut-off before I could reopen this issue. |
@cpojer Any updates? |
No, you haven't provided a full repository that highlights this problem so there is no way for me to confirm your issue. |
Below is the code. I did not want to create a repo for two files. Please try and let me know ./package.json {
"name": "jest-restify-supertest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "jest"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"jest-cli": "^12.0.2",
"supertest": "^1.2.0"
},
"jest": {
"automock": false,
"bail": true,
"collectCoverage": true,
"moduleFileExtensions": [
"js"
],
"testFileExtensions": [
"js"
],
"testPathIgnorePatterns": [
"/node_modules/",
"/coverage/"
]
},
"dependencies": {
"restify": "^4.0.4"
}
} ./tests/index-test.js 'use strict';
jest.disableAutomock();
jest.unmock('supertest').unmock('restify');
var restify = require('restify');
var app = restify.createServer();
app.get('/user', function (req, res) {
res.status(200).json({ name: 'tobi' });
});
var request = require('supertest')(app);
describe('Test', function () {
it('works', function () {
request(app)
.get('/user')
.expect('Content-Type', /json/)
.expect('Content-Length', '15')
.expect(200)
.end(function (err, res) {
if (err) throw err;
});
});
}); Error Message My-MacBook-Pro:jest-restify-supertest me$ npm test
> [email protected] test /Users/me/Documents/workspace/self/jest-restify-supertest
> jest
Using Jest CLI v12.0.2, jasmine2
Running 1 test suite...[SECURITY] node-uuid: crypto not usable, falling back to insecure Math.random()
FAIL __tests__/index-test.js
● Runtime Error
Error: Cannot find module '_http_common' from 'stream.js'
at Runtime._resolveNodeModule (/Users/me/Documents/workspace/self/jest-restify-supertest/node_modules/jest-cli/src/Runtime/Runtime.js:451:11)
at Object.<anonymous> (/Users/me/Documents/workspace/self/jest-restify-supertest/node_modules/spdy/lib/spdy/stream.js:13:20)
at Object.<anonymous> (/Users/me/Documents/workspace/self/jest-restify-supertest/node_modules/spdy/lib/spdy.js:19:15)
----------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
----------|----------|----------|----------|----------|----------------|
All files | 100 | 100 | 100 | 100 | |
----------|----------|----------|----------|----------|----------------|
npm ERR! Test failed. See above for more details. |
I think this should be fixed by setting the "testEnvironment" config option to "node". jsdom doesn't deal well with this stuff. |
I ran over this issue today and here is how I deal with it.
I think the key is to pass |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
node 5.4.1
jest-cli ^12.0.2
restify ^4.0.4
supertest ^1.2.0
I want to use Jest to do backend nodejs REST API testing also. I do not want to install another test tool like mocha etc.
In above code
appServer
returns a restify server instance. I am usingsupertest
because I want to do code coverage as well. But I get below error.The text was updated successfully, but these errors were encountered: