testcafe icon indicating copy to clipboard operation
testcafe copied to clipboard

Node.js unit testing

Open inikulin opened this issue 7 years ago • 13 comments

Are you requesting a feature or reporting a bug?

feature

What is the current behavior?

TestCafe supports e2e testing only

What is the expected behavior?

TestCafe could support node.js unit testing as well. "One tool to rule them all"

inikulin avatar Mar 15 '17 10:03 inikulin

I'm looking at adding unit and end-to-end tests to a large, mature web app... and if I could go with a single solution I would.

RoyTinker avatar Aug 03 '17 22:08 RoyTinker

I'm interested in having TestCafe being able to run unit tests, but I'd see more value if it could run them on real browsers, as for e2e, otherwise there are many solutions for running tests on node.js. Afaik only karma support unit tests on real-browsers. Unit tests on node.js are supported by many but that way your tests run on the only engine that nobody uses among your users. TestCafe may strive for more.

riquito avatar Aug 24 '17 17:08 riquito

@riquito Thanks for you idea. It requires careful consideration (because it should be new API, new approach..). I'm not sure we're ready to do it right now but we can consider it in the future.

AlexanderMoskovkin avatar Aug 28 '17 08:08 AlexanderMoskovkin

I think your team should focus more on http testing. Like postman or supertest.

devdelpiero avatar Feb 22 '19 15:02 devdelpiero

@devdelpiero TestCafe already has some functionality for intercepting HTTP Requests. Please refer to the following article: https://devexpress.github.io/testcafe/documentation/test-api/intercepting-http-requests/ At the moment we think that implemented functionality is sufficient to satisfy needs of most users, so at this moment we don't have plans of moving in this way.

AlexKamaev avatar Feb 25 '19 14:02 AlexKamaev

Yes, that would be a nice addition. Something like what Cypress advertises - Unit, Integration and End-End tests

saimanoharnethi avatar Sep 27 '19 11:09 saimanoharnethi

If you could just add some configuration option to fixture and/or test so that I can prevent the browser from starting it would be really easy to use testcafe for both api and end-to-end tests in the same suite. Starting the browser can be very slow so would be great if that could be stopped.

cattermo avatar Sep 22 '20 06:09 cattermo

@cattermo Thank you for your suggestion. You can run TestCafe without specifying the testing page and in headless browser mode. In this case, the test would be launched much faster.

For example:

fixture ('Fixture');
test('test', async => {
 //test API
});

Dmitry-Ostashev avatar Sep 23 '20 07:09 Dmitry-Ostashev

@cattermo There is still no way to avoid opening a browser when TestCafe test execution starts. However, in 1.20.0+, TestCafe offers the t.request method designed for API testing.

helen-dikareva avatar Jul 19 '22 11:07 helen-dikareva

@cattermo There is still no way to avoid opening a browser when TestCafe test execution starts. However, in 1.20.0+, TestCafe offers the t.request method designed for API testing.

I agree, is there any way just running API tests using TestCafe and without opening browser at all?

jiteshsojitra avatar Aug 22 '22 07:08 jiteshsojitra

@jiteshsojitra You can use headless mode. Unit testing isn't supported.

Aleksey28 avatar Aug 23 '22 08:08 Aleksey28

@jiteshsojitra You can use headless mode. Unit testing isn't supported.

Yes, that alternative is not bad. It would be great, if testcafe gives a way by excluding browser stuff for API tests and would be huge benefit as a tool to all. I think, it will be highly appreciated for this feature and may create huge demand for TestCafe tool.

Will it not take any system/browser resources if headless mode used?

A headless browser is just like any other browser, the only difference is we cannot see anything on the screen. Here we can say that the program actually runs in the backend and nothing can be viewed on the screen. Thus, it is known to be the one without a Head/GUI.

jiteshsojitra avatar Aug 23 '22 08:08 jiteshsojitra

Yes, that is true. It behaves as described.

Aleksey28 avatar Aug 24 '22 06:08 Aleksey28

Hi folks,

We decided not to introduce the all-in-one tool. We want to focus on implementing E2E-specific features. Please use mocha, ava, and other tools to run Node.js unit tests. Also, you can use the built-in Node.js test runner.

miherlosev avatar Jun 09 '23 09:06 miherlosev