Skip to content

Commit b433d52

Browse files
authored
feat(command): add integrate command (#47)
Added a new `integrate` command which supports running integration tests from a separate `integration-tests/` "project" within the library. Docs for the new `integrate` command were added as well. I also added integration tests for `@benmvp/cli` for the build command to verify that build actually does what it is supposed to. So I was able to Fix #32 and also dogfood the `integrate` command. As part of building out the `integrate` functionality, I needed to add the result of `npm pack` as a dev dependency to the project, which kept failing in Yarn. `yarn add --dev /path/to/tarball.tgz` would return before it was _really_ done and a result the follow on commands with fail. As a result I switched the project over from Yarn to npm. All docks were updated accordingly. BREAKING CHANGE: The `unit` test mode was renamed to `spec` in order to make more sense with integration tests. The way the integration tests are run in the project is by running `npx benmvp test`. The parameters passed to `benmvp integrate` are ultimately passed as the parameters to `npx benmvp test`. Have a mode called `unit` when running integration tests seemed confusion. Really it's just running Jest spec tests, so the rename was to better reflect that. In order to just run **unit** tests, you run `benmvp test -m spec` in order to just run **integration** tests you run `benmvp integration -m spec`. I also set `maxWarnings` for eslint to `0` so that all warnings are also errors as well.
1 parent 3212dee commit b433d52

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+7466
-5614
lines changed

.travis.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ node_js:
44
- '12'
55
- '10'
66
- '8'
7-
cache: yarn
7+
cache: npm
88

9-
script: yarn test
9+
script: npm run test && npm run integrate
1010

1111
jobs:
1212
include:
13-
- stage: NPM Release
13+
- stage: deploy
14+
name: "NPM Release"
1415
node_js: '10'
15-
script: yarn build
16+
script: npm run build
1617

1718
# Using semantic-release, deploy a new version of the library
1819
deploy:

CONTRIBUTING.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ Thank you for your interest in contributing to my CLI!
1313

1414
## Setup
1515

16-
1. This project uses [yarn](https://yarnpkg.com/en/) as a package management system. If you don't have it installed, you can follow the [installation instructions](https://yarnpkg.com/lang/en/docs/install/)
1716
1. [For the repository](https://help.github.com/articles/fork-a-repo/)
1817
1. Clone your new forked repository to your local computer
1918
1. Set the `benmvp` repository as your branch's upstream branch: `git remote add upstream https://github.com/benmvp/benmvp-cli.git`
2019
1. Navigate to the root directory of your newly cloned repository: `cd /path/to/benmvp-cli`
21-
1. `yarn install` to install local dependencies
20+
1. `npm install` to install local dependencies
2221

2322
## Using branches to submit changes
2423

@@ -58,8 +57,8 @@ Please try to conform to the coding style of the code base.
5857

5958
## Steps to submit:
6059

61-
1. Please ensure that your changes are fully covered by one or more unit test(s).
60+
1. Please ensure that your changes are fully covered by one or more unit tests.
6261
1. Check to make sure that your changes are documented properly (inline comments for interesting lines, READMEs, etc.)
63-
1. Run `yarn test` to ensure that all tests pass, the linter is satisfied and your changes are typescript compliant.
62+
1. Run `npm test` to ensure that all tests pass, the linter is satisfied and your changes are typescript compliant.
6463
1. PR titles must be prefixed by the type of changes the PR contains followed by the scope of what the PR touches. We are following the [angular commit guidelines](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines). Please use one of `feat, fix, docs, style, refactor, perf, test, chore` as the prefix. The " is the the direct product your changes affect. Example: `chore(build): Add encrypted ssh key for semantic-release` because its a chore and it touches the build. For multiple scope items, you can comma separate 2 or 3 but if there are more than that please use a `*` instead.
6564
1. Please use a [closing issue keyword](https://help.github.com/articles/closing-issues-using-keywords/) to indicate the issue that your fix addresses in the description section of the pull request template. Example: `fixes #32` to close issue #32

README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,36 +54,44 @@ Read the API docs for more on [`benmvp create`](docs/cli/create.md).
5454

5555
## Quick Usage
5656

57-
### Testing
57+
### Unit Testing
5858

5959
```sh
60-
yarn test
60+
npm test
6161
```
6262

63-
In your continuous integration (CI) environment, run `yarn test` (or `npm test`) to do a one-time pass of Typescript typings, ESLint linting, and Jest tests. This can also be run locally (i.e. for commit hooks).
63+
In your continuous integration (CI) environment, run `npm test` (or `yarn test`) to do a one-time pass of Typescript typings, ESLint linting, and Jest unit tests. This can also be run locally (i.e. for commit hooks).
6464

6565
Read the API docs for more on [`benmvp test`](docs/cli/test.md).
6666

6767
### Developing
6868

6969
```sh
70-
yarn start
70+
npm start
7171
```
7272

73-
When developing, run `yarn start` (or `npm start`) which will validate Typescript typings, ESLint linting, and Jest tests as you develop and change code.
73+
When developing, run `npm start` (or `yarn start`) which will validate Typescript typings, ESLint linting, and Jest unit tests as you develop and change code.
7474

7575
Read the API docs for more on [`benmvp start`](docs/cli/start.md).
7676

7777
### Building
7878

7979
```sh
80-
yarn build
80+
npm run build
8181
```
8282

83-
In your continuous integration (CI) environment, run `yarn build` (or `npm build`) to generated transpiled versions of your code in ESM (ECMAScript module) and CJS (CommonJS).
83+
In your continuous integration (CI) environment, run `npm run build` (or `yarn build`) to generate transpiled versions of your code in ESM (ECMAScript module) and CJS (CommonJS), as well as TypeScript definition files.
8484

8585
Read the API docs for more on [`benmvp build`](docs/cli/build.md).
8686

87+
### Integration Testing
88+
89+
```sh
90+
npm run integrate
91+
```
92+
93+
In your continuous integration (CI) environment, run `npm run integrate` (or `yarn integrate`) to run additional integration tests for the library. The integration "project" will also be typed and linted. This can also be run locally (i.e. for commit hooks but is not recommended).
94+
8795
## Docs
8896

8997
`@benmvp/cli` has two interfaces: a CLI and a Node API. View the [full docs](docs/).

bin/benmvp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
const {code, message, error} = await run(args);
88

99
if (code) {
10-
console.error(error);
10+
// console.error(error);
1111
console.error(message);
1212
}
1313

docs/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ The CLI exposes the following commands:
1010
- [`benmvp test`](cli/test.md) - Runs a one-time pass of typing, linting, unit tests & code coverage for the library
1111
- [`benmvp start`](cli/start.md) - Runs the lib's tests in on-going watch mode during active development
1212
- [`benmvp build`](cli/build.md) - Builds the library into the desired module formats at the specified location
13+
- [`benmvp integrate`](integrate.md) - Runs additional integration tests for the library
1314

1415
## Node API docs
1516

@@ -19,4 +20,5 @@ The Node API exposes the following functions:
1920
- [`test()`](api/test.md) - Runs a one-time pass of the specified modes of tests
2021
- [`start()`](api/start.md) - Runs the specified modes of tests in on-going watch mode during active development
2122
- [`build()`](api/build.md) - Builds the library into the desired module formats at the specified location
23+
- [`integrate()`](integrate.md) - Runs additional integration tests for the library
2224
- [`run()`](api/run.md) - Parses the specified array of CLI arguments to runs the desired command

docs/api/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ The Node API exposes the following functions:
66
- [`test()`](test.md) - Runs a one-time pass of the specified modes of tests
77
- [`start()`](start.md) - Runs the specified modes of tests in on-going watch mode during active development
88
- [`build()`](build.md) - Builds the library into the desired module formats at the specified location
9+
- [`integrate()`](integrate.md) - Runs additional integration tests for the library
910
- [`run()`](run.md) - Parses the specified array of CLI arguments to runs the desired command
1011

docs/api/build.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ build({
4949
`build()` has the following [TypeScript](https://www.typescriptlang.org/) signature:
5050

5151
```js
52-
([options]: Options): Promise<Result>
52+
(options?: Options): Promise<Result>
5353
```
5454

5555
## Options
@@ -76,7 +76,7 @@ Optional. Defaults to `./lib`.
7676

7777
### `watch`
7878

79-
A flag indicating whether or not to continuously generate the built module formats whenever source files change. This is most useful if you've linked your library into a host application (with [`yarn link`](https://yarnpkg.com/lang/en/docs/cli/link/) or [`npm link`](https://docs.npmjs.com/cli/link)).
79+
A flag indicating whether or not to continuously generate the built module formats whenever source files change. This is most useful if you've linked your library into a host application (with [`npm link`](https://docs.npmjs.com/cli/link) or [`yarn link`](https://yarnpkg.com/lang/en/docs/cli/link/)).
8080

8181
Optional. Defaults to `false`.
8282

docs/api/create.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# `create()` Documentation
22

3+
> NOTE: `create()` is still under development
4+
5+
36
Creates a new library with the specified name set up with infrastructure using `@benmvp/cli`, returning a `Promise` indicating whether the creation succeeded or failed.
47

5-
- Add `"test"`, `"start"`, and `"build"` scripts in the `package.json` to call [`benmvp test`](test.md), [`benmvp start`](start.md), and [`benmvp build`](build), respectively
6-
- After the `package.json` is created (or updated), it will install `@benmvp/cli` as a dev dependency, using [Yarn](https://yarnpkg.com/) if available. If Yarn is unavailable, it will fallback to [NPM](https://docs.npmjs.com/)
8+
- Add `"test"`, `"start"`, `"build"` and `"integrate"` scripts in the `package.json` to call [`benmvp test`](test.md), [`benmvp start`](start.md), [`benmvp build`](build.md), and [`benmvp integrate`](integrate.md), respectively
9+
- After the `package.json` is created (or updated), it will install `@benmvp/cli` as a dev dependency, using [Yarn](https://yarnpkg.com/) if available. If Yarn is unavailable, it will fallback to [npm](https://docs.npmjs.com/)
710
- Will add (or overwrite) a `.travis.yml` file w/ [build stages](https://docs.travis-ci.com/user/build-stages/) for testing and deploying the library
811

912
Looking for CLI docs? View companion [`benmvp create` documentation](../cli/create.md).
@@ -45,7 +48,7 @@ Add custom setup to an existing library:
4548
import {create} from '@benmvp/cli'
4649

4750
create({
48-
modes: ['type', 'unit'],
51+
modes: ['type', 'spec'],
4952
out: './built',
5053
formats: ['esm', 'cjs'],
5154
})
@@ -56,7 +59,7 @@ create({
5659
`create()` has the following [TypeScript](https://www.typescriptlang.org/) signature:
5760

5861
```js
59-
([options]: Options): Promise<Result>
62+
(options?: Options): Promise<Result>
6063
```
6164

6265
## Options
@@ -103,11 +106,11 @@ An `Array` of the types or modes of tests to run. Available modes:
103106

104107
- `'type'` - Runs Typescript type-checking
105108
- `'lint'` - Runs ESLint
106-
- `'unit'` - Runs Jest-based unit tests
109+
- `'spec'` - Runs Jest-based tests
107110

108111
Optional. Defaults to all modes when unspecified.
109112

110-
This will initialize the `"start"` and `"test"` scripts in the `package.json` to pass the matching argument.
113+
This will initialize the `"start"`, `"test"` and `"integrate"` scripts in the `package.json` to pass the matching argument.
111114

112115

113116
## Return Value

docs/api/integrate.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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)!

docs/api/run.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ To run just unit tests:
2929
```js
3030
const {run} = require('@benmvp/cli');
3131

32-
run(['test', '--modes', 'unit'])
32+
run(['test', '--modes', 'spec'])
3333
```
3434

3535
## Type
3636

3737
`run()` has the following [TypeScript](https://www.typescriptlang.org/) signature:
3838

3939
```js
40-
([args]: Array<string>): Promise<Result>
40+
(args?: string[]): Promise<Result>
4141
```
4242

4343
## Arguments

0 commit comments

Comments
 (0)