Skip to content

Commit

Permalink
feat: respect length on array. (#69)
Browse files Browse the repository at this point in the history
feat: respect length on array.

feat: add `startsWith()` for existing behavior

BREAKING CHANGE: array will now fail when the length does not match.

Removed `AtLeaseOnce`. It is the same as `has()`

feat: support `anything`

BREAKING CHANGE: undefined will check against undefined.

Use `anything` for the previous `undefined` support

feat: Add formatDiffs

chore: only run tests on node@11

because of bigint tests.
  • Loading branch information
unional authored Mar 13, 2019
1 parent 987ffa3 commit 32ffe11
Show file tree
Hide file tree
Showing 30 changed files with 1,403 additions and 1,052 deletions.
51 changes: 25 additions & 26 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@ workflows:
all:
jobs:
- node-latest
- node10:
requires:
- node-latest
- node9:
requires:
- node-latest
- node8:
requires:
- node-latest
- node6:
requires:
- node-latest
# - node10:
# requires:
# - node-latest
# - node9:
# requires:
# - node-latest
# - node8:
# requires:
# - node-latest
# - node6:
# requires:
# - node-latest
- release:
filters:
branches:
only: master
requires:
- node-latest
- node10
- node9
- node8
- node6
# - node10
# - node9
# - node8
# - node6
jobs:
local:
docker:
- image: circleci/node:11
steps:
- checkout
- run: npm run verify
- run: yarn verify
node-latest:
docker:
- image: circleci/node:11
Expand All @@ -45,8 +45,7 @@ jobs:
name: Install Dependencies
command: |
if [ ! -d node_modules ]; then
npm ci
npm i --no-save jest-junit
yarn install
fi
- save_cache:
name: Save node modules cache
Expand All @@ -57,8 +56,8 @@ jobs:
root: '.'
paths:
- node_modules
- run: npm run verify
- run: npx codecov
- run: yarn verify
- run: yarn codecov
- store_test_results:
path: .reports/junit
node10:
Expand All @@ -68,7 +67,7 @@ jobs:
- checkout
- attach_workspace:
at: '.'
- run: npm run verify
- run: yarn verify
- store_test_results:
path: .reports/junit
node9:
Expand All @@ -78,7 +77,7 @@ jobs:
- checkout
- attach_workspace:
at: '.'
- run: npm run verify
- run: yarn verify
- store_test_results:
path: .reports/junit
node8:
Expand All @@ -88,7 +87,7 @@ jobs:
- checkout
- attach_workspace:
at: '.'
- run: npm run verify
- run: yarn verify
- store_test_results:
path: .reports/junit
node6:
Expand All @@ -98,7 +97,7 @@ jobs:
- checkout
- attach_workspace:
at: '.'
- run: npm run verify
- run: yarn verify
- store_test_results:
path: .reports/junit
release:
Expand All @@ -108,5 +107,5 @@ jobs:
- checkout
- attach_workspace:
at: '.'
- run: npm run clean && npm run build
- run: yarn clean && yarn build
- run: npx semantic-release
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ notifications:
email: false
node_js:
- '11'
- '10'
- '9'
- '8'
- '6'
# - '10'
# - '9'
# - '8'
# - '6'
branches:
only:
- master
- /^greenkeeper.*$/
script:
- npm i --no-save jest-junit
- npm run verify
- yarn verify
- ./scripts/run-on-node-version.sh 11 "npm install -g codacy-coverage && cat ./coverage/lcov.info | codacy-coverage"
- ./scripts/run-on-node-version.sh 11 "npm install -g coveralls && cat ./coverage/lcov.info | coveralls"
36 changes: 17 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
[![Visual Studio Code][vscode-image]][vscode-url]
[![Wallaby.js][wallaby-image]][wallaby-url]

Manage and generate artifacts to test data across boundaries.
A purposely loose comparison tool.

## Version 5 breaking changes

- exact check on array
- no spread on array, use `has()/some()` or `every()`
- `undefined` now checks against `undefined` instead of a placeholder for anything. Use `anything` for the previous behavior.

## createSatisfier(expectation)

Expand Down Expand Up @@ -65,20 +71,16 @@ createSatisfier({ a: /boo/ }).exec({ a: 'foo' })
createSatisfier({ a: a => a === 1 }).exec({ a: 2 })
```

## Meaning of undefined
## `anything`

If `undefined` is used in expectation, it will match anything.
If `anything` is used in expectation, it will match anything.

```ts
createSatisfier(underfined).test({})
createSatisfier({ a: undefined }).test({})
createSatisfier([undefined, 1]).test(['x', 1])
```
import { anything } from 'satisfier'

If you want to test for `undefined` explicitly, use predicate function.

```ts
createSatisfier(x => x === undefined).test(undefined)
createSatisfier(anything).test({})
createSatisfier({ a: anything }).test({})
createSatisfier([anything, 1]).test(['x', 1])
```

## test against array
Expand All @@ -90,18 +92,14 @@ There are several ways to test against array:
When you use an array expectation to test against array,
each entry in the expectation will be used to test against the corresponding entry in the array.

If the subject array is longer than the expectation array,
the extra entries are not tested.

You can also skip over entries by putting in `undefined`.
You can also skip over entries by putting in `anything`.

```ts
import { createSatisfier } from 'satisfier'

// all true
createSatisfier([1]).test([1, 2, 3])
createSatisfier([undefined, 1]).test(['...anything...', 1])
createSatisfier([e => e === undefined, 1]).test([undefined, 1])
createSatisfier([anything, 1]).test(['...anything...', 1])
createSatisfier([e => e === anything, 1]).test([anything, 1])
```

### using predicate expectation
Expand Down Expand Up @@ -160,7 +158,7 @@ results[0].expected.tersify()
tersify(results[0])
```

Examples of predicate: `And`, `AtLeastOnce`, `every`, `has`, `isInInterval`, `isInRange`, `isTypeOf`, `none`, `Or`, `some`
Examples of predicate: `every`, `has`, `isInInterval`, `isInRange`, `isTypeOf`, `none`, `some`, `startsWith`

## Contribute

Expand Down
22 changes: 13 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,23 @@
"typings": "lib/index.d.ts",
"scripts": {
"build": "tsc -p tsconfig.es5.json && tsc -p tsconfig.esnext.json",
"clean": "rimraf lib",
"dc": "npm run dependency-check",
"clean": "rimraf lib libm",
"dc": "yarn dependency-check",
"dependency-check": "dependency-check . --unused --no-dev && dependency-check . --missing --no-dev",
"lint": "tslint -p tsconfig.json",
"test": "jest --reporters=default",
"verify": "npm run lint && npm run build && npm run dependency-check && jest --coverage",
"watch": "jest --watch"
},
"devDependencies": {
"@unional/devpkg-node": "^1.2.4",
"assertron": "^6.1.0"
"verify": "yarn lint && yarn build && yarn dependency-check && jest --coverage --reporters=default",
"watch": "jest --watch",
"watch:type": "tsc --watch"
},
"dependencies": {
"tersify": "^1.2.6"
"tersify": "^2.0.2"
},
"devDependencies": {
"@unional/devpkg-node": "^1.2.5",
"assertron": "^6.1.0",
"codecov": "^3.2.0",
"jest-junit": "^6.3.0",
"type-plus": "^1.15.1"
}
}
16 changes: 0 additions & 16 deletions src/And.spec.ts

This file was deleted.

26 changes: 0 additions & 26 deletions src/And.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/ArrayEntryExpectation.ts

This file was deleted.

29 changes: 0 additions & 29 deletions src/AtLeastOnce.spec.ts

This file was deleted.

24 changes: 0 additions & 24 deletions src/AtLeastOnce.ts

This file was deleted.

18 changes: 0 additions & 18 deletions src/Or.spec.ts

This file was deleted.

25 changes: 0 additions & 25 deletions src/Or.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/anything.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const anything = Symbol('anything')
Loading

0 comments on commit 32ffe11

Please sign in to comment.