Skip to content

Commit aab69c9

Browse files
authored
test: lint vitest (#2098)
1 parent 1c9043b commit aab69c9

15 files changed

+139
-119
lines changed

.eslintrc.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ module.exports = defineConfig({
2929
rules: {
3030
// We may want to use this in the future
3131
'no-useless-escape': 'off',
32-
'deprecation/deprecation': 'error',
3332
eqeqeq: ['error', 'always', { null: 'ignore' }],
3433
'no-else-return': 'error',
3534
'prefer-template': 'error',
35+
36+
'deprecation/deprecation': 'error',
37+
3638
'@typescript-eslint/array-type': [
3739
'error',
3840
{ default: 'array-simple', readonly: 'generic' },
@@ -112,8 +114,10 @@ module.exports = defineConfig({
112114
},
113115
{
114116
files: ['test/*.spec.ts'],
117+
extends: ['plugin:vitest/recommended'],
115118
rules: {
116119
'deprecation/deprecation': 'off',
120+
117121
'@typescript-eslint/restrict-template-expressions': [
118122
'error',
119123
{
@@ -122,6 +126,9 @@ module.exports = defineConfig({
122126
allowAny: true,
123127
},
124128
],
129+
130+
'vitest/expect-expect': 'off',
131+
'vitest/valid-expect': ['error', { maxArgs: 2 }],
125132
},
126133
},
127134
],

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
"eslint-plugin-deprecation": "~1.4.1",
119119
"eslint-plugin-jsdoc": "~44.0.0",
120120
"eslint-plugin-prettier": "~4.2.1",
121+
"eslint-plugin-vitest": "~0.2.2",
121122
"glob": "~10.2.2",
122123
"npm-run-all": "~4.1.5",
123124
"picocolors": "~1.0.0",

pnpm-lock.yaml

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/all_functional.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ describe('BROKEN_LOCALE_METHODS test', () => {
138138
});
139139

140140
Object.keys(modules).forEach((module) => {
141-
describe(module, () => {
141+
describe(`${module}`, () => {
142142
it('should not contain obsolete configuration (methods)', () => {
143143
const existingMethods = modules[module];
144144
const configuredMethods = Object.keys(
@@ -157,14 +157,14 @@ describe('BROKEN_LOCALE_METHODS test', () => {
157157

158158
describe('functional tests', () => {
159159
for (const [locale, faker] of Object.entries(allFakers)) {
160-
describe(locale, () => {
160+
describe(`${locale}`, () => {
161161
if (locale === 'base') {
162162
it.skip('base locale is checked by other tests');
163163
return;
164164
}
165165

166166
Object.keys(modules).forEach((module) => {
167-
describe(module, () => {
167+
describe(`${module}`, () => {
168168
modules[module].forEach((meth) => {
169169
const testAssertion = () => {
170170
// TODO @ST-DDT 2022-03-28: Use random seed once there are no more failures
@@ -195,14 +195,14 @@ describe('functional tests', () => {
195195

196196
describe('faker.helpers.fake functional tests', () => {
197197
for (const [locale, faker] of Object.entries(allFakers)) {
198-
describe(locale, () => {
198+
describe(`${locale}`, () => {
199199
if (locale === 'base') {
200200
it.skip('base locale is checked by other tests');
201201
return;
202202
}
203203

204204
Object.keys(modules).forEach((module) => {
205-
describe(module, () => {
205+
describe(`${module}`, () => {
206206
modules[module].forEach((meth) => {
207207
const testAssertion = () => {
208208
// TODO @ST-DDT 2022-03-28: Use random seed once there are no more failures

test/commerce.spec.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,14 @@ describe('commerce', () => {
110110
const price = faker.commerce.price(100, 100, 1);
111111

112112
expect(price).toBeTruthy();
113-
expect(price, 'the price should be equal 100.0').toStrictEqual(
114-
'100.0'
115-
);
113+
expect(price, 'the price should be equal 100.0').toBe('100.0');
116114
});
117115

118116
it('should handle argument dec = 0', () => {
119117
const price = faker.commerce.price(100, 100, 0);
120118

121119
expect(price).toBeTruthy();
122-
expect(price, 'the price should be equal 100').toStrictEqual('100');
120+
expect(price, 'the price should be equal 100').toBe('100');
123121
});
124122
});
125123

test/datatype.spec.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from 'vitest';
2-
import { faker } from '../src';
2+
import { faker, FakerError } from '../src';
33
import { seededTests } from './support/seededRuns';
44

55
const NON_SEEDED_BASED_RUN = 25;
@@ -226,7 +226,9 @@ describe('datatype', () => {
226226

227227
expect(() => {
228228
faker.datatype.number({ min, max });
229-
}).toThrowError(`Max ${max} should be greater than min ${min}.`);
229+
}).toThrow(
230+
new FakerError(`Max ${max} should be greater than min ${min}.`)
231+
);
230232
});
231233
});
232234

test/finance.spec.ts

+11-17
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,7 @@ describe('finance', () => {
265265
amount = faker.finance.amount(100, 100, 1);
266266

267267
expect(amount).toBeTruthy();
268-
expect(amount, 'the amount should be equal 100.0').toStrictEqual(
269-
'100.0'
270-
);
268+
expect(amount, 'the amount should be equal 100.0').toBe('100.0');
271269
});
272270

273271
//TODO: add support for more currency and decimal options
@@ -280,7 +278,7 @@ describe('finance', () => {
280278
).toMatch(/^[0-9\.]+$/);
281279
});
282280

283-
it('it should handle negative amounts', () => {
281+
it('should handle negative amounts', () => {
284282
const amount = faker.finance.amount(-200, -1);
285283

286284
expect(amount).toBeTruthy();
@@ -292,23 +290,21 @@ describe('finance', () => {
292290
).toBeGreaterThan(-201);
293291
});
294292

295-
it('it should handle argument dec', () => {
293+
it('should handle argument dec', () => {
296294
const amount = faker.finance.amount(100, 100, 1);
297295

298296
expect(amount).toBeTruthy();
299-
expect(amount, 'the amount should be equal 100.0').toStrictEqual(
300-
'100.0'
301-
);
297+
expect(amount, 'the amount should be equal 100.0').toBe('100.0');
302298
});
303299

304-
it('it should handle argument dec = 0', () => {
300+
it('should handle argument dec = 0', () => {
305301
const amount = faker.finance.amount(100, 100, 0);
306302

307303
expect(amount).toBeTruthy();
308-
expect(amount, 'the amount should be equal 100').toStrictEqual('100');
304+
expect(amount, 'the amount should be equal 100').toBe('100');
309305
});
310306

311-
it('it should return a string', () => {
307+
it('should return a string', () => {
312308
const amount = faker.finance.amount(100, 100, 0);
313309

314310
expect(amount).toBeTruthy();
@@ -542,9 +538,7 @@ describe('finance', () => {
542538
});
543539

544540
it('should throw an error when length is less than 1', () => {
545-
expect(() => faker.finance.pin(-5)).toThrowError(
546-
/^minimum length is 1$/
547-
);
541+
expect(() => faker.finance.pin(-5)).toThrow(/^minimum length is 1$/);
548542
});
549543
});
550544

@@ -565,7 +559,7 @@ describe('finance', () => {
565559
expect(
566560
ibanLib.mod97(ibanLib.toDigitString(bban)),
567561
'the result should be equal to 1'
568-
).toStrictEqual(1);
562+
).toBe(1);
569563
});
570564

571565
it('should return a specific and formally correct IBAN number', () => {
@@ -577,15 +571,15 @@ describe('finance', () => {
577571
expect(
578572
ibanLib.mod97(ibanLib.toDigitString(bban)),
579573
'the result should be equal to 1'
580-
).toStrictEqual(1);
574+
).toBe(1);
581575
});
582576

583577
it.each(['AA', 'EU'])(
584578
'throws an error for unsupported country code "%s"',
585579
(unsupportedCountryCode) =>
586580
expect(() =>
587581
faker.finance.iban(false, unsupportedCountryCode)
588-
).toThrowError(
582+
).toThrow(
589583
new FakerError(
590584
`Country code ${unsupportedCountryCode} not supported.`
591585
)

test/finance_iban.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ describe('finance_iban', () => {
303303
0,
304304
2
305305
)}must start with 'CR' in CR IBAN ${ibanFormated}`
306-
).to.eq('CR');
306+
).toBe('CR');
307307

308308
expect(
309309
iban.substring(2, 22),

0 commit comments

Comments
 (0)