1.0.0 • Published 1 year ago

test-as-package v1.0.0

Weekly downloads
-
License
(MIT or CC0 1.0)
Repository
github
Last release
1 year ago

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 'chai';
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.strictEqual(cliOutputs.exitCode, 0);
    });
});
1.0.0

1 year ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago