Build reliableSvelte
applications usingCypress
Maurice de Beijer
@mauricedb
1
 Maurice de Beijer
 The Problem Solver
 Microsoft MVP
 Freelance developer/instructor
 Twitter: @mauricedb
 Web: http://www.TheProblemSolver.nl
 E-mail: maurice.de.beijer@gmail.com
2
Cypress.io
Course
3
Topics
 What is Cypress.io?
 What is Svelte and SvelteKit?
 UsingTDD to building a SvelteKit application
 Testing pages
 API testing
 Running the Cypress tests in GitHub Actions
4
What isCypress and
why should you care?
5
Cypress.io
6
What is
Cypress?
 Cypress is a front end testing tool
 Built for the modern web
 Tests are easy to write
 Using simple JavaScript orTypeScript
 TimeTravel runner lets you inspect test at each step
 Click on a step to see the state of the browser
 Automatic waiting for elements
 Makes tests more resilient
 Video recording of running test
 Helps debugging failing tests on the CI server
7
What is
Cypress?
 Lets you fake the network when required
 Or use the real backend as appropriate
 Automatically retry of failing tests
 Run flaky tests multiple times
 Many standard and 3rd party extensions
 Or write your own in JavaScript
 Can run in Docker containers
 Consistent cross platform behavior
 Runs inside the browser
 Not based onW3C WebDriver API
8
Testing
Triangle
🗣
End 2 End
Integration
UnitTesting
9
UnitTesting
10
Why End to End?
The more your tests resemble the way your software
is used, the more confidence they can give you!
Kent C. Dodds
11
What isSvelte
andSvelteKit?
12
svelte.dev
13
Svelte
 A new approach to building user interfaces
 The most loved web framework according to Stack Overflow
 Svelte is a component framework
 Just like React,Vue or Angular
 A Svelte application is reactive
 Only the parts of the application that use reactive state are updated
 Compiles your components into JavaScript
 No Svelte runtime library
14
SvelteKit
15
SvelteKit
 SvelteKit is an application framework powered by Svelte
 Just like Next.js for React or Nuxt.js forVue
 Designed for building extremely high-performance web apps
 Server side rendering at runtime
 Prerendering at build time
 Prefetching pages
 File based routing
 HTTP API endpoints
 Error handling
 Sessions
 Very fast builds when developing
 UsingVite/ESBuild
16
npm init svelte
17
MovieCard.svelte
18
What we are
building
19
How we are
testing
20
Cypress
Dashboard
21
Cypress andTDD
22
Testing the
navigation
23
Testing anAPI
24
Intercepting an
AJAX request
25
GitHubAction
26
CypressTesting Library
27
28
Cypress
Testing
Library
 Test your UI components in a more user-centric way
 Users don’t use CSS queries
 Allows better queries within Cypress
 Queries are often bases on accessibility
 SvelteTesting Library is also usable with Jest
 Using the same query functions
29
Cypress
Testing
Library
30
Code/Slides
 http://theproblemsolver.nl/Presentations
 https://github.com/mauricedb/surati-tech-talk-2022
31
Conclusion
 Cypress is a great tool for End to End testing
 More reliable then relying on unit testing and manual testing
 Write tests that resemble your user’s actions
 Great approach forTest Driven Development
 Test that your API’s return the shape you expect
 A mismatch can lead to vague errors
32
Maurice de Beijer
@mauricedb
maurice.de.beijer
@gmail.com
33

Surati Tech Talks 2022 / Build reliable Svelte applications using Cypress