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

Restructure project #410

Merged
merged 81 commits into from Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from 80 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
db62f1f
Add module name mapper to `src` directory
mattphillips Jan 29, 2022
589ac34
Condense `toBeAfter` into one file
mattphillips Jan 29, 2022
8246b83
Disable all matchers test
mattphillips Jan 29, 2022
2a92a7b
Condense `fail` into one file
mattphillips Jan 29, 2022
5daecb1
Condense `pass` matcher into one file
mattphillips Jan 31, 2022
39f303a
Fix lint errors
mattphillips Jan 31, 2022
29ab13f
Condense `toBeAfterOrEqualTo` matcher into one file
mattphillips Jan 31, 2022
6dd14e6
Condense `toBeArray` matcher into one file
mattphillips Jan 31, 2022
f689d25
Condense `toBeArrayOfSize` matcher into one file
mattphillips Jan 31, 2022
df3f191
Condense `toBeBefore` matcher into one file
mattphillips Jan 31, 2022
225235d
Condense `toBeBeforeOrEqualTo` matcher into one file
mattphillips Jan 31, 2022
b6e429c
Fix broken snapshots
mattphillips Jan 31, 2022
f09acad
Condense `toBeBetween` matcher into one file
mattphillips Jan 31, 2022
789f360
Condense `toBeBoolean` matcher into one file
mattphillips Jan 31, 2022
dbbcb7c
Condense `toBeDate` matcher into one file
mattphillips Jan 31, 2022
df87bc5
Condense `toBeDateString` matcher into one file
mattphillips Jan 31, 2022
b948a9d
Condense `toBeEmpty` matcher into one file
mattphillips Jan 31, 2022
6b69371
Condense `toBeEmptyObject` matcher into one file
mattphillips Jan 31, 2022
7af5b38
Condense `toBeEven` matcher into one file
mattphillips Jan 31, 2022
fa1e3c1
Condense `toBeExtensible` matcher into one file
mattphillips Jan 31, 2022
3d1a693
Remove lambdas from messages
mattphillips Jan 31, 2022
8bc3771
Condense `toBeFalse` matcher into one file
mattphillips Jan 31, 2022
20cea81
Condense `toBeFinite` matcher into one file
mattphillips Jan 31, 2022
733ff39
Condense `toBeFrozen` matcher into one file
mattphillips Jan 31, 2022
b0a61a6
Condense `toBeFunction` matcher into one file
mattphillips Jan 31, 2022
53f1999
Condense `toBeHexadecimal` matcher into one file
mattphillips Jan 31, 2022
72e5900
Condense `toBeInteger` matcher into one file
mattphillips Jan 31, 2022
ab3eaf1
Condense `toBeNaN` matcher into one file
mattphillips Jan 31, 2022
80ca51d
Condense `toBeNegative` matcher into one file
mattphillips Jan 31, 2022
ab2fe38
Condense `toBeNil` matcher into one file
mattphillips Jan 31, 2022
62cf9f0
Condense `toBeNumber` matcher into one file
mattphillips Jan 31, 2022
fc97d82
Condense `toBeObject` matcher into one file
mattphillips Jan 31, 2022
28b7733
Condense `toBeOdd` matcher into one file
mattphillips Jan 31, 2022
dc22c14
Condense `toBeOneOf` matcher into one file
mattphillips Jan 31, 2022
c493e4d
Condense `toBePositive` matcher into one file
mattphillips Jan 31, 2022
e90bd3b
Condense `toBeSealed` matcher into one file
mattphillips Jan 31, 2022
b8eed0f
Condense `toBeString` matcher into one file
mattphillips Jan 31, 2022
5d975fb
Condense `toBeSymbol` matcher into one file
mattphillips Jan 31, 2022
2a97fbe
Condense `toBeTrue` matcher into one file
mattphillips Jan 31, 2022
6274cab
Condense `toBeValidDate` matcher into one file
mattphillips Jan 31, 2022
e473dff
Condense `toBeWithin` matcher into one file
mattphillips Jan 31, 2022
8518a22
Condense `toContainAllEntries` matcher into one file
mattphillips Jan 31, 2022
32f2da6
Condense `toContainAllKeys` matcher into one file
mattphillips Jan 31, 2022
010b514
Condense `toContainAllValues` matcher into one file
mattphillips Jan 31, 2022
af93ba1
Condense `toContainAnyEntries` matcher into one file
mattphillips Jan 31, 2022
d592f09
Condense `toContainAnyKeys` matcher into one file
mattphillips Jan 31, 2022
2c13b4f
Condense `toContainAnyValues` matcher into one file
mattphillips Jan 31, 2022
e1e8dc4
Condense `toContainEntries` matcher into one file
mattphillips Jan 31, 2022
add2912
Condense `toContainEntry` matcher into one file
mattphillips Jan 31, 2022
e72c6d2
Condense `toContainKey` matcher into one file
mattphillips Jan 31, 2022
154cbd9
Condense `toContainKeys` matcher into one file
mattphillips Jan 31, 2022
554eec7
Condense `toContainValue` matcher into one file
mattphillips Jan 31, 2022
d2c7a99
Condense `toContainValues` matcher into one file
mattphillips Jan 31, 2022
72b51cc
Condense `toEndWith` matcher into one file
mattphillips Jan 31, 2022
10c3077
Condense `toEqualCaseInsensitive` matcher into one file
mattphillips Jan 31, 2022
cc8c80e
Condense `toEqualIgnoringWhitespace` matcher into one file
mattphillips Jan 31, 2022
8288b41
Condense `toHaveBeenCalledAfter` matcher into one file
mattphillips Jan 31, 2022
2d54d92
Condense `toHaveBeenCalledBefore` matcher into one file
mattphillips Jan 31, 2022
0d9ec45
Condense `toHaveBeenCalledOnce` matcher into one file
mattphillips Jan 31, 2022
c2f40c7
Condense `toInclude` matcher into one file
mattphillips Jan 31, 2022
ef78f50
Condense `toIncludeAllMembers` matcher into one file
mattphillips Jan 31, 2022
c978845
Condense `toIncludeAllPartialMembers` matcher into one file
mattphillips Jan 31, 2022
2feb7f6
Condense `toIncludeAnyMembers` matcher into one file
mattphillips Jan 31, 2022
44e8f4f
Condense `toIncludeMultiple` matcher into one file
mattphillips Jan 31, 2022
209601e
Condense `toIncludeRepeated` matcher into one file
mattphillips Jan 31, 2022
8d62f8d
Condense `toIncludeSameMembers` matcher into one file
mattphillips Jan 31, 2022
7493919
Condense `toPartiallyContain` matcher into one file
mattphillips Jan 31, 2022
db7c0a5
Condense `toReject` matcher into one file
mattphillips Jan 31, 2022
39506a8
Condense `toResolve` matcher into one file
mattphillips Jan 31, 2022
5dfbd60
Condense `toSatisfy` matcher into one file
mattphillips Jan 31, 2022
a8a9850
Condense `toSatisfyAll` matcher into one file
mattphillips Jan 31, 2022
800da58
Condense `toSatisfyAny` matcher into one file
mattphillips Jan 31, 2022
b15ac5c
Condense `toStartWith` matcher into one file
mattphillips Jan 31, 2022
bb24d0a
Condense `toThrowWithMessage` matcher into one file
mattphillips Jan 31, 2022
410255e
Rename toBeTrue test file
mattphillips Jan 31, 2022
1b160e4
Move matchers integration test to `test` namespace
mattphillips Jan 31, 2022
f585c8b
Move util tests to `test` namespace
mattphillips Jan 31, 2022
f629315
Update contributing docs
mattphillips Jan 31, 2022
e72dd14
Add tests for missing coverage
mattphillips Jan 31, 2022
dae7ff1
Add message checking tests to `toThrowWithMessage`
mattphillips Feb 1, 2022
06c8051
Add set/map/generator to `toBeEmpty` tests
mattphillips Feb 1, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 7 additions & 0 deletions .eslintrc
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
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
keeganwitt marked this conversation as resolved.
Show resolved Hide resolved

