Skip to content

Commit ee57a3c

Browse files
committed
part5 new version
1 parent 3e760d9 commit ee57a3c

File tree

7 files changed

+29
-43
lines changed

7 files changed

+29
-43
lines changed

src/components/InfoBanner.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ const InfoBanner = ({ visible, onHide }) => {
4545
return (
4646
<div style={style}>
4747
<div style={textStyle}>
48+
<p style={{ marginBottom: 20}}>
49+
The testing libraries used in part 5 were changed 3rd March 2024. In frontend Vite replaced Jest. For End to end-tests Playwright is the new preferred library.
50+
</p>
4851
<p>
49-
The testing library used in part 4 was changed 13th February 2024 from Jest to Node:test.
50-
If you have started with Jest, you may continue. The relevant material is still available, see the "Legacy: testing with Jest"
52+
If you have started with Jest or Cypress, you may continue. The relevant material is still available, for Jest, the link is at the top of part 5c and for the Cypress, the link is at the menu at the left.
5153
</p>
5254
</div>
5355
<div style={buttonDiv}>

src/components/layout.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Footer from './Footer/Footer';
1010
import PropTypes from 'prop-types';
1111
import SkipToContent from './SkipToContent/SkipToContent';
1212

13-
const BANNER_TO_KEY = 'part_4_changes';
13+
const BANNER_TO_KEY = 'part_5_changes';
1414

1515
const Layout = props => {
1616
const { i18n } = useTranslation();
@@ -23,7 +23,7 @@ const Layout = props => {
2323
useEffect(() => {
2424
const key = localStorage.getItem(BANNER_TO_KEY)
2525
if (!key) {
26-
const relevant = window.location.href.includes('osa4') || window.location.href.includes('en/part4')
26+
const relevant = window.location.href.includes('osa5') || window.location.href.includes('en/part5')
2727
setVisible(relevant);
2828
}
2929
}, []);

src/content/0/en/part0a.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,10 @@ Despite changes *all the submitted exercises remain valid*, and the course can b
340340
341341
Recent major changes
342342
343-
- Parts 1-9 (11th September - 5th October): Create React app replaced with Vite
343+
- Parts 3-5 (February-March 2024): Libraries used for testing changed
344+
- Part 10 (February 26, 2024): Library versions updated
344345
- Part 11 (16th January 2024): Example project dependencies updated
346+
- Parts 1-2, 6-9 (11th September - 5th October): Create React app replaced with Vite
345347
346348
### Expanding on a previously completed course
347349

src/content/0/fi/osa0a.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,10 @@ Kurssilla ei ole enää vuosittaisia versiota. Kurssi on siis käynnissä koko a
282282
Muutoksista huolimatta <i>kaikki jo tehdyt palautukset säilyvät voimassa</i>, eli voit jatkaa kurssia päivityksistä huolimatta normaaliin tapaan.
283283

284284
Viimeaikaisia isompia muutoksia
285-
- Osat 1-9 (11.9-5.10.2023): Create React app korvattu Vitellä
285+
- Osat 3-5 (helmi-maaliskuu 2024): Testaukseen käytetyt kirjastot muutettu
286+
- Osa 10 (26.2.2024): Kirjastoversiot päivitetty
286287
- Osa 11 (16.1.2024): Esimerkkiprojektin riippuvuudet päivitetty
288+
- Osat 1-2, 6-9 (11.9-5.10.2023): Create React app korvattu Vitellä
287289

288290
### Aiemmin suoritetun kurssin täydentäminen
289291

src/content/5/en/part5e.md

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ E2E library [Cypress](https://www.cypress.io/) has become popular within the las
1717

1818
Let's make some end-to-end tests for our note application.
1919

20-
We begin by installing Cypress to <i>the frontend</i> as a development dependency
20+
Unlike the backend tests or unit tests done on the React front-end, End to End tests do not need to be located in the same npm project where the code is. Let's make a completely separate project for the E2E tests with the _npm init_ command. Then install Cypress to <i>the new project</i> as a development dependency
2121

2222
```js
2323
npm install --save-dev cypress
@@ -29,12 +29,6 @@ and by adding an npm-script to run it:
2929
{
3030
// ...
3131
"scripts": {
32-
"dev": "vite --host", // highlight-line
33-
"build": "vite build",
34-
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
35-
"preview": "vite preview",
36-
"server": "json-server -p3001 --watch db.json",
37-
"test": "jest",
3832
"cypress:open": "cypress open" // highlight-line
3933
},
4034
// ...
@@ -532,8 +526,6 @@ The first command searches for a component containing the text <i>another note c
532526

533527
The second command checks that the text on the button has changed to <i>make important</i>.
534528

535-
The tests and the current frontend code can be found on the [GitHub](https://github.com/fullstack-hy2020/part2-notes-frontend/tree/part5-9) branch <i>part5-9</i>.
536-
537529
### Failed login test
538530

539531
Let's make a test to ensure that a login attempt fails if the password is wrong.
@@ -1056,8 +1048,7 @@ You can see the HTTP requests done by the tests on the Network tab, and the cons
10561048
10571049
![developer console while running cypress](../../images/5/38new.png)
10581050
1059-
So far we have run our Cypress tests using the graphical test runner.
1060-
It is also possible to run them [from the command line](https://docs.cypress.io/guides/guides/command-line.html). We just have to add an npm script for it:
1051+
So far we have run our Cypress tests using the graphical test runner. It is also possible to run them [from the command line](https://docs.cypress.io/guides/guides/command-line.html). We just have to add an npm script for it:
10611052
10621053
```js
10631054
"scripts": {
@@ -1072,7 +1063,7 @@ Now we can run our tests from the command line with the command <i>npm run test:
10721063
10731064
Note that videos of the test execution will be saved to <i>cypress/videos/</i>, so you should probably git ignore this directory. It is also possible to [turn off](https://docs.cypress.io/guides/guides/screenshots-and-videos#Videos) the making of videos.
10741065
1075-
Tests are found in [GitHubissa](https://github.com/fullstack-hy2020/notes-e2e-cypress/).
1066+
Tests are found in [GitHub](https://github.com/fullstack-hy2020/notes-e2e-cypress/).
10761067
10771068
Final version of the frontend code can be found on the [GitHub](https://github.com/fullstack-hy2020/part2-notes-frontend/tree/part5-9) branch <i>part5-9</i>.
10781069

src/content/5/fi/osa5d.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@ lang: fi
77

88
<div class="content">
99

10-
We have done integration tests for the backend that test it as a whole at the app level, and unit tests for the frontend that test individual components.
10+
Olemme tehneet backendille sitä apin tasolla kokonaisuutena testaavia integraatiotestejä ja frontendille yksittäisiä komponentteja testaavia yksikkötestejä.
1111

12-
Now let's look at one way of doing <i>End to End (E2E) tests</i> on [the system as a whole](https://en.wikipedia.org/wiki/System_testing).
12+
Katsotaan nyt erästä tapaa tehdä [järjestelmää kokonaisuutena](https://en.wikipedia.org/wiki/System_testing) tutkivia <i>End to End (E2E) ‑testejä</i>.
1313

14-
E2E testing of web applications takes place using a browser with the help of a library. There are several solutions available, for example [Selenium](http://www.seleniumhq.org/), which enables the automation of tests with almost any browser. Another option is to use the so-called [headless browser](https://en.wikipedia.org/wiki/Headless_browser) i.e. a browser that has no graphical user interface at all. For example, it is possible to run Chrome in Headless mode.
14+
Web-sovellusten E2E-testaus tapahtuu käyttäen selainta jonkin kirjaston avulla. Ratkaisuja on tarjolla useita, esimerkiksi [Selenium](http://www.seleniumhq.org/), joka mahdollistaa testien automatisoinnin lähes millä tahansa selaimella. Toinen vaihtoehto on käyttää ns. [headless browseria](https://en.wikipedia.org/wiki/Headless_browser) eli selainta, jolla ei ole ollenkaan graafista käyttöliittymää. Esim. Chromea on mahdollista suorittaa Headless-moodissa.
1515

16-
E2E tests are potentially the most useful test category, as they examine the system through the same interface as real users.
16+
E2E testit ovat potentiaalisesti kaikkein hyödyllisin testikategoria, sillä ne tutkivat järjestelmää saman rajapinnan kautta kuin todelliset käyttäjät.
1717

18-
There are also unpleasant aspects to E2E tests. They are more challenging to configure than unit and integration tests. E2E tests are also typically quite slow, and in larger software their execution time can easily reach minutes or even hours. This is unfortunate for application development, because when coding an application it is very useful to be able to run tests as often as possible for [regressions](https://en.wikipedia.org/wiki/Regression_testing) in the code.
18+
E2E-testeihin liittyy myös ikäviä puolia. Niiden konfigurointi on haastavampaa kuin yksikkö- ja integraatiotestien. E2E-testit ovat tyypillisesti myös melko hitaita ja isommassa ohjelmistossa niiden suoritusaika voi helposti nousta minuutteihin, tai jopa tunteihin. Tämä on ikävää sovelluskehityksen kannalta, sillä sovellusta koodatessa on erittäin hyödyllistä pystyä suorittamaan testejä mahdollisimman usein koodin [regressioiden](https://en.wikipedia.org/wiki/Regression_testing) varalta.
1919

20-
The problem is also that the tests performed via the user interface may be unreliable, i.e. in English [flaky](https://hackernoon.com/flaky-tests-a-war-that-never-ends-9aa32fdef359), some of the tests sometimes pass and sometimes not, even if nothing changes in the code.
20+
Ongelmana on usein myös se, että käyttöliittymän kautta tehtävät testit saattavat olla epäluotettavia eli englanniksi [flaky](https://hackernoon.com/flaky-tests-a-war-that-never-ends-9aa32fdef359), osa testeistä menee välillä läpi ja välillä ei, vaikka koodissa ei muuttuisi mikään.
2121

22-
At the moment, perhaps the two easiest to use libraries for End to End testing are [Cypress](https://www.cypress.io/) and [Playwright](https://playwright.dev/).
22+
Tämän hetken kaksi ehkä helppokäyttöisintä kirjastoa End to End -testaukseen ovat [Cypress](https://www.cypress.io/) ja [Playwright](https://playwright.dev/).
2323

24-
From the statistics on the page [npmtrends.com](https://npmtrends.com/cypress-vs-playwright), we see that Cypress, which dominated the market for the last five years, is still the clear number one, but Playwright has started a rapid rise in the second half of 2023:
24+
Sivun [npmtrends.com](https://npmtrends.com/cypress-vs-playwright) statistiikasta näemme, että viimeiset viisi vuotta markkinaa hallinnut Cypress on edelleen selvä ykkönen, mutta Playwright on lähtenyt nopeaan nousuun vuoden 2023 toisella puolikkaalla:
2525

2626
![cypress vs playwright in npm trends](../../images/5/cvsp.png)
2727

28-
Cypres has been used on this course for years. Now Playwright is also included as a new addition. You can choose whether to complete the E2E testing part of the course with Cypress or Playrwight. The operating principles of both libraries are very similar, so your choice is not very important. However, Playwright is now the primary recommended E2E library for the course.
28+
Tällä kurssilla on jo vuosia käytetty Cypresiä. Nyt mukana on uutena myös Playwright. Saat itse valita suoritatko kurssin E2E-testausta käsittelevän osan Cypressillä vai Playrwightillä. Molempien kirjastojen toimintaperiaatteet ovat hyvin samankaltaisia, joten kovin suurta merkitystä valinnallasi ei ole. Playwright on kuitenkin nyt kurssin ensisijaisesti suosittelema E2E-kirjasto.
2929

30-
If your choice is Playwright, go ahead. If you end up using Cypress, go [here](/osa5/end_to_end_testaus_cypress).
30+
Jos valintasi on Playwright, jatka eteenpäin. Jos päädyt käyttämään Cypressiä, mene [tänne](/osa5/end_to_end_testaus_cypress).
3131

3232
### Playwright
3333

src/content/5/fi/osa5e.md

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ Jos valintasi on Cypress, jatka eteenpäin. Jos päädyt käyttämään Playwrig
1313

1414
### Cypress
1515

16-
Aloitetaan asentamalla Cypress <i>frontendin</i> kehitysaikaiseksi riippuvuudeksi
16+
Toisin kuin React-frontille tehdyt yksikkötestit tai backendin testit, nyt tehtävien End to End -testien ei tarvitse sijaita samassa npm-projektissa missä koodi on. Tehdään E2E-testeille kokonaan oma projekti komennolla _npm init_.
17+
18+
Asennetaan sitten Cypress suorittamalla uuden projektin kehitysaikaiseksi riippuvuudeksi
1719

1820
```js
1921
npm install --save-dev cypress
@@ -25,20 +27,12 @@ ja määritellään npm-skripti käynnistämistä varten, ja tehdään myös pie
2527
{
2628
// ...
2729
"scripts": {
28-
"dev": "vite --host", // highlight-line
29-
"build": "vite build",
30-
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
31-
"preview": "vite preview",
32-
"server": "json-server -p3001 --watch db.json",
33-
"test": "jest",
3430
"cypress:open": "cypress open" // highlight-line
3531
},
3632
// ...
3733
}
3834
```
3935

40-
Toisin kuin esim. frontendin yksikkötestit, Cypress-testit voidaan sijoittaa joko frontendin tai backendin repositorioon, tai vaikka kokonaan omaan repositorioonsa.
41-
4236
Cypress-testit olettavat että testattava järjestelmä on käynnissä kun testit suoritetaan, eli toisin kuin esim. backendin integraatiotestit, Cypress-testit <i>eivät käynnistä</i> testattavaa järjestelmää testauksen yhteydessä.
4337

4438
Tehdään <i>backendille</i> npm-skripti, jonka avulla se saadaan käynnistettyä testausmoodissa, eli siten, että <i>NODE\_ENV</i> saa arvon <i>test</i>.
@@ -1013,15 +1007,10 @@ Developer-konsoli on monin tavoin hyödyllinen testejä debugatessa. Network-tab
10131007
10141008
![Console-välilehti havainnollistaa testien löytämiä elementtejä.](../../images/5/38new.png)
10151009
1016-
Olemme toistaiseksi suorittaneet Cypress-testejä ainoastaan graafisen test runnerin kautta. Testit on luonnollisesti mahdollista suorittaa myös [komentoriviltä](https://docs.cypress.io/guides/guides/command-line.html). Lisätään vielä sovellukselle npm-skripti tätä tarkoitusta varten
1010+
Olemme toistaiseksi suorittaneet Cypress-testejä ainoastaan graafisen test runnerin kautta. Testit on luonnollisesti mahdollista suorittaa myös [komentoriviltä](https://docs.cypress.io/guides/guides/command-line.html). Lisätään vielä projektiin npm-skripti tätä tarkoitusta varten
10171011
10181012
```js
10191013
"scripts": {
1020-
"start": "react-scripts start",
1021-
"build": "react-scripts build",
1022-
"test": "react-scripts test",
1023-
"eject": "react-scripts eject",
1024-
"eslint": "eslint .",
10251014
"cypress:open": "cypress open",
10261015
"test:e2e": "cypress run" // highlight-line
10271016
},

0 commit comments

Comments
 (0)