Détail du package

ember-cli-blueprint-test-helpers

ember-cli21.1kMIT0.19.2

Blueprint test helpers for ember-cli. Mocks ember-cli for generate and destroy commands.

ember-addon, ember

readme

ember-cli-blueprint-test-helpers

npm version Build Status Build status

test helpers for ember-cli blueprints

Installation

ember install ember-cli-blueprint-test-helpers

It should be noted that ember-cli-blueprint-test-helpers currently only works for testing blueprints inside addon projects.

Usage

Running Tests

The blueprint tests can be run by:

node_modules/.bin/mocha node-tests --recursive

For convenience you should add the following to your package.json:

"scripts": {
  "nodetest": "mocha node-tests --recursive"
}

to be able to use npm run nodetest to run the tests.

Generating Tests

Generate a blueprint test scaffold using the blueprint-test generator:

ember generate blueprint-test my-blueprint

which will generate a test file at node-tests/blueprints/my-blueprint-test.js.

Example Usage

describe('Acceptance: ember generate and destroy my-blueprint', function() {
  // create and destroy temporary working directories
  setupTestHooks(this);

  it('my-blueprint foo', function() {
    const args = ['my-blueprint', 'foo'];

    // create a new Ember.js app in the working directory
    return emberNew()

      // then generate and destroy the `my-blueprint` blueprint called `foo`
      .then(() => emberGenerateDestroy(args, (file) => {

        // and run some assertions in between
        expect(file('path/to/file.js'))
          .to.contain('file contents to match')
          .to.contain('more file contents\n');
      }));

     // magically done for you: assert that the generated files are destroyed again
  });
});

or more explicitly:

describe('Acceptance: ember generate and destroy my-blueprint', function() {
  // create and destroy temporary working directories
  setupTestHooks(this);

  it('my-blueprint foo', function() {
    const args = ['my-blueprint', 'foo'];

    // create a new Ember.js app in the working directory
    return emberNew()

      // then generate the `my-blueprint` blueprint called `foo`
      .then(() => emberGenerate(args))

      // then assert that the files were generated correctly
      .then(() => expect(file('path/to/file.js'))
        .to.contain('file contents to match')
        .to.contain('more file contents\n'))

      // then destroy the `my-blueprint` blueprint called `foo`
      .then(() => emberDestroy(args))

      // then assert that the files were destroyed correctly
      .then(() => expect(file('path/to/file.js')).to.not.exist);
  });
});

if your blueprints support the new MU file structure, you can test them using this option: { ìsModuleUnification: true }

describe('Acceptance: ember generate and destroy my-blueprint', function() {
  // create and destroy temporary working directories
  setupTestHooks(this);

  it('my-blueprint foo', function() {
    const args = ['my-blueprint', 'foo'];

    // create a new Ember.js app in the working directory
    // this app will have MU file structure, namely a `src` directory
    return emberNew({ isModuleUnification: true })

      // then generate the `my-blueprint` blueprint called `foo`
      .then(() => emberGenerate(args, { isModuleUnification: true }))

      // then assert that the files were generated correctly
      .then(() => expect(file('path/to/file.js'))
        .to.contain('file contents to match')
        .to.contain('more file contents\n'))

      // then destroy the `my-blueprint` blueprint called `foo`
      .then(() => emberDestroy(args, { isModuleUnification: true }))

      // then assert that the files were destroyed correctly
      .then(() => expect(file('path/to/file.js')).to.not.exist);
  });
});

API Reference

This project exports two major API endpoints for you to use:

  • require('ember-cli-blueprint-test-helpers/chai')

    This endpoint exports the Chai assertion library including the chai-as-promised and chai-files plugins

  • require('ember-cli-blueprint-test-helpers/helpers')

    This endpoint exports the functions mentioned in the following API reference


setupTestHooks(scope, options)

Prepare the test context for the blueprint tests.

