Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: lint vitest #2098

Merged
merged 6 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ module.exports = defineConfig({
rules: {
// We may want to use this in the future
'no-useless-escape': 'off',
'deprecation/deprecation': 'error',
eqeqeq: ['error', 'always', { null: 'ignore' }],
'no-else-return': 'error',
'prefer-template': 'error',

'deprecation/deprecation': 'error',

'@typescript-eslint/array-type': [
'error',
{ default: 'array-simple', readonly: 'generic' },
Expand Down Expand Up @@ -112,8 +114,10 @@ module.exports = defineConfig({
},
{
files: ['test/*.spec.ts'],
extends: ['plugin:vitest/recommended'],
rules: {
'deprecation/deprecation': 'off',

Shinigami92 marked this conversation as resolved.
Show resolved Hide resolved
'@typescript-eslint/restrict-template-expressions': [
'error',
{
Expand All @@ -122,6 +126,9 @@ module.exports = defineConfig({
allowAny: true,
},
],

Shinigami92 marked this conversation as resolved.
Show resolved Hide resolved
'vitest/expect-expect': 'off',
'vitest/valid-expect': ['error', { maxArgs: 2 }],
},
},
],
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
"eslint-plugin-deprecation": "~1.4.1",
"eslint-plugin-jsdoc": "~44.0.0",
"eslint-plugin-prettier": "~4.2.1",
"eslint-plugin-vitest": "~0.2.2",
"glob": "~10.2.2",
"npm-run-all": "~4.1.5",
"picocolors": "~1.0.0",
Expand Down
16 changes: 16 additions & 0 deletions pnpm-lock.yaml

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

10 changes: 5 additions & 5 deletions test/all_functional.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe('BROKEN_LOCALE_METHODS test', () => {
});

Object.keys(modules).forEach((module) => {
describe(module, () => {
describe(`${module}`, () => {
Shinigami92 marked this conversation as resolved.
Show resolved Hide resolved
it('should not contain obsolete configuration (methods)', () => {
const existingMethods = modules[module];
const configuredMethods = Object.keys(
Expand All @@ -157,14 +157,14 @@ describe('BROKEN_LOCALE_METHODS test', () => {

describe('functional tests', () => {
for (const [locale, faker] of Object.entries(allFakers)) {
describe(locale, () => {
describe(`${locale}`, () => {
if (locale === 'base') {
it.skip('base locale is checked by other tests');
return;
}

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

describe('faker.helpers.fake functional tests', () => {
for (const [locale, faker] of Object.entries(allFakers)) {
describe(locale, () => {
describe(`${locale}`, () => {
if (locale === 'base') {
it.skip('base locale is checked by other tests');
return;
}

Object.keys(modules).forEach((module) => {
describe(module, () => {
describe(`${module}`, () => {
modules[module].forEach((meth) => {
const testAssertion = () => {
// TODO @ST-DDT 2022-03-28: Use random seed once there are no more failures
Expand Down
6 changes: 2 additions & 4 deletions test/commerce.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,14 @@ describe('commerce', () => {
const price = faker.commerce.price(100, 100, 1);

expect(price).toBeTruthy();
expect(price, 'the price should be equal 100.0').toStrictEqual(
'100.0'
);
expect(price, 'the price should be equal 100.0').toBe('100.0');
});

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

expect(price).toBeTruthy();
expect(price, 'the price should be equal 100').toStrictEqual('100');
expect(price, 'the price should be equal 100').toBe('100');
});
});

Expand Down
6 changes: 4 additions & 2 deletions test/datatype.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { faker } from '../src';
import { faker, FakerError } from '../src';
import { seededTests } from './support/seededRuns';

const NON_SEEDED_BASED_RUN = 25;
Expand Down Expand Up @@ -226,7 +226,9 @@ describe('datatype', () => {

expect(() => {
faker.datatype.number({ min, max });
}).toThrowError(`Max ${max} should be greater than min ${min}.`);
}).toThrow(
new FakerError(`Max ${max} should be greater than min ${min}.`)
);
});
});

Expand Down
28 changes: 11 additions & 17 deletions test/finance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,7 @@ describe('finance', () => {
amount = faker.finance.amount(100, 100, 1);

expect(amount).toBeTruthy();
expect(amount, 'the amount should be equal 100.0').toStrictEqual(
'100.0'
);
expect(amount, 'the amount should be equal 100.0').toBe('100.0');
});

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

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

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

it('it should handle argument dec', () => {
it('should handle argument dec', () => {
const amount = faker.finance.amount(100, 100, 1);

expect(amount).toBeTruthy();
expect(amount, 'the amount should be equal 100.0').toStrictEqual(
'100.0'
);
expect(amount, 'the amount should be equal 100.0').toBe('100.0');
});

it('it should handle argument dec = 0', () => {
it('should handle argument dec = 0', () => {
const amount = faker.finance.amount(100, 100, 0);

expect(amount).toBeTruthy();
expect(amount, 'the amount should be equal 100').toStrictEqual('100');
expect(amount, 'the amount should be equal 100').toBe('100');
});

it('it should return a string', () => {
it('should return a string', () => {
const amount = faker.finance.amount(100, 100, 0);

expect(amount).toBeTruthy();
Expand Down Expand Up @@ -542,9 +538,7 @@ describe('finance', () => {
});

it('should throw an error when length is less than 1', () => {
expect(() => faker.finance.pin(-5)).toThrowError(
/^minimum length is 1$/
);
expect(() => faker.finance.pin(-5)).toThrow(/^minimum length is 1$/);
});
});

Expand All @@ -565,7 +559,7 @@ describe('finance', () => {
expect(
ibanLib.mod97(ibanLib.toDigitString(bban)),
'the result should be equal to 1'
).toStrictEqual(1);
).toBe(1);
});

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

it.each(['AA', 'EU'])(
'throws an error for unsupported country code "%s"',
(unsupportedCountryCode) =>
expect(() =>
faker.finance.iban(false, unsupportedCountryCode)
).toThrowError(
).toThrow(
Shinigami92 marked this conversation as resolved.
Show resolved Hide resolved
new FakerError(
`Country code ${unsupportedCountryCode} not supported.`
)
Expand Down
2 changes: 1 addition & 1 deletion test/finance_iban.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ describe('finance_iban', () => {
0,
2
)}must start with 'CR' in CR IBAN ${ibanFormated}`
).to.eq('CR');
).toBe('CR');

expect(
iban.substring(2, 22),
Expand Down
Loading