npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-cli-blueprint-test-helpers

v0.19.2

Published

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

Downloads

4,895

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

  • https://github.com/emberjs/ember.js
  • https://github.com/emberjs/data
  • https://github.com/ember-cli/ember-cli-legacy-blueprints
  • https://github.com/simplabs/ember-simple-auth
  • https://github.com/DockYard/ember-suave

License

This project is licensed under the MIT License.