Ember CLI Blueprint Test Helpers

0.19.2 · active · verified Wed Apr 22

ember-cli-blueprint-test-helpers provides a dedicated suite of testing utilities for `ember-cli` blueprint authors. It enables comprehensive testing of blueprint generation and destruction logic by mocking the `ember-cli` environment, allowing developers to simulate `ember generate` and `ember destroy` commands within a controlled context. The current stable version is `0.19.2`, with releases occurring periodically to address bugs and introduce minor enhancements, rather than a fixed cadence. A key differentiator is its specialized focus on blueprint testing within Ember addon projects, providing helpers like `setupTestHooks`, `emberNew`, `emberGenerate`, `emberDestroy`, and `emberGenerateDestroy` to streamline the assertion process for generated and removed files, including support for Module Unification setups. This package is crucial for ensuring the correctness and stability of `ember-cli` blueprints.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up blueprint tests using Mocha and Chai, generate and destroy a hypothetical 'my-blueprint', and assert file existence and content. It also shows testing with Module Unification.

import { setupTestHooks, emberNew, emberGenerate, emberDestroy, file } from 'ember-cli-blueprint-test-helpers';
import { expect } from 'chai';

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

  it('my-blueprint foo generates and cleans up files', async function() {
    const args = ['my-blueprint', 'foo'];

    // Create a new Ember.js app in the working directory
    await emberNew();

    // Generate the `my-blueprint` blueprint with name `foo`
    await emberGenerate(args);

    // Assert that the files were generated correctly
    expect(file('app/components/foo.js')).to.exist;
    expect(file('app/components/foo.js'))
      .to.contain('import Component from '@glimmer/component';')
      .to.contain('export default class FooComponent extends Component {}');

    // Destroy the `my-blueprint` blueprint with name `foo`
    await emberDestroy(args);

    // Assert that the generated files were destroyed correctly
    expect(file('app/components/foo.js')).to.not.exist;
  });

  it('my-blueprint bar with Module Unification', async function() {
    const args = ['my-blueprint', 'bar'];

    // Create a new Ember.js app with Module Unification structure
    await emberNew({ isModuleUnification: true });

    // Generate and destroy the `my-blueprint` blueprint called `bar`
    await emberGenerateDestroy(args, (fileContents) => {
      // Assertions run between generate and destroy
      expect(fileContents('src/ui/components/bar/component.js')).to.exist;
      expect(fileContents('src/ui/components/bar/component.js'))
        .to.contain('// Module Unification component content');
    });
  });
});

view raw JSON →