jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.25k stars 6.46k forks source link

Jest + Supertest + Restify not working #982

Closed ravilution closed 8 years ago

ravilution commented 8 years ago

@cpojer Reopening the accidentally closed https://github.com/facebook/jest/issues/977

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.

'use strict';
var request = require('supertest')(require('../appServer'));
describe('Test', function () {
    it('works', function () {
        request
            .get('/api')
            .expect(200)
            .end(function (err, res) {
                expect(err).toEqual(null);
            });
    });
});

In above code appServer returns a restify server instance. I am using supertest because I want to do code coverage as well. But I get below error.

Error: Cannot find module '_http_common' from 'stream.js'
    at Runtime._resolveNodeModule (/Users/me/Documents/workspace/node_modules/jest-cli/src/Runtime/Runtime.js:451:11)
    at Object.<anonymous> (/Users/me/Documents/workspace/node_modules/spdy/lib/spdy/stream.js:13:20)
    at Object.<anonymous> (/Users/me/Documents/workspace/node_modules/spdy/lib/spdy.js:19:15)

I have automock turned off. I also tried you unmock code. I also tried jest.disableAutomock();. Nothing works. Below is my jest config in package.json

  "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 commented 8 years ago

Reopened #977.

github-actions[bot] commented 3 years ago

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. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.