4.0.0 • Published 3 months ago

cli-testlab v4.0.0

Weekly downloads
1,711
License
-
Repository
github
Last release
3 months ago

cli-testlab

NPM Version

Node.js test framework for CLI utilities

Example usage

Basic usage

const { execCommand } = require('cli-testlab')

describe('CLI app under test', () => {
  it('expect error', async () => {
    return execCommand(`node appUnderTest.js error Kaboom`, {
      expectedErrorMessage: 'Kaboom'
    })
  })

  it('expect output X', async () => {
    return execCommand(`node appUnderTest.js message OK`, {
      expectedOutput: 'OK'
    })
  })

  it('do not expect output Y', async () => {
    return execCommand(`node appUnderTest.js message OK`, {
      notExpectedOutput: 'error'
    })
  })
})

File cleanup usage

const path = require('path');
const { execCommand, FileTestHelper } = require('cli-testlab');
const { expect } = require('chai');

describe('Application under test', () => {
  describe('Tests that require cleanup', () => {
    /**
     * @type FileTestHelper
     */
    let fileHelper;
    beforeEach(() => {
     fileHelper = new FileTestHelper(
         path.resolve(__dirname, '../directoryForNewFiles')
       );
    });

    afterEach(() => {
      fileHelper.cleanup();
    });

    it('Test that requires cleanup', async () => {
      fileHelper.registerGlobForCleanup(
        'test/directoryForNewFiles/*_somename.js'
      );

      await execCommand(
        `node appThatCreatesFiles.js`,
        {
          expectedOutput: 'File created succesfully',
        }
      );

      const fileCount = fileHelper.fileGlobExists(
        'test/directoryForNewFiles/*_somename.js'
      );
      expect(fileCount).to.equal(1);
    });
4.0.0

3 months ago

3.0.0

11 months ago

2.2.0

3 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.11.0

4 years ago

1.10.0

4 years ago

1.9.0

4 years ago

1.8.0

5 years ago

1.7.0

5 years ago

1.6.0

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago