test-as-package
v2.0.1
Published
Test a repository as an npm package applied to internal test repos.
Downloads
1,436
Maintainers
Readme
test-as-package
Test a repo, inside of the repo itself, as if it were already deployed as an npm package. Packs, installs, and runs the package's CLI script.
Installation
npm i -D test-as-package
This is meant for testing, so you probably want to install it as a dev dependency (hence the -D
flag).
Usage
Run CLI command first
Pass your test scripts to the test-as-package
cli command:
test-as-package mocha
It's probably best to include this in your npm test
script:
{
"scripts": {
"test": "test-as-package mocha"
}
}
Replace mocha
with whatever your test command is (such has jest
).
The test-as-package
CLI will handle packing up your package and installing it inside of NodeModules so it can be run as if it were installed as a package dependency. (This is done without affecting package.json
or package-lock.json
.
Use the runPackageCli
API
To actually test your package's CLi, use runPackageCli
inside of tests:
import {assert} from '@augment-vir/assert';
import {describe, it} from '@augment-vir/test';
import {runPackageCli} from 'test-as-package';
describe('my CLI', () => {
it('produces correct output', async () => {
const cliOutputs = await runPackageCli({
commandArgs: ['cliArg1'],
});
// assert that the command exited without any errors
assert.strictEquals(cliOutputs.exitCode, 0);
});
});