# NAME

bb-test - Command line tool for source code analysis (lint), and unit testing

# SYNOPSIS

```bash
bb-test [--help] [-v|--version]
bb-test lint [--help] [-f|--format <format>] [-o|--output <file>]
    [-c|--eslint-config <config file>] [-x --exclude <node glob>] [src]
bb-test unit [--help] [--prebuilt <paths>] [--load-prebuilt <names>]
    [-x --exclude <node glob>] [--exclude-defaults] [-b|--build-plugins <file|node_modules>]
    [-t|--test-plugins <plugin-list>] [--karma-plugins <plugin-list>] [--disable-karma-plugins]
    [-f|--format <format>] [-B|--browsers <browsers>] [--coverage <reporters>]
    [-w|--watch] [sources...]
```

# OPTIONS

| Option | Description |
| ------ | ----------- |
| -v, --version | output the version number |
| --help | Output usage information |

# COMMANDS

## NAME

bb-test lint - Run eslint and report javascript lint errors

## SYNOPSIS

```bash
bb-test lint [--help] [-f|--format <format>] [-o|--output <file>]
    [-c|--eslint-config <config file>] [-x --exclude <node glob>] [src]
```

## DESCRIPTION

By default bb-test lint uses the @backbase/eslint-config-backbase package for
the linting rules. These rules are strongly based on the airbnb es6 rules.

If you specify a custom eslint config file, it's recommended to extend from
@backbase/eslint-config-backbase rules.

## OPTIONS

| Option | Description |
| ------ | ----------- |
| -f, --format &lt;format&gt; | Use a specific output format |
| -o, --output &lt;file&gt; | Specify output file to write report to |
| -c, --eslint-config &lt;config file&gt; | Custom eslint configuration file |
| -x --exclude &lt;node glob&gt; | Comma separated paths/globs to ignore. Make sure to wrap globs in single quotes to avoid shell expansion |
| --help | Output usage information |

## EXAMPLES

Lint all javascript files in the current directory:

```bash
  $ bb-test lint
```

Lint all javascript files in a sub directory (single quotes to avoid bash expansion):

```bash
  $ bb-test lint 'src/**/*.js'
```

Lint using a custom config file:

```bash
  $ bb-test lint --eslint-config ./eslint.conf.json
```

Exclude custom glob patterns from linting:

```bash
  $ bb-test lint --exclude 'prebuilt/*,assets/*'
```

## NAME

bb-test unit - Run unit tests for CXP items

## SYNOPSIS

```bash
bb-test unit [--help] [--prebuilt <paths>] [--load-prebuilt <names>]
    [-x --exclude <node glob>] [--exclude-defaults] [-b|--build-plugins <file|node_modules>]
    [-t|--test-plugins <plugin-list>] [--karma-plugins <plugin-list>] [--disable-karma-plugins]
    [-f|--format <format>] [-B|--browsers <browsers>] [--coverage <reporters>]
    [-w|--watch] [sources...]
```

## DESCRIPTION

By default the tests are run in chrome via karma (with webpack) using jasmine.

bb-test unit works in a similar way to bb-package. It will look for all the
sources that need to be tested in the current directory (by default). It will
also load any prebuilt dependencies in node_modules or target/backbase (by default).

## OPTIONS

