question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tests are not run when express is required in the test file

See original GitHub issue

It seems Cypress stops executing tests as soon as the express package is required within a test file.

Sample test file:

// ./cypress/integration/test_spec.js
var express = require("express");

describe("test", function() {
  it("case", () => {
    throw new Error("should fail");
  });
});

Running this test through cypress run gives this:

If the require call is commented, the test fails as expected.

My environment:

$ node --version
v6.0.0
$ cypress --version
Cypress CLI: 0.13.1

Express package version installed in node_modules: 4.14.1.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
chrisvenesscommented, Mar 15, 2018

In case it’s helpful to anyone, I’ve found having this in my package.json works:

"scripts": {
    "test-cypress": "node app.js & pid=$!; cypress run; kill -9 $pid"
}

(using cypress 2.0.4).

1reaction
brian-manncommented, Apr 5, 2017

We have not been opinionated about the server setup / teardown other than what we have in our public projects for CI scripts.

The reason is that the vast majority of our users only need to programmatically boot webservers in CI. Our users typically iterate in the headed browser all day so there’s not really ever a “start” and an “end” event. This is part of what separates Cypress from other browser automation tools. We’re like a long running experience which you use to drive, develop, and debug your application code all day.

Running headlessly from start to stop is really only useful in CI, its just not practical to run locally.

Since cypress can be spawned programmatically you could just write a simple wrapper using child_process in node.

We are actually in the middle of rewriting our CLI tool to be a requireable node_module which will have a nice API to do these things for you.

Here’s the open issue for that with some example API code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

'app.address is not a function' when testing an express HTTPS ...
js file and I run node app.js , then the app starts fine, although the test produces the same error. test_node/app.js var https...
Read more >
How to correctly unit test Express server - Gleb Bahmutov
Something is not right! First, why do we want to start and stop the server for each unit test? Aside from testing a...
Read more >
How To Start Unit Testing Your Express Apps
One last trick: you can run mocha . --recursive to run all test files recursively in the current directory, and you can run...
Read more >
Get started with unit testing - Visual Studio (Windows)
In this article. Create unit tests; Run unit tests; View live unit test results (Visual Studio Enterprise); Use a third-party test framework ...
Read more >
Code Coverage - Cypress Documentation
js file after running the test. Selectors code coverage. Our unit test is hitting the line we could not reach from the end-to-end...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found