|
| 1 | +# `integrate()` Documentation |
| 2 | + |
| 3 | +Runs additional integration tests for the library, returning a `Promise` indicating whether the test run succeeded or failed. |
| 4 | + |
| 5 | +> NOTE: `integrate()` assumes the integration tests live within the `integration-tests/src` folder of the current working directory where the script is being called. |
| 6 | +
|
| 7 | +The integration tests generally are run in your continuous integration (CI) environment to verify that your library when packaged can successfully be used by clients. The goal is dummy library/project in which you write tests that import and use the library like a normal client would. |
| 8 | + |
| 9 | +The integration test process is as follows: |
| 10 | + |
| 11 | +1. [`npm pack`](https://docs.npmjs.com/cli/pack.html) the library to create the _same_ `.tgz` tarball that would be published in the registry |
| 12 | +1. Copy the integration tests "project" at `integration-tests/` over to a temporary directory |
| 13 | +1. `npm install` the packed library (from Step 1) and any other dependencies specified in the `package.json` of the project |
| 14 | +1. Run `npx benmvp test` on the project to run the tests |
| 15 | + |
| 16 | +Looking for CLI docs? View companion [`benmvp integrate` documentation](../cli/integrate.md). |
| 17 | + |
| 18 | +## Examples |
| 19 | + |
| 20 | +To run all modes of integration tests on all files (default behavior): |
| 21 | + |
| 22 | +```js |
| 23 | +import {integrate} from '@benmvp/cli' |
| 24 | + |
| 25 | +integrate() |
| 26 | +``` |
| 27 | + |
| 28 | +To run just the integration tests themselves (excluding linting & typing) on all files: |
| 29 | + |
| 30 | +```js |
| 31 | +import {integrate} from '@benmvp/cli' |
| 32 | + |
| 33 | +integrate({ |
| 34 | + modes: ['spec'], |
| 35 | +}) |
| 36 | +``` |
| 37 | + |
| 38 | +To run just linting & typing on all files in the integration tests project: |
| 39 | + |
| 40 | +```js |
| 41 | +import {integrate} from '@benmvp/cli' |
| 42 | + |
| 43 | +integrate({ |
| 44 | + modes: ['lint', 'type'], |
| 45 | +}) |
| 46 | +``` |
| 47 | + |
| 48 | +To run all modes only on files within `utils/` directories of the integration tests project: |
| 49 | + |
| 50 | +```js |
| 51 | +import {integrate} from '@benmvp/cli' |
| 52 | + |
| 53 | +integrate({ |
| 54 | + pattern: 'utils/', |
| 55 | +}) |
| 56 | +``` |
| 57 | + |
| 58 | +To just run linting on files within `api/` directories of the integration tests project: |
| 59 | + |
| 60 | +```js |
| 61 | +import {integrate} from '@benmvp/cli' |
| 62 | + |
| 63 | +integrate({ |
| 64 | + modes: ['lint'], |
| 65 | + pattern: 'api/', |
| 66 | +}) |
| 67 | +``` |
| 68 | + |
| 69 | +## Signature |
| 70 | + |
| 71 | +`integrate()` has the following [TypeScript](https://www.typescriptlang.org/) signature: |
| 72 | + |
| 73 | +```js |
| 74 | +type Mode = 'spec' | 'type' | 'lint' |
| 75 | +namespace TestOptions { |
| 76 | + modes: Mode[]; |
| 77 | + pattern: string; |
| 78 | +} |
| 79 | + |
| 80 | +(options?: TestOptions): Promise<Result> |
| 81 | +``` |
| 82 | + |
| 83 | +## Options |
| 84 | + |
| 85 | +The optional `TestOptions` object supports the following properties: |
| 86 | + |
| 87 | +### `modes` |
| 88 | + |
| 89 | +An `Array` of the types or modes of tests to run. Available modes: |
| 90 | + |
| 91 | +- `'spec'` - Runs Jest-based tests (files ending in `.spec.ts` or in `__tests__` folder) |
| 92 | +- `'type'` - Runs Typescript type-checking (files ending in `.ts`) |
| 93 | +- `'lint'` - Runs ESLint (files ending in `.ts`) |
| 94 | + |
| 95 | +Optional. Defaults to all modes when unspecified. |
| 96 | + |
| 97 | +### `pattern` |
| 98 | + |
| 99 | +A regexp pattern string that is matched against all tests paths before executing the test. |
| 100 | + |
| 101 | +Optional. Defaults to `''` (signifying no filter) |
| 102 | + |
| 103 | +## Return Value |
| 104 | + |
| 105 | +`integrate()` returns a `Promise`. |
| 106 | + |
| 107 | +When `integrate()` finishes successfully, the resolved value will be an `object` with a `code` property set to `0`. |
| 108 | + |
| 109 | +If `integrate()` exits unsuccessfully, the resolved value will be an `object` with a non-zero `code` property, a user-friendly `message` property, and an `error` property pointing to the inner exception. |
| 110 | + |
| 111 | +--- |
| 112 | + |
| 113 | +## More help |
| 114 | + |
| 115 | +Looking for CLI docs? View companion [`benmvp integrate` documentation](../cli/integrate.md). |
| 116 | + |
| 117 | +Still unsure of how to use `@benmvp/cli`? [Ask for help](https://github.com/benmvp/benmvp-cli/issues)! |
0 commit comments