Skip to content

Commit

Permalink
refactor: Restructure project
Browse files Browse the repository at this point in the history
  • Loading branch information
mattphillips committed Mar 8, 2022
1 parent b239074 commit 56d8b45
Show file tree
Hide file tree
Showing 419 changed files with 1,795 additions and 3,576 deletions.
7 changes: 7 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
"expect": true
},
"plugins": ["eslint-plugin-import", "import", "jest"],
"settings": {
"import/resolver": {
"node": {
"moduleDirectory": ["./", "node_modules"]
}
}
},
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
"rules": {
"comma-spacing": [1, { "before": false, "after": true }],
Expand Down
14 changes: 4 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ Thanks for being willing to contribute!
3. `$ yarn test` to validate you've got it working
4. Create a branch for your PR

## Here as part of Hacktoberfest?

Head over to [here](https://hacktoberfest.digitalocean.com/sign_up/register) to signup if you haven't already

## Making changes

- All changes should have unit tests
Expand All @@ -24,12 +20,10 @@ Head over to [here](https://hacktoberfest.digitalocean.com/sign_up/register) to

### New Matchers

- Each matcher should be placed in it's own directory inside of the `matchers` directory.
- A matcher directory should contain the following:
- `index.js` - An export of the matcher in the format expected by Jest. See the docs for an [example](http://facebook.github.io/jest/docs/en/expect.html#expectextendmatchers). Note: the test outcome messages must be a function that returns a string (this caught me out 😉).
- `index.test.js` - Test suite that uses the new matcher and make sure it passes.
- `predicate.js` - The function that tests the actual value meets the expected value / behavior.
- `predicate.test.js` - Tests for the predicate both true/false cases must be covered.
- Each matcher should be placed in it's own file inside of the `src/matchers/[matcher].js`.
- A matcher should:
- Export the matcher in the format expected by Jest. See the docs for an [example](http://facebook.github.io/jest/docs/en/expect.html#expectextendmatchers). Note: the test outcome messages must be a function that returns a string (this caught me out 😉).
- Tests for the matcher should go in `test/matchers/[matcher].test.js` - Test suite that uses the new matcher and make sure it passes.
- Docs for the new matcher should be updated in the API section of the `README.md` to no longer say `Unimplemented`.
- Type definitions for the new matchers should be added to `types/index.d.ts`.

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
"snapshotSerializers": [
"pretty-format/build/plugins/ConvertAnsi.js"
],
"moduleNameMapper": {
"src/(.*)": "<rootDir>/src/$1"
},
"coverageThreshold": {
"global": {
"branches": 100,
Expand Down
6 changes: 6 additions & 0 deletions src/matchers/fail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function fail(_, message) {
return {
pass: false,
message: () => (message ? message : 'fails by .fail() assertion'),
};
}
10 changes: 0 additions & 10 deletions src/matchers/fail/index.js

This file was deleted.

1 change: 0 additions & 1 deletion src/matchers/fail/predicate.js

This file was deleted.

7 changes: 0 additions & 7 deletions src/matchers/fail/predicate.test.js

This file was deleted.

6 changes: 6 additions & 0 deletions src/matchers/pass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function pass(_, message) {
return {
pass: true,
message: () => (message ? message : 'passes by .pass() assertion'),
};
}
10 changes: 0 additions & 10 deletions src/matchers/pass/index.js

This file was deleted.

1 change: 0 additions & 1 deletion src/matchers/pass/predicate.js

This file was deleted.

7 changes: 0 additions & 7 deletions src/matchers/pass/predicate.test.js

This file was deleted.

18 changes: 18 additions & 0 deletions src/matchers/toBeAfter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export function toBeAfter(date, after) {
const { printReceived, matcherHint } = this.utils;
const passMessage =
matcherHint('.not.toBeAfter', 'received', '') +
'\n\n' +
`Expected date to be after ${printReceived(after)} but received:\n` +
` ${printReceived(date)}`;

const failMessage =
matcherHint('.toBeAfter', 'received', '') +
'\n\n' +
`Expected date to be after ${printReceived(after)} but received:\n` +
` ${printReceived(date)}`;

const pass = date > after;

return { pass, message: () => (pass ? passMessage : failMessage) };
}
22 changes: 0 additions & 22 deletions src/matchers/toBeAfter/index.js

This file was deleted.

5 changes: 0 additions & 5 deletions src/matchers/toBeAfter/predicate.js

This file was deleted.

14 changes: 0 additions & 14 deletions src/matchers/toBeAfter/predicate.test.js

This file was deleted.

19 changes: 19 additions & 0 deletions src/matchers/toBeAfterOrEqualTo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export function toBeAfterOrEqualTo(actual, expected) {
const { printReceived, matcherHint } = this.utils;

const passMessage =
matcherHint('.not.toBeAfterOrEqualTo', 'received', '') +
'\n\n' +
`Expected date to be after or equal to ${printReceived(expected)} but received:\n` +
` ${printReceived(actual)}`;

const failMessage =
matcherHint('.toBeAfterOrEqualTo', 'received', '') +
'\n\n' +
`Expected date to be after or equal to ${printReceived(expected)} but received:\n` +
` ${printReceived(actual)}`;

const pass = actual >= expected;

return { pass, message: () => (pass ? passMessage : failMessage) };
}
22 changes: 0 additions & 22 deletions src/matchers/toBeAfterOrEqualTo/index.js

This file was deleted.

5 changes: 0 additions & 5 deletions src/matchers/toBeAfterOrEqualTo/predicate.js

This file was deleted.

18 changes: 0 additions & 18 deletions src/matchers/toBeAfterOrEqualTo/predicate.test.js

This file was deleted.

19 changes: 19 additions & 0 deletions src/matchers/toBeArray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export function toBeArray(expected) {
const { matcherHint, printReceived } = this.utils;

const passMessage =
matcherHint('.not.toBeArray', 'received', '') +
'\n\n' +
'Expected value to not be an array received:\n' +
` ${printReceived(expected)}`;

const failMessage =
matcherHint('.toBeArray', 'received', '') +
'\n\n' +
'Expected value to be an array received:\n' +
` ${printReceived(expected)}`;

const pass = Array.isArray(expected);

return { pass, message: () => (pass ? passMessage : failMessage) };
}
22 changes: 0 additions & 22 deletions src/matchers/toBeArray/index.js

This file was deleted.

1 change: 0 additions & 1 deletion src/matchers/toBeArray/predicate.js

This file was deleted.

14 changes: 0 additions & 14 deletions src/matchers/toBeArray/predicate.test.js

This file was deleted.

25 changes: 25 additions & 0 deletions src/matchers/toBeArrayOfSize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { determinePropertyMessage } from '../utils';

export function toBeArrayOfSize(actual, expected) {
const { printExpected, printReceived, matcherHint } = this.utils;

const passMessage = `${matcherHint('.not.toBeArrayOfSize')}
Expected value to not be an array of size:
${printExpected(expected)}
Received:
value: ${printReceived(actual)}
length: ${printReceived(determinePropertyMessage(actual, 'length'))}`;

const failMessage = `${matcherHint('.toBeArrayOfSize')}
Expected value to be an array of size:
${printExpected(expected)}
Received:
value: ${printReceived(actual)}
length: ${printReceived(determinePropertyMessage(actual, 'length'))}`;

const pass = Array.isArray(actual) && actual.length === expected;

return { pass, message: () => (pass ? passMessage : failMessage) };
}
30 changes: 0 additions & 30 deletions src/matchers/toBeArrayOfSize/index.js

This file was deleted.

8 changes: 0 additions & 8 deletions src/matchers/toBeArrayOfSize/predicate.js

This file was deleted.

21 changes: 0 additions & 21 deletions src/matchers/toBeArrayOfSize/predicate.test.js

This file was deleted.

Loading

0 comments on commit 56d8b45

Please sign in to comment.