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

chore: migrate to named exports from rules #363

Merged
merged 3 commits into from Oct 11, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions .eslintrc
Expand Up @@ -33,5 +33,13 @@
"no-trailing-spaces": 1,
"object-curly-spacing": [1, "always"],
"quotes": ["warn", "single", { "avoidEscape": true }]
},
"overrides": [
Copy link
Member Author

@SimenB SimenB Oct 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly to give a squiggle for people rebasing old PRs (in addition to failing tests) - I expect all new to copy the approach of existent ones and not notice this rule

{
"files": "src/matchers/*/index.js",
"rules": {
"import/no-default-export": "error"
}
}
]
}
6 changes: 1 addition & 5 deletions README.md
Expand Up @@ -187,7 +187,6 @@ test('passes when using an asymmetrical matcher', () => {

#### .pass(message)


Passing assertion.

```js
Expand All @@ -196,7 +195,6 @@ expect().pass('should pass');

#### .fail(message)


Failing assertion.

```js
Expand Down Expand Up @@ -303,9 +301,7 @@ Use `.toIncludeAllPartialMembers` when checking if an `Array` contains all of th

```js
test('passes when given array values match the partial members of the set', () => {
expect([{ foo: 'bar', baz: 'qux' }]).toIncludeAllPartialMembers([
{ foo: 'bar' },
]);
expect([{ foo: 'bar', baz: 'qux' }]).toIncludeAllPartialMembers([{ foo: 'bar' }]);
});
```

Expand Down
6 changes: 3 additions & 3 deletions src/matchers/fail/index.js
Expand Up @@ -5,6 +5,6 @@ const failMessage = message => {
else return () => 'fails by .fail() assertion';
};

export default {
fail: (expected, message) => ({ pass: predicate(), message: failMessage(message) }),
};
export function fail(expected, message) {
return { pass: predicate(), message: failMessage(message) };
}
2 changes: 1 addition & 1 deletion src/matchers/fail/index.test.js
@@ -1,4 +1,4 @@
import matcher from './';
import * as matcher from './';

expect.extend(matcher);

Expand Down
195 changes: 64 additions & 131 deletions src/matchers/index.js
@@ -1,131 +1,64 @@
import failMatcher from './fail';
import passMatcher from './pass';
import toBeAfterMatcher from './toBeAfter';
import toBeArrayMatcher from './toBeArray';
import toBeArrayOfSizeMatcher from './toBeArrayOfSize';
import toBeBeforeMatcher from './toBeBefore';
import toBeBooleanMatcher from './toBeBoolean';
import toBeDateMatcher from './toBeDate';
import toBeDateStringMatcher from './toBeDateString';
import toBeEmptyMatcher from './toBeEmpty';
import toBeEmptyObjectMatcher from './toBeEmptyObject';
import toBeEvenMatcher from './toBeEven';
import toBeExtensibleMatcher from './toBeExtensible';
import toBeFalseMatcher from './toBeFalse';
import toBeFiniteMatcher from './toBeFinite';
import toBeFrozenMatcher from './toBeFrozen';
import toBeFunctionMatcher from './toBeFunction';
import toBeHexadecimalMatcher from './toBeHexadecimal';
import toBeIntegerMatcher from './toBeInteger';
import toBeNaNMatcher from './toBeNaN';
import toBeNegativeMatcher from './toBeNegative';
import toBeNilMatcher from './toBeNil';
import toBeNumberMatcher from './toBeNumber';
import toBeObjectMatcher from './toBeObject';
import toBeOddMatcher from './toBeOdd';
import toBeOneOfMatcher from './toBeOneOf';
import toBePositiveMatcher from './toBePositive';
import toBeSealedMatcher from './toBeSealed';
import toBeStringMatcher from './toBeString';
import toBeSymbolMatcher from './toBeSymbol';
import toBeTrueMatcher from './toBeTrue';
import toBeValidDateMatcher from './toBeValidDate';
import toBeWithinMatcher from './toBeWithin';
import toContainAllEntriesMatcher from './toContainAllEntries';
import toContainAllKeysMatcher from './toContainAllKeys';
import toContainAllValuesMatcher from './toContainAllValues';
import toContainAnyEntriesMatcher from './toContainAnyEntries';
import toContainAnyKeysMatcher from './toContainAnyKeys';
import toContainAnyValuesMatcher from './toContainAnyValues';
import toContainEntriesMatcher from './toContainEntries';
import toContainEntryMatcher from './toContainEntry';
import toContainKeyMatcher from './toContainKey';
import toContainKeysMatcher from './toContainKeys';
import toContainValueMatcher from './toContainValue';
import toContainValuesMatcher from './toContainValues';
import toEndWithMatcher from './toEndWith';
import toEqualCaseInsensitiveMatcher from './toEqualCaseInsensitive';
import toHaveBeenCalledAfterMatcher from './toHaveBeenCalledAfter';
import toHaveBeenCalledBeforeMatcher from './toHaveBeenCalledBefore';
import toHaveBeenCalledOnceMatcher from './toHaveBeenCalledOnce';
import toIncludeMatcher from './toInclude';
import toIncludeAllMembersMatcher from './toIncludeAllMembers';
import toIncludeAllPartialMembersMatcher from './toIncludeAllPartialMembers';
import toIncludeAnyMembersMatcher from './toIncludeAnyMembers';
import toIncludeMultipleMatcher from './toIncludeMultiple';
import toIncludeRepeatedMatcher from './toIncludeRepeated';
import toIncludeSameMembersMatcher from './toIncludeSameMembers';
import toRejectMatcher from './toReject';
import toResolveMatcher from './toResolve';
import toSatisfyMatcher from './toSatisfy';
import toSatisfyAllMatcher from './toSatisfyAll';
import toSatisfyAnyMatcher from './toSatisfyAny';
import toStartWithMatcher from './toStartWith';
import toThrowWithMessageMatcher from './toThrowWithMessage';

// this is absolutely horrible, but all matchers are default exports of an object with the name of the matcher

export const fail = failMatcher.fail;
export const pass = passMatcher.pass;
export const toBeAfter = toBeAfterMatcher.toBeAfter;
export const toBeArray = toBeArrayMatcher.toBeArray;
export const toBeArrayOfSize = toBeArrayOfSizeMatcher.toBeArrayOfSize;
export const toBeBefore = toBeBeforeMatcher.toBeBefore;
export const toBeBoolean = toBeBooleanMatcher.toBeBoolean;
export const toBeDate = toBeDateMatcher.toBeDate;
export const toBeDateString = toBeDateStringMatcher.toBeDateString;
export const toBeEmpty = toBeEmptyMatcher.toBeEmpty;
export const toBeEmptyObject = toBeEmptyObjectMatcher.toBeEmptyObject;
export const toBeEven = toBeEvenMatcher.toBeEven;
export const toBeExtensible = toBeExtensibleMatcher.toBeExtensible;
export const toBeFalse = toBeFalseMatcher.toBeFalse;
export const toBeFinite = toBeFiniteMatcher.toBeFinite;
export const toBeFrozen = toBeFrozenMatcher.toBeFrozen;
export const toBeFunction = toBeFunctionMatcher.toBeFunction;
export const toBeHexadecimal = toBeHexadecimalMatcher.toBeHexadecimal;
export const toBeInteger = toBeIntegerMatcher.toBeInteger;
export const toBeNaN = toBeNaNMatcher.toBeNaN;
export const toBeNegative = toBeNegativeMatcher.toBeNegative;
export const toBeNil = toBeNilMatcher.toBeNil;
export const toBeNumber = toBeNumberMatcher.toBeNumber;
export const toBeObject = toBeObjectMatcher.toBeObject;
export const toBeOdd = toBeOddMatcher.toBeOdd;
export const toBeOneOf = toBeOneOfMatcher.toBeOneOf;
export const toBePositive = toBePositiveMatcher.toBePositive;
export const toBeSealed = toBeSealedMatcher.toBeSealed;
export const toBeString = toBeStringMatcher.toBeString;
export const toBeSymbol = toBeSymbolMatcher.toBeSymbol;
export const toBeTrue = toBeTrueMatcher.toBeTrue;
export const toBeValidDate = toBeValidDateMatcher.toBeValidDate;
export const toBeWithin = toBeWithinMatcher.toBeWithin;
export const toContainAllEntries = toContainAllEntriesMatcher.toContainAllEntries;
export const toContainAllKeys = toContainAllKeysMatcher.toContainAllKeys;
export const toContainAllValues = toContainAllValuesMatcher.toContainAllValues;
export const toContainAnyEntries = toContainAnyEntriesMatcher.toContainAnyEntries;
export const toContainAnyKeys = toContainAnyKeysMatcher.toContainAnyKeys;
export const toContainAnyValues = toContainAnyValuesMatcher.toContainAnyValues;
export const toContainEntries = toContainEntriesMatcher.toContainEntries;
export const toContainEntry = toContainEntryMatcher.toContainEntry;
export const toContainKey = toContainKeyMatcher.toContainKey;
export const toContainKeys = toContainKeysMatcher.toContainKeys;
export const toContainValue = toContainValueMatcher.toContainValue;
export const toContainValues = toContainValuesMatcher.toContainValues;
export const toEndWith = toEndWithMatcher.toEndWith;
export const toEqualCaseInsensitive = toEqualCaseInsensitiveMatcher.toEqualCaseInsensitive;
export const toHaveBeenCalledAfter = toHaveBeenCalledAfterMatcher.toHaveBeenCalledAfter;
export const toHaveBeenCalledBefore = toHaveBeenCalledBeforeMatcher.toHaveBeenCalledBefore;
export const toHaveBeenCalledOnce = toHaveBeenCalledOnceMatcher.toHaveBeenCalledOnce;
export const toInclude = toIncludeMatcher.toInclude;
export const toIncludeAllMembers = toIncludeAllMembersMatcher.toIncludeAllMembers;
export const toIncludeAllPartialMembers = toIncludeAllPartialMembersMatcher.toIncludeAllPartialMembers;
export const toIncludeAnyMembers = toIncludeAnyMembersMatcher.toIncludeAnyMembers;
export const toIncludeMultiple = toIncludeMultipleMatcher.toIncludeMultiple;
export const toIncludeRepeated = toIncludeRepeatedMatcher.toIncludeRepeated;
export const toIncludeSameMembers = toIncludeSameMembersMatcher.toIncludeSameMembers;
export const toReject = toRejectMatcher.toReject;
export const toResolve = toResolveMatcher.toResolve;
export const toSatisfy = toSatisfyMatcher.toSatisfy;
export const toSatisfyAll = toSatisfyAllMatcher.toSatisfyAll;
export const toSatisfyAny = toSatisfyAnyMatcher.toSatisfyAny;
export const toStartWith = toStartWithMatcher.toStartWith;
export const toThrowWithMessage = toThrowWithMessageMatcher.toThrowWithMessage;
export { fail } from './fail';
export { pass } from './pass';
export { toBeAfter } from './toBeAfter';
export { toBeArray } from './toBeArray';
export { toBeArrayOfSize } from './toBeArrayOfSize';
export { toBeBefore } from './toBeBefore';
export { toBeBoolean } from './toBeBoolean';
export { toBeDate } from './toBeDate';
export { toBeDateString } from './toBeDateString';
export { toBeEmpty } from './toBeEmpty';
export { toBeEmptyObject } from './toBeEmptyObject';
export { toBeEven } from './toBeEven';
export { toBeExtensible } from './toBeExtensible';
export { toBeFalse } from './toBeFalse';
export { toBeFinite } from './toBeFinite';
export { toBeFrozen } from './toBeFrozen';
export { toBeFunction } from './toBeFunction';
export { toBeHexadecimal } from './toBeHexadecimal';
export { toBeInteger } from './toBeInteger';
export { toBeNaN } from './toBeNaN';
export { toBeNegative } from './toBeNegative';
export { toBeNil } from './toBeNil';
export { toBeNumber } from './toBeNumber';
export { toBeObject } from './toBeObject';
export { toBeOdd } from './toBeOdd';
export { toBeOneOf } from './toBeOneOf';
export { toBePositive } from './toBePositive';
export { toBeSealed } from './toBeSealed';
export { toBeString } from './toBeString';
export { toBeSymbol } from './toBeSymbol';
export { toBeTrue } from './toBeTrue';
export { toBeValidDate } from './toBeValidDate';
export { toBeWithin } from './toBeWithin';
export { toContainAllEntries } from './toContainAllEntries';
export { toContainAllKeys } from './toContainAllKeys';
export { toContainAllValues } from './toContainAllValues';
export { toContainAnyEntries } from './toContainAnyEntries';
export { toContainAnyKeys } from './toContainAnyKeys';
export { toContainAnyValues } from './toContainAnyValues';
export { toContainEntries } from './toContainEntries';
export { toContainEntry } from './toContainEntry';
export { toContainKey } from './toContainKey';
export { toContainKeys } from './toContainKeys';
export { toContainValue } from './toContainValue';
export { toContainValues } from './toContainValues';
export { toEndWith } from './toEndWith';
export { toEqualCaseInsensitive } from './toEqualCaseInsensitive';
export { toHaveBeenCalledAfter } from './toHaveBeenCalledAfter';
export { toHaveBeenCalledBefore } from './toHaveBeenCalledBefore';
export { toHaveBeenCalledOnce } from './toHaveBeenCalledOnce';
export { toInclude } from './toInclude';
export { toIncludeAllMembers } from './toIncludeAllMembers';
export { toIncludeAllPartialMembers } from './toIncludeAllPartialMembers';
export { toIncludeAnyMembers } from './toIncludeAnyMembers';
export { toIncludeMultiple } from './toIncludeMultiple';
export { toIncludeRepeated } from './toIncludeRepeated';
export { toIncludeSameMembers } from './toIncludeSameMembers';
export { toReject } from './toReject';
export { toResolve } from './toResolve';
export { toSatisfy } from './toSatisfy';
export { toSatisfyAll } from './toSatisfyAll';
export { toSatisfyAny } from './toSatisfyAny';
export { toStartWith } from './toStartWith';
export { toThrowWithMessage } from './toThrowWithMessage';
9 changes: 8 additions & 1 deletion src/matchers/index.test.js
Expand Up @@ -48,8 +48,15 @@ describe('asymmetric matchers', () => {
describe('all matchers', () => {
test('must be exported', () => {
const directories = fs.readdirSync(__dirname).filter(dir => fs.statSync(path.join(__dirname, dir)).isDirectory());
const namedMatchers = Object.keys(matchers);

expect(Object.keys(matchers)).toHaveLength(directories.length);
try {
expect(namedMatchers).toHaveLength(directories.length);
} catch (error) {
const missing = new Set(directories.filter(dir => !namedMatchers.includes(dir)));
console.error('Missing', missing);
throw error;
}
});

describe('must be functions', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/matchers/pass/index.js
Expand Up @@ -5,6 +5,6 @@ const passMessage = message => {
else return () => 'passes by .pass() assertion';
};

export default {
pass: (expected, message) => ({ pass: predicate(), message: passMessage(message) }),
};
export function pass(expected, message) {
return { pass: predicate(), message: passMessage(message) };
}
2 changes: 1 addition & 1 deletion src/matchers/pass/index.test.js
@@ -1,4 +1,4 @@
import matcher from './';
import * as matcher from './';

expect.extend(matcher);

Expand Down
6 changes: 2 additions & 4 deletions src/matchers/toBeAfter/index.js
Expand Up @@ -14,13 +14,11 @@ const failMessage = (received, after) => () =>
`Expected date to be after ${printReceived(after)} but received:\n` +
` ${printReceived(received)}`;

export default {
toBeAfter: (date, after) => {
export function toBeAfter(date, after) {
const pass = predicate(date, after);
if (pass) {
return { pass: true, message: passMessage(date, after) };
}

return { pass: false, message: failMessage(date, after) };
},
};
}
2 changes: 1 addition & 1 deletion src/matchers/toBeAfter/index.test.js
@@ -1,4 +1,4 @@
import matcher from './';
import * as matcher from './';

expect.extend(matcher);

Expand Down
6 changes: 2 additions & 4 deletions src/matchers/toBeArray/index.js
Expand Up @@ -14,13 +14,11 @@ const failMessage = received => () =>
'Expected value to be an array received:\n' +
` ${printReceived(received)}`;

export default {
toBeArray: expected => {
export function toBeArray(expected) {
const pass = predicate(expected);
if (pass) {
return { pass: true, message: passMessage(expected) };
}

return { pass: false, message: failMessage(expected) };
},
};
}
2 changes: 1 addition & 1 deletion src/matchers/toBeArray/index.test.js
@@ -1,4 +1,4 @@
import matcher from './';
import * as matcher from './';

expect.extend(matcher);

Expand Down
6 changes: 2 additions & 4 deletions src/matchers/toBeArrayOfSize/index.js
Expand Up @@ -21,13 +21,11 @@ Received:
value: ${printReceived(actual)}
length: ${printReceived(determinePropertyMessage(actual, 'length'))}`;

export default {
toBeArrayOfSize: (actual, expected) => {
export function toBeArrayOfSize(actual, expected) {
const pass = predicate(actual, expected);
if (pass) {
return { pass: true, message: passMessage(actual, expected) };
}

return { pass: false, message: failMessage(actual, expected) };
},
};
}
2 changes: 1 addition & 1 deletion src/matchers/toBeArrayOfSize/index.test.js
@@ -1,4 +1,4 @@
import matcher from './';
import * as matcher from './';

expect.extend(matcher);

Expand Down
6 changes: 2 additions & 4 deletions src/matchers/toBeBefore/index.js
Expand Up @@ -14,13 +14,11 @@ const failMessage = (received, before) => () =>
`Expected date to be before ${printReceived(before)} but received:\n` +
` ${printReceived(received)}`;

export default {
toBeBefore: (date, before) => {
export function toBeBefore(date, before) {
const pass = predicate(date, before);
if (pass) {
return { pass: true, message: passMessage(date, before) };
}

return { pass: false, message: failMessage(date, before) };
},
};
}
2 changes: 1 addition & 1 deletion src/matchers/toBeBefore/index.test.js
@@ -1,4 +1,4 @@
import matcher from './';
import * as matcher from './';

expect.extend(matcher);

Expand Down
6 changes: 2 additions & 4 deletions src/matchers/toBeBoolean/index.js
Expand Up @@ -14,13 +14,11 @@ const failMessage = received => () =>
'Expected value to be of type boolean, received:\n' +
` ${printReceived(received)}`;

export default {
toBeBoolean: received => {
export function toBeBoolean(received) {
const pass = predicate(received);
if (pass) {
return { pass: true, message: passMessage(received) };
}

return { pass: false, message: failMessage(received) };
},
};
}
2 changes: 1 addition & 1 deletion src/matchers/toBeBoolean/index.test.js
@@ -1,4 +1,4 @@
import matcher from './';
import * as matcher from './';

expect.extend(matcher);

Expand Down