Parameters:

  • {Object} scope the test context (i.e. this)
  • {Object} [options] optional parameters
  • {Number} [options.timeout=20000] the test timeout in milliseconds
  • {Object} [options.tmpenv] object containing info about the temporary directory for the test.
  • {String} [options.cliPath='ember-cli'] path to the ember-cli dependency
  • {Boolean} [options.disabledTasks=['addon-install', 'bower-install', 'npm-install']] override the mocked installs Defaults to lib/helpers/tmp-env.js

Returns: {Promise}


emberNew(options)

Create a new Ember.js app or addon in the current working directory.

Parameters:

  • {Object} [options] optional parameters
  • {String} [options.target='app'] the type of project to create (app, addon or in-repo-addon)
  • {Boolean} [options.isModuleUnification=true] a toggle to use MU file structure

Returns: {Promise}


emberGenerate(args, options)

Run a blueprint generator.

Parameters:

  • {Array.<String>} args arguments to pass to ember generate (e.g. ['my-blueprint', 'foo'])
  • {Object} [options] optional parameters
  • {Boolean} [options.isModuleUnification=true] a toggle to use MU file structure

Returns: {Promise}


emberDestroy(args, options)

Run a blueprint destructor.

Parameters:

  • {Array.<String>} args arguments to pass to ember destroy (e.g. ['my-blueprint', 'foo'])
  • {Object} [options] optional parameters
  • {Boolean} [options.isModuleUnification=true] a toggle to use MU file structure

Returns: {Promise}


emberGenerateDestroy(args, assertionCallback, options)

Run a blueprint generator and the corresponding blueprint destructor while checking assertions in between.

Parameters:

  • {Array.<String>} args arguments to pass to ember generate (e.g. ['my-blueprint', 'foo'])
  • {Function} assertionCallback the callback function in which the assertions should happen
  • {Object} [options] optional parameters
  • {Boolean} [options.isModuleUnification=true] a toggle to use MU file structure

Returns: {Promise}


modifyPackages(packages)

Modify the dependencies in the package.json file of the test project.

Parameters:

  • {Array.<Object>} packages the list of packages that should be added, changed or removed

setupPodConfig(options)

Setup usePods in .ember-cli and/or podModulePrefix in environment.js.

Parameters:

  • {Object} [options] optional parameters
  • {Boolean} [options.usePods] add usePods in .ember-cli
  • {Boolean} [options.podModulePrefix] set npodModulePrefix to app/pods in config/environment.js

Used by

License

This project is licensed under the MIT License.

changelog

Change Log

v0.19.2 (2018-12-18)

:bug: Bug Fix

:house: Internal

Committers: 2

v0.19.1 (2018-09-22)

:rocket: Enhancement

Committers: 1

v0.19.0 (2018-09-22)

:boom: Breaking Change

:rocket: Enhancement

:memo: Documentation

:house: Internal

Committers: 2

v0.18.3 (2017-10-16)

:rocket: Enhancement

Committers: 1

v0.18.2 (2017-10-14)

:house: Internal

Committers: 2

v0.18.1 (2017-10-13)

:bug: Bug Fix

:house: Internal

Committers: 1

v0.18.0 (2017-10-03)

Full Changelog

Implemented enhancements:

  • CI: Use "auto-dist-tag" for deployment #110 (Turbo87)

Closed issues:

  • emberNew inside scoped npm package #119
  • Remove tmp-sync from dependencies #105

Merged pull requests:

v0.17.2 (2017-04-06)

Full Changelog

Merged pull requests:

v0.17.1 (2017-03-23)

Full Changelog

Closed issues:

  • An in-range update of rsvp is breaking the build 🚨 #102
  • An in-range update of fs-extra is breaking the build 🚨 #101
  • An in-range update of ember-cli is breaking the build 🚨 #100
  • update changelog #95

Merged pull requests:

v0.17.0 (2017-02-27)

Full Changelog

Merged pull requests:

v0.16.0 (2017-02-24)

Full Changelog

Merged pull requests:

v0.15.0 (2017-02-22)

Full Changelog

Merged pull requests:

v0.14.0 (2016-11-23)

Full Changelog

v0.13.2 (2016-11-23)

Full Changelog

v0.13.1 (2016-11-22)

Full Changelog

Closed issues:

  • Remove "walk-sync" dependency #72

