Skip to content

Commit

Permalink
Lint tests using eslint-vitest-plugin
Browse files Browse the repository at this point in the history
Also adds commented `all` Vitest ESLintconfig for later testing purpose.
  • Loading branch information
meduzen authored Apr 8, 2024
1 parent fb5f3c3 commit 335472b
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 53 deletions.
19 changes: 18 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import tseslint from 'typescript-eslint'
import js from '@eslint/js'
import vitest from 'eslint-plugin-vitest'

export default tseslint.config(
js.configs.recommended,

{
files: ['**/*.js'],
languageOptions: {
Expand Down Expand Up @@ -64,4 +64,21 @@ export default tseslint.config(
'template-tag-spacing': [2, 'always'],
},
},
{
files: ['**/*.test.js'],
plugins: { vitest },
rules: {
...vitest.configs.recommended.rules,
// ...vitest.configs.all.rules, // worth testing from time to time…
// 'vitest/consistent-test-it': 0,
'vitest/no-test-return-statement': 1,
// 'vitest/prefer-expect-assertions': 0, // when testing `vitest.configs.all.rules`
'vitest/require-to-throw-message': 1,
},
languageOptions: {
globals: {
...vitest.environments.env.globals,
},
},
},
)
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@
"@vitest/coverage-v8": "^1.4.0",
"@vitest/ui": "^1.4.0",
"eslint": "^9.0.0",
"eslint-plugin-vitest": "0.4.2-beta.5",
"size-limit": "^11.1.2",
"tsd": "^0.31.0",
"typescript": "^5.4.4",
"typescript-eslint": "^7.5.0",
"typescript-eslint": "^7.6.0",
"vitest": "^1.4.0"
},
"pnpm": {
Expand Down
120 changes: 72 additions & 48 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ describe('duration', () => {
const durationInDays = { d: 43 }

test('is a function', () => expect(duration).toBeInstanceOf(Function))
test('()', () => expect(() => duration(null)).toThrow())
test('(null)', () => expect(() => duration(null)).toThrow(Error))
test('()', () => expect(duration()).toBe('PT0S'))
test('empty object {}', () => expect(duration({})).toBe('PT0S'))
test('empty object {}', () => expect(duration({}, false)).toBe('PT0S'))
test('empty object {} and preserve excess value', () => expect(duration({}, false)).toBe('PT0S'))

test('complete object', () => expect(duration(durationObject)).toBe('P3W5DT10H43M2.61S'))
test('complete object with too high values', () => expect(duration(durationWithTooHighValues)).toBe('P5W6DT12H55M55.3S'))
Expand Down Expand Up @@ -257,7 +257,7 @@ describe('DateTime class', () => {
test(".to('month')", () => expect(twoWeeksAfterSummer.to('month')).toBe('2021-07'))
test('weeks is changed when day changes', () => {
summer.setDate(summer.getDate() + 14)
return expect(summer.getWeek()).toBe(29)
expect(summer.getWeek()).toBe(29)
})
})

Expand Down

0 comments on commit 335472b

Please sign in to comment.