DEV Community

Discussion on: How you can help Angular in 2020

Collapse
 
jwp profile image
John Peters

Hello Lars;
I've abandoned all Protractor and all Karma/Jasmine work in favor of Cypress. Cypress is a direct 1 to 1 replacement for Protractor but overlaps into the Unit Test layer due to its ability to intercept and alter all incoming and outgoing HTTP requests.

Cypress majorly reduces the dependency issues found in all Angular Unit Test frameworks, because it runs in the browser! No more client side mocking, no more major hunting down dependencies.

I understand there's a Goolge Cypress-like clone, which I haven't tried yet. Maybe someday I'll get there.

Collapse
 
damoeb profile image
damoeb

As always it comes down to what you want to test. Protractor uses Selenium to talk to a browser (so you could test browser support) cypress has their own chrome runtime. Because of complexity and runtime overhead I want to have as little end to end tests as possible (smoke test). If you test all layers and a test breaks, the reason can be in every one of these layers and the infrastructure. If tests become flacky, its better to have none at all, because you will get less confident depending on them.

Unit tests have a different purpose. They validate the logic of the function under test. They are fast, independent, stable. You can execute thousands of unit tests or a handful of cypress/selenium tests.

Personally I would do a manual smoke test instead of automating a fragile jenga tower. And once the software is mature enough build a ton of unit tests, maybe even property based tests.

Collapse
 
jwp profile image
John Peters • Edited

Hello damoeb;
I was a test manager of a team of 35 people in three continents for 7 years, (at one time). I am very familiar with testing methods and terminology.

The problem I kept seeing then, was that the traditional concepts of Unit Testing, E2E, and even Smoke testing are off-base today. All have very specific definitions which managers or product owners feel is the "right" one. Unfortunately most of them are not developers and are under the assumption their understanding of those definitions are only what they think they are, with no need to communicate that understanding.

Those old definitions are over 20+ years old. Since then, new tools such as Cypress have crossed the line from only E2E to overlapping with Unit Test and Smoke Test ability. It's a true one-stop-shop.

Cypress does not need, as you know; the huge Protractor and Selenium set up. It's simply a browser driver (similar to Selenium) which allows http request interception. This allows for creating unit tests by altering the data.

It's fast, complete, and requires only a small ramp up time to get going. Unfortunately it's based on JQuery, but for the goodness it has, I am easily able to overlook that part.

My motto "In 2021; Just say no to Karma/Jasmine or Protractor/Selenium"

Thread Thread
 
layzee profile image
Lars Gyrup Brink Nielsen

Thanks for discussing, everyone. Just wanted to make you all aware that there are plenty of options for end-to-end testing:

Thread Thread
 
jwp profile image
John Peters • Edited

I was wanting to look into Puppeteer a while back, today I found this on their site:

How to intercept an HTTP request in Puppeteer

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.setRequestInterception(true);
  page.on('request', interceptedRequest => {
    if (interceptedRequest.url().endsWith('.png') || interceptedRequest.url().endsWith('.jpg'))
      interceptedRequest.abort();
    else
      interceptedRequest.continue();
  });
  await page.goto('https://example.com');

  await browser.close();
})();
Enter fullscreen mode Exit fullscreen mode

They too can intercept inbound and outbound requests ✔️
I don't know yet if the data can be changed, but the workflow can be altered.