test-as-package
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

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);
    });
});

Package Sidebar

Install

npm i test-as-package

Weekly Downloads

10

Version

2.0.1

License

(MIT or CC0 1.0)

Unpacked Size

24.8 kB

Total Files

26

Last publish

Collaborators

  • electrovir