Skip to content

Commit

Permalink
Snapshot test all the negated usage examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mmkal committed Oct 23, 2022
1 parent c4652da commit 40f7277
Show file tree
Hide file tree
Showing 4 changed files with 355 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ node_modules
dist
*ignoreme*
coverage

# ignore non-pnpm lockfiles
package-lock.json
yarn.lock
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ See below for lots more examples.
- [Jest & `eslint-plugin-jest`](#jest--eslint-plugin-jest)
- [Similar projects](#similar-projects)
- [Comparison](#comparison)
- [Contributing](#contributing)
<!-- codegen:end -->

## Installation and usage
Expand All @@ -54,7 +55,7 @@ The `expectTypeOf` method takes a single argument, or a generic parameter. Neith

### Features

<!-- codegen:start {preset: markdownFromTests, source: test/index.test.ts} -->
<!-- codegen:start {preset: markdownFromTests, source: test/usage.test.ts} -->
Check an object's type with `.toEqualTypeOf`:

```typescript
Expand Down Expand Up @@ -473,3 +474,13 @@ The key differences in this project are:
- assertions on types "matching" rather than exact type equality, for "is-a" relationships e.g. `expectTypeOf(square).toMatchTypeOf<Shape>()`
- built into existing tooling. No extra build step, cli tool, IDE extension, or lint plugin is needed. Just import the function and start writing tests. Failures will be at compile time - they'll appear in your IDE and when you run `tsc`.
- small implementation with no dependencies. <200 lines of code - [take a look!](./src/index.ts) (tsd, for comparison, is [2.6MB](https://bundlephobia.com/result?p=tsd@0.13.1) because it ships a patched version of typescript).

## Contributing

In most cases, it's worth checking existing issues or creating on to discuss a new feature or a bug fix before opening a pull request.

Once you're ready to make a pull request: clone the repo, and install pnpm if you don't have it already with `npm install --global pnpm`. Lockfiles for `npm` and `yarn` are gitignored.

If you're adding a feature, you should write a self-contained usage example in the form of a test, in [test/usage.test.ts](./test/usage.test.ts). This file is used to populate the bulk of this readme using [eslint-plugin-codegen](https://npmjs.com/package/eslint-plugin-codegen), and to generate an ["errors" test file](./test/errors.test.ts), which captures the error messages that are emitted for failing assertions by the typescript compiler. So, the test name should be written as a human-readable sentence explaining the usage example. Have a look at the existing tests for an idea of the style.

After adding the tests, run `npm run lint -- --fix` to update the readme, and `npm test -- --updateSnapshot` to update the errors test. The generated documentation and tests should be pushed to the same branch as the source code, and submitted as a pull request. CI will test that the docs and tests are up to date if you forget to run these commands.
Loading

0 comments on commit 40f7277

Please sign in to comment.