@@ -8,13 +8,16 @@ This package provides Jest helpers for usage in a skills competition environment
88
99- [ Installation] ( #installation )
1010- [ Usage] ( #usage )
11+ - [ Grouping] ( #grouping )
12+ - [ Extra tests] ( #extra-tests )
1113- [ License] ( #license )
1214
1315## Installation
1416
1517** Requirements:**
1618
1719- Node ` 22 ` or greater
20+ - Jest ` 30 ` or greater
1821
1922To install this package, run the following command:
2023
@@ -26,8 +29,8 @@ It is suggested to add the following npm scripts:
2629
2730``` json
2831"scripts" : {
29- "test" : " jest" ,
30- "test:json" : " cross-env SKILLS17_JSON=true jest"
32+ "test" : " jest" ,
33+ "test:json" : " cross-env SKILLS17_JSON=true jest"
3134},
3235```
3336
@@ -61,6 +64,66 @@ folder of your task, next to the `package.json` file.
6164See the [ ` @skills17/task-config ` ] ( https://github.com/skills17/task-config#configuration ) package for a detailed
6265description of all available properties in the ` config.yaml ` file.
6366
67+ ### Grouping
68+
69+ A core concept is test groups. You usually don't want to test everything for one criterion in one
70+ test function but instead split it into multiple ones for a cleaner test class and a better overview.
71+
72+ In JS, tests are grouped by a test name prefix defined in the ` config.yaml ` file.
73+
74+ All ` describe ` s are concatenated with the actual test names before evaluation.
75+
76+ For example, the following test will have the name ` Countries > Overview > lists all countries ` :
77+
78+ ``` typescript
79+ describe (' Countries' , () => {
80+ describe (' Overview' , () => {
81+ it (' lists all countries' , () => {
82+ // ...
83+ });
84+ });
85+ });
86+ ```
87+
88+ To catch and group all tests within the ` Overview ` description, the group matcher can be set to
89+ ` Countries > Overview > .+ ` for example. Each of the tests within that group will now award 1 point
90+ to the group.
91+
92+ ### Extra tests
93+
94+ To prevent cheating, extra tests can be used.
95+ They are not available to the competitors and should test the same things as the normal tests do,
96+ but with different values.
97+
98+ For example, if your normal test contains a check to search the list of all countries by 'Sw* ', copy
99+ the test into an extra test and change the search string to 'Ca* '.
100+ Since the competitors will not know the extra test, it would detect statically returned values that
101+ were returned to satisfy the 'Sw* ' tests instead of actually implement the search logic.
102+
103+ Extra tests are detected by their ` describe ` , which should equal ` 'Extra' ` or ` 'extra' ` . That means
104+ that you can wrap your test in an additional extra ` describe ` like shown below. The other
105+ ` describe ` s and test names should equal the ones from the normal tests. If they don't, a warning
106+ will be displayed.
107+
108+ ``` typescript
109+ describe (' Extra' , () => { // <-- only this describe has to be added
110+ describe (' Countries' , () => {
111+ it (' lists all countries' , () => {
112+ // ...
113+ });
114+ });
115+ });
116+ ```
117+
118+ It usually makes sense to move the extra tests in a separate folder, so the folder can be deleted
119+ before the tasks are distributed to the competitors.
120+ Nothing else needs to be done or configured.
121+
122+ If an extra test fails while the corresponding normal test passes, a warning will be displayed that
123+ a manual review of that test is required since it detected possible cheating.
124+ The penalty then has to be decided manually from case to case, the points visible in the output
125+ assumed that the test passed and there was no cheating.
126+
64127## License
65128
66129[ MIT] ( https://github.com/skills17/jest-helpers/blob/master/LICENSE )
0 commit comments