## 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
Expand Up @@ -78,6 +78,9 @@
"snapshotSerializers": [
"pretty-format/build/plugins/ConvertAnsi.js"
],
"moduleNameMapper": {
"src/(.*)": "<rootDir>/src/$1"
},
Comment on lines +81 to +83
Copy link
Member

Choose a reason for hiding this comment

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

why do we want this? seems likely to only cause confusion for most tools

Copy link
Member Author

Choose a reason for hiding this comment

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

So that we can import from src in the test files as src/ and test/ are at the same level in the directory instead of having to add ../.. to all imports.

Copy link
Member

@SimenB SimenB Feb 1, 2022

Choose a reason for hiding this comment

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

right, but is avoiding ../ worth breaking "go to definition" etc?

I don't really have a strong opinion here (nor ownership 😀) but in the same way removing the import.all macro makes things not require specific tooling I don't think configuring the resolver of jest and eslint (and later typescript I assume) keeps the code base as approachable as possible.

(if we want something like this, we should use https://nodejs.org/api/packages.html#subpath-imports or something that has an actual spec behind it instead of ad hoc config. That said, Jest does not support it (yet)).


Again, this is your project, not mine, so feel free to structure it how you want to 🙂 Just putting my opinion out there, because what else is the internet for?

Copy link
Member Author

Choose a reason for hiding this comment

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

Again, this is your project, not mine, so feel free to structure it how you want to 🙂 Just putting my opinion out there, because what else is the internet for?

Love this 😆 your opinions are always welcome!


Tbh I setup all of my Typescript projects with the ability to import from src to make it easy to do absolute imports and move stuff around. With vscode at least (when using TS) importing from src doesn't break go to definition, do you know if it does in other editors?

I kind of see this PR as a precursor to switching to TS so hopefully the tooling will be better then.

This all probably stems from my Java days and when I work in Scala and being able to treat directories as packages/namespaces regardless of source set 😝

Copy link
Member

Choose a reason for hiding this comment

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

I've been writing Rust lately, so I feel this 😀

"coverageThreshold": {
"global": {
"branches": 100,
Expand Down
6 changes: 6 additions & 0 deletions src/matchers/fail.js
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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.