Merged pull requests:

v0.13.0 (2016-06-15)

Full Changelog

Implemented enhancements:

Fixed bugs:

Closed issues:

  • AppVeyor build broken #62

Merged pull requests:

v0.12.1 (2016-06-07)

Full Changelog

Fixed bugs:

v0.12.0 (2016-05-26)

Full Changelog

Implemented enhancements:

  • Add babel option for default blueprint #55 (trabus)

Closed issues:

  • Allow opting out of the destroy phase for emberGenerateDestroy. #54

Merged pull requests:

v0.11.0 (2016-04-06)

Full Changelog

Implemented enhancements:

Closed issues:

  • Asserting contents of app/router.js #38

Merged pull requests:

  • Acceptance test for emberGenerateDestroy #52 (trabus)
  • Use "mocha-eslint" for linting #51 (Turbo87)
  • Replace test runner with simple "mocha" call #50 (Turbo87)
  • README: Add list of library users #48 (Turbo87)

v0.10.2 (2016-03-30)

Full Changelog

Fixed bugs:

  • blueprint-helper: Explicitly use "chai-as-promised" #47 (Turbo87)
  • Rename contents to contains in example assertion #46 (kimroen)
  • Fix require() call #44 (Turbo87)

v0.10.1 (2016-03-28)

Full Changelog

Closed issues:

  • ember-cli-shims error #33

v0.10.0 (2016-03-24)

Full Changelog

Implemented enhancements:

  • blueprint-helpers: Reuse assertFileToNotExist() from internal helpers #41 (Turbo87)
  • Improve assertion message in assertFileNotExists() #37 (Turbo87)
  • Remove EOLNEWLINE condition #36 (Turbo87)

Fixed bugs:

  • assertThrows no longer functional #34
  • Fixes #34 fix assertThrows by using chai-as-promised rejectedWith #35 (trabus)

Closed issues:

  • Move blueprint-test to node-tests folder #4

Merged pull requests:

  • README: Add AppVeyor badge #43 (Turbo87)
  • Add glob to package.json #42 (jeradg)
  • Added rsvp as dep for nodetest-runner to replace ember-cli/lib/ext/promise #40 (trabus)
  • Add AppVeyor manifest #39 (Turbo87)

v0.9.0 (2016-02-25)

Full Changelog

Implemented enhancements:

Fixed bugs:

  • README: Fix broken "scripts" instruction #26 (Turbo87)
  • blueprints/blueprint-test: Remove EOL import #24 (Turbo87)
  • Fixes #19 use expect().to.be.true in assertions #20 (trabus)

Closed issues:

  • Remove "console.log" statements #30
  • Add "testFramework" option #27
  • expect(...) is not complete #19
  • Document skipInit option #13

Merged pull requests:

v0.8.0 (2016-02-12)

Full Changelog

Closed issues:

  • .npmignore in blueprint replaces projects .npmignore #3
  • Random Issues #1

Merged pull requests:

  • Internal test helper bump #18 (trabus)
  • Added documentation and cleaned up fixture packages #17 (trabus)
  • Added mocha as dev-dep and to default blueprint index #16 (trabus)
  • Blueprint fixes #15 (trabus)
  • Bump version of dependency in blueprint #14 (pangratz)

v0.7.0 (2016-01-19)

Full Changelog

Merged pull requests:

  • Remove double node-tests prefix. #10 (rwjblue)
  • Remove extra references to nodetest.js. #9 (rwjblue)
  • move blueprint-test to blueprint root folder #8 (trabus)
  • Remove this library from its own blueprint. #7 (rwjblue)

v0.6.0 (2015-12-16)

Full Changelog

Closed issues:

  • More random issues #2

Merged pull requests:

  • Fixes #4 move tests to node-tests folder #6 (trabus)

v0.5.0 (2015-11-26)

Full Changelog

v0.4.0 (2015-11-26)

Full Changelog

v0.3.0 (2015-10-14)

Full Changelog

v0.2.0 (2015-10-09)

Full Changelog

v0.1.0 (2015-10-09)

* This Change Log was automatically generated by github_changelog_generator