Skip to content

Commit c4d5d42

Browse files
committed
Update section about eslint error with vitest keywords
1 parent 1b21810 commit c4d5d42

File tree

2 files changed

+35
-45
lines changed

2 files changed

+35
-45
lines changed

src/content/5/en/part5c.md

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -150,33 +150,28 @@ $ npm test
150150
PASS Waiting for file changes...
151151
```
152152

153-
Eslint complains about the keywords _test_ and _expect_ in the tests. The problem can be solved by installing [eslint-plugin-vitest-globals](https://www.npmjs.com/package/eslint-plugin-vitest-globals):
154-
155-
```
156-
npm install --save-dev eslint-plugin-vitest-globals
157-
```
158-
159-
and enable the plugin by editing the _.eslintrc.cjs_ file as follows:
153+
Eslint complains about the keywords _test_ and _expect_ in the tests. The problem can be solved by adding the following configuration to the <i>eslint.config.js</i> file:
160154

161155
```js
162-
module.exports = {
163-
root: true,
164-
env: {
165-
browser: true,
166-
es2020: true,
167-
"vitest-globals/env": true // highlight-line
168-
},
169-
extends: [
170-
'eslint:recommended',
171-
'plugin:react/recommended',
172-
'plugin:react/jsx-runtime',
173-
'plugin:react-hooks/recommended',
174-
'plugin:vitest-globals/recommended', // highlight-line
175-
],
156+
// ...
157+
158+
export default [
176159
// ...
177-
}
160+
// highlight-start
161+
{
162+
files: ['**/*.test.{js,jsx}'],
163+
languageOptions: {
164+
globals: {
165+
...globals.vitest
166+
}
167+
}
168+
}
169+
// highlight-end
170+
]
178171
```
179172

173+
This is how ESLint is informed that Vitest keywords are globally available in test files.
174+
180175
### Test file location
181176

182177
In React there are (at least) [two different conventions](https://medium.com/@JeffLombardJr/organizing-tests-in-jest-17fc431ff850) for the test file's location. We created our test files according to the current standard by placing them in the same directory as the component being tested.

src/content/5/fi/osa5c.md

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -154,32 +154,27 @@ $ npm test
154154

155155
Kuten olettaa saattaa, testi menee läpi.
156156

157-
Eslint valittaa testeissä olevista avainsanoista _test_ ja _expect_. Ongelmasta päästään eroon asentamalla [eslint-plugin-vitest-globals](https://www.npmjs.com/package/eslint-plugin-vitest-globals):
158-
159-
```
160-
npm install --save-dev eslint-plugin-vitest-globals
161-
```
162-
163-
ja ottamalla plugin käyttöön muokkaamalla tiedostoa _.eslint.cjs_ seuraavasti:
157+
Eslint valittaa testeissä olevista avainsanoista _test_ ja _expect_. Ongelmasta päästään eroon lisäämällä tiedostoon <i>eslint.config.js</i> seuraava määrittely:
164158

165159
```js
166-
module.exports = {
167-
root: true,
168-
env: {
169-
browser: true,
170-
es2020: true,
171-
"vitest-globals/env": true // highlight-line
172-
},
173-
extends: [
174-
'eslint:recommended',
175-
'plugin:react/recommended',
176-
'plugin:react/jsx-runtime',
177-
'plugin:react-hooks/recommended',
178-
'plugin:vitest-globals/recommended', // highlight-line
179-
],
160+
// ...
161+
162+
export default [
180163
// ...
181-
}
182-
```
164+
// highlight-start
165+
{
166+
files: ['**/*.test.{js,jsx}'],
167+
languageOptions: {
168+
globals: {
169+
...globals.vitest
170+
}
171+
}
172+
}
173+
// highlight-end
174+
]
175+
```
176+
177+
Näin ESLintille kerrotaan, että Vitestin avainsanat ovat testitiedostoissa globaalisti saatavilla.
183178

184179
### Testien sijainti
185180

0 commit comments

Comments
 (0)