| Option | Description |
| ------ | ----------- |
| --prebuilt &lt;paths&gt; | Comma separated paths to prebuilt items (items that don't require a webpack build). These will be merged with the defaults. |
| --load-prebuilt &lt;names&gt; | Comma separated list of prebuilt items to load in the browser. This is useful if your tests require a global thatis provided by a prebuilt item. |
| -x --exclude &lt;node glob&gt; | Comma separated paths/globs to ignore. Make sure to wrap globs in single quotes to avoid shell expansion. The exclude glob is evaluated relative to each source directory provided. This exclude is applied the same way as bb-package. It shouldn't be used to exclude certain files from testing, but for excluding entire Backbase itemsfrom being found for testing. |
| --exclude-defaults | Exclude prebuilt defaults |
| -b, --build-plugins &lt;file&#124;node_modules&gt; | Comma separated path/node modules to use for the build process |
| -t, --test-plugins &lt;plugin-list&gt; | Comma separated path/node modules to use for unit testing |
| --karma-plugins &lt;plugin-list&gt; | Comma separated names of karma plugins to use for unit testing. If not set, all sibling plugins starting with karma-* will be loaded |
| --disable-karma-plugins | Disable auto-loading of karma-* plugins |
| -f, --format &lt;format&gt; | Comma separated list of output formats. Possible values (without plugins): dots,progress |
| -B, --browsers &lt;browsers&gt; | Browser to launch, by default karma is using a Chrome launcher. In order to launch a browser you must have the karma launcher installed (ignore peer dependency warnings) |
| --coverage [reporters] | Comma separated list of coverage reporters. Possible values: text-summary,html,lcov. Reports will be created in "reports" dir. |
| -w, --watch | Watch files and re-run tests on changes |
| --help | Output usage information |

## KARMA PLUGINS

All karma plugins are automatically loaded. Karma plugins are npm packages that
are installed as peers to bb-test, and begin with 'karma-'.

## BROWSERS

Chrome is the default launcher used, but there is support for any karma launcher.

Because karma plugins are loaded automatically, just install the correct plugin
for the browser you want to launch. For example, you can install the Firefox
Launcher and run bb-test unit with --browsers=Firefox. Make sure to consult
the launchers documentation for the correct name of the browser.

It can also accept a comma separated list of browsers.

## LOADING PREBUILT FILES

Karma has an option for loading addition files in the browser. bb-test has a similar
option where you can load prebuilt files in the page (even if they're not directly
imported into one of the items you're testing).

For example, if you have a config-bb-module-loader in your project, which relies
on the vendor-bb-systemjs item to already be loaded on the page, you can tell bb-test
to always include vendor-bb-systemjs on the page.

## TEST PLUGINS

bb-test supports it's own set of test plugins. A bb-test plugin is an npm
package that begins with @bb-cli/bb-test-plugin-. To load a plugin just provide
that last part of the name to bb-test unit.

For example, there is an angular-mocks plugin that enables you to use ngmock
in your tests, and can be loaded via --test-plugins=ngmock
https://www.npmjs.com/package/@bb-cli/bb-test-plugin-ngmock

# EXAMPLES

Install Firefox launcher and run with firefox:

```bash
  $ npm install -g karma-firefox-launcher
  $ bb-test unit --browsers Firefox
```

Or run with Firefox AND Chrome:

```bash
  $ bb-test unit --browsers Firefox,Chrome
```

Install and run with test plugin @bb-cli/bb-test-plugin-ngmock
(which adds support for angular-mocks):

```bash
  $ npm install -g @bb-cli/bb-test-plugin-ngmock
  $ bb-test unit --test-plugins ngmock
```

Run tests with support for compiling sass files:

```bash
  $ npm install -g @bb-cli/bb-build-plugin-sass
  $ bb-test unit --build-plugins sass
```

Create html & lcov coverage in reports/ dir, and print coverage to stdout:

```bash
  $ bb-test unit --coverage text-summary,html,lcov
```

Combining aliases for test-plugins, build-plugins, browsers, and coverage as
you might do on a jenkins machine:

```bash
  $ bb-test unit -t ngmock -b sass -B PhantomJS --coverage lcov,text-summary
```

Instead of the current directory, look for CXP source items in src/ with
additional prebuilt dependencies in prebuilt/. Note: this will still search
for dependencies in node_modules and target/backbase:

```bash
  $ bb-test unit src/ --prebuilt prebuilt/
```

Load vendor-bb-systemjs into the browser so the System global is defined:

```bash
  $ bb-test unit --load-prebuilt vendor-bb-systemjs
```

## ENVIRONMENT VARIABLES

bb-test will generate an entry file for the tests. By default a tmp file will be created. Use this to write to a specific file for the test entry. This can be useful for debugging issues with bb-test.
```bash
BB_TEST_UNIT_CREATE_ENTRY=entry.js
```

# ENVIRONMENT VARIABLES

Set the amount of log output
```bash
LOG_LEVEL=silly|verbose|info|warn|error
```

Set whether or not to use colors in output
```bash
COLOR=false|true
```