How can you be confident that your code is well-tested? For me, the criteria are straightforward: you feel comfortable deploying it automatically to production on a Friday evening, and the release pipeline stays as green as an evergreen tree. In this talk, I'll share some approaches that I am fo...
How can you be confident that your code is well-tested? For me, the criteria are straightforward: you feel comfortable deploying it automatically to production on a Friday evening, and the release pipeline stays as green as an evergreen tree. In this talk, I'll share some approaches that I am following to hit both targets for Node.js apps (APIs BFFs, etc)
Size: 822.06 KB
Language: en
Added: Jun 18, 2024
Slides: 15 pages
Slide Content
Testing:
Do More
With Less
Practical approach to test
Node.js web-apps, APIs, BFFs
Eugene Fidelin | JSNation 2024 Amsterdam
2
Is your code well-tested?
Do you feel comfortable
deploying it automatically
to production on a Friday
evening?
Does your release pipeline
stay as green as an
evergreen tree?
Why? DORA metrics
Lead Time for Changes
The amount of time it takes a
commit to get into production
Change Failure Rate
The percentage of deployments
causing a failure in production
3
Deployment Frequency
How often a team successfully
releases to production
Time to restore service
How long it takes a team to recover
from a failure in production
Static
Unit tests
Integration
tests
End to end
tests
Costs Confidence Speed
Very high High Low
Low - Medium Very good High
Low Average High
Very low Low Very high
4
How? Testing trophy
Steps to approach testing
0 2 41
Step 0
Enable static linters,
and type checks
Step 2
Write unit tests for
reusable parts and code
without coverage
Step 4
Use metrics, tracing,
logging to identify
anomalies on production
3
Step 3
Write very few e2e
tests only for the most
business critical flow(s)
Step 1
Create integration
tests for all happy and
non-happy flows
Node.js app architecture
6
App code
Code to test
External lib/service
Unit test
7
App code
Code to test
External lib/service
Test coverage
Scenario of integration test
8
Given anincoming request
app makesspecified API calls
and returns theexpected response
Focused Integration test
9
App code
Code to test
External lib/service
Test coverage
Mocks
Black-box Integration test
10
App code
Code to test
External lib/service
Test coverage
Mocks
Broad Integration test
11
App code
Code to test
External lib/service
Test coverage
Mocks
End to end test
12
App code
Code to test
External lib/service
Test coverage
Key takeaways
13
Adopt Testing Trophy
01
Start with Integration tests
02
Reduce amount of
e2e test
03
Measure impact with
DORA metrics
04
Tools
superagent
Simulate incoming HTTP
request
node-mocks-http
Mock Express.js
request/response objects
Jest / Vitest
Test framework, mock
deps, snapshots
nock
Mock downstream
HTTP API calls
14
Cypress.io /
Playwright
Testing in browser
CREDITS: This presentation template was
created by Slidesgo, including icons by Flaticon
and infographics & images by Freepik
Thanks!
15
Eugene Fidelin
Engineering Manager @
eugene.fi[email protected]
linkedin.com/in/eugef
medium.com/@EugeneFidelin