Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ember-cli-blueprint-test-helpers

Package Overview
Dependencies
Maintainers
3
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-cli-blueprint-test-helpers - npm Package Compare versions

Comparing version 0.10.2 to 0.11.0

chai.js

3

.eslintrc.js

@@ -13,2 +13,5 @@ module.exports = {

},
parserOptions: {
ecmaVersion: 6,
},
rules: {

@@ -15,0 +18,0 @@ 'indent': [2, 2, {

24

blueprints/blueprint-test/files/__root__/__name__-test.js
'use strict';
var setupTestHooks = require('ember-cli-blueprint-test-helpers/lib/helpers/setup');
var BlueprintHelpers = require('ember-cli-blueprint-test-helpers/lib/helpers/blueprint-helper');
var generateAndDestroy = BlueprintHelpers.generateAndDestroy;
var blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers');
var setupTestHooks = blueprintHelpers.setupTestHooks;
var emberNew = blueprintHelpers.emberNew;
var emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy;
var expect = require('ember-cli-blueprint-test-helpers/chai').expect;
describe('Acceptance: ember generate and destroy <%= blueprintName %>', function() {
setupTestHooks(this);
it('<%= blueprintName %> foo', function() {
var args = ['<%= blueprintName %>', 'foo'];
// pass any additional command line options in the arguments array
return generateAndDestroy(['<%= blueprintName %>', 'foo'], {
// define files to assert, and their contents
files: [
// { file: 'app/type/foo.js', contains: ['foo']}
]
});
return emberNew()
.then(() => emberGenerateDestroy(args, (file) => {
// expect(file('app/type/foo.js)).to.contain('foo');
}));
});
});

@@ -15,12 +15,9 @@ 'use strict';

/**
Setup mocha test hooks
Prepare the test context for the blueprint tests.
@method setupTestHooks
@param {Object} [scope]
@param {Object} scope
@param {Object} [options]
@param {Number} [options.timeout]
@param {Number} [options.timeout=20000]
@param {Object} [options.tmpenv]
@param {Function} [options.before]
@param {Function} [options.after]
@param {Function} [options.beforeEach]
@param {Function} [options.afterEach]
@return {null}

@@ -34,5 +31,2 @@ */

before(function () {
if (options && options.before) {
options.before();
}
BlueprintNpmTask.disableNPM(Blueprint);

@@ -43,5 +37,2 @@ conf.setup();

after(function() {
if (options && options.after) {
options.after();
}
BlueprintNpmTask.restoreNPM(Blueprint);

@@ -52,5 +43,2 @@ conf.restore();

beforeEach(function() {
if (options && options.beforeEach) {
options.beforeEach();
}
tmp.freshDir();

@@ -62,5 +50,2 @@ process.chdir(tmp.tmpdir);

afterEach(function() {
if (options && options.afterEach) {
options.afterEach();
}
debug('afterEach:tmpdir: ', walkSync(tmp.tmpdir));

@@ -67,0 +52,0 @@ this.timeout(10000);

{
"name": "ember-cli-blueprint-test-helpers",
"version": "0.10.2",
"version": "0.11.0",
"description": "Blueprint test helpers for ember-cli. Mocks ember-cli for generate and destroy commands.",
"main": "index.js",
"scripts": {
"lint": "eslint blueprints lib tests",
"test": "npm run lint && npm run nodetest",
"nodetest": "node tests/runner.js"
"lint": "mocha tests/lint-test",
"test": "mocha tests --recursive"
},

@@ -27,2 +26,3 @@ "ember-addon": {

"chai-as-promised": "^5.1.0",
"chai-files": "^1.0.0",
"debug": "^2.2.0",

@@ -32,5 +32,3 @@ "ember-cli-internal-test-helpers": "^0.8.1",

"findup": "^0.1.5",
"fs-extra": "^0.24.0",
"glob": "5.0.13",
"rsvp": "^3.0.17",
"fs-extra": "^0.26.7",
"tmp-sync": "^1.0.0",

@@ -43,6 +41,8 @@ "walk-sync": "^0.2.5"

"eslint-plugin-chai-expect": "^1.0.0",
"mocha": "^2.2.1",
"mocha-only-detector": "0.0.2",
"rimraf": "^2.4.3"
"mocha": "^2.4.5",
"mocha-eslint": "^2.0.2",
"mocha-only-detector": "^0.1.0",
"rimraf": "^2.4.3",
"rsvp": "^3.0.17"
}
}

@@ -0,3 +1,4 @@

ember-cli-blueprint-test-helpers
================================
==============================================================================

@@ -7,18 +8,34 @@ [![Build Status](https://travis-ci.org/ember-cli/ember-cli-blueprint-test-helpers.svg?branch=master)](https://travis-ci.org/ember-cli/ember-cli-blueprint-test-helpers)

test helpers for [ember-cli](https://github.com/ember-cli/ember-cli) blueprints
About
-----
ember-cli-blueprint-test-helpers contains several test helpers for testing blueprints.
Installation
------------------------------------------------------------------------------
Install the helpers via npm:
```
npm install --save-dev ember-cli-blueprint-test-helpers
```
Run the following command to generate the test runner:
```
ember generate ember-cli-blueprint-test-helpers
```
Usage
-----
------------------------------------------------------------------------------
Install ember-cli-blueprint-test-helpers
### Running Tests
Running Tests
-------------
The blueprint tests can be run by:
To run the blueprint tests, run `node node-tests/nodetest-runner.js`.
For convenience and CI purposes you can add the following to your `package.json`:
```
node node-tests/nodetest-runner.js
```
For convenience you should add the following to your `package.json`:
```json

@@ -29,196 +46,195 @@ "scripts": {

```
Then you can use `npm run nodetest` to run.
Generating Blueprint Tests
--------------------------
to be able to use `npm run nodetest` to run the tests.
Generate a blueprint test scaffold using the blueprint-test blueprint.
`ember g blueprint-test my-blueprint`
The blueprint test will be generated inside the node-tests/blueprint folder as:
### Generating Tests
Generate a blueprint test scaffold using the `blueprint-test` generator:
```
node-tests/blueprints/my-blueprint-test.js
ember generate blueprint-test my-blueprint
```
The minimum common setup is in the generated test, setup for generating and destroying a blueprint in one test.
Test Setup
----------
which will generate a test file at `node-tests/blueprints/my-blueprint-test.js`.
The `setupTestHooks` convenience method sets up a blueprint test with a timeout as well as before, after, beforeEach, and afterEach hooks:
### Example Usage
```js
describe('Acceptance: ember generate', function() {
// pass in test instance, and an optional options object.
setupTestHooks(this, {timeout: 1000});
describe('Acceptance: ember generate and destroy my-blueprint', function() {
// create and destroy temporary working directories
setupTestHooks(this);
it('my-blueprint foo', function() {
var 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
});
});
```
If you need to override or add to any of the hooks, you may pass a function in the options.
The options supported are:
* __timeout__ _(number)_: Duration before test times out.
* __tmpenv__ _(tmpenv object)_: Object containing info about the temporary directory for the test. Defaults to [`lib/helpers/tmp-env.js`](https://github.com/ember-cli/ember-cli-blueprint-test-helpers/blob/master/lib/helpers/tmp-env.js)
* __before__ _(function)_: Hook to execute code at the beginning of the before function.
* __after__ _(function)_: Hook to execute code at the beginning of the after function.
* __beforeEach__ _(function)_: Hook to execute code at the beginning of the beforeEach function.
* __afterEach__ _(function)_: Hook to execute code at the beginning of the afterEach function.
or more explicitly:
Generate and Destroy Test Helpers
---------------------------------
```js
describe('Acceptance: ember generate and destroy my-blueprint', function() {
// create and destroy temporary working directories
setupTestHooks(this);
Use `generate`, `destroy`, or `generateAndDestroy` to run a test.
it('my-blueprint foo', function() {
var args = ['my-blueprint', 'foo'];
All three methods take the following signature:
commandArgs (array), options (object)
// create a new Ember.js app in the working directory
return emberNew()
// then generate the `my-blueprint` blueprint called `foo`
.then(() => emberGenerate(args))
The commandArgs should contain any commandline properties and options that would be passed to a generate or destroy command.
// 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))
The options should contain a files object, as well as any of the following options:
* __usePods__ _(boolean)_: Sets up `.ember-cli` file with `"usePods": true`. Default: false
* __podModulePrefix__ _(boolean)_: Sets up `config/environment.js` with 'app/pods' as the `podModulePrefix`. Default: false
* __skipInit__ _(boolean)_: Skips the temporary project init step for situations where the project has already been setup. Most commonly used when generating inside the `afterGenerate` hook.
// then assert that the files were destroyed correctly
.then(() => expect(file('path/to/file.js')).to.not.exist);
});
});
```
* __target__ _(string)_: Defines the type of project to setup for the test. Recognized values: __'app'__, __'addon'__, __'inRepoAddon'__
* __packages__ _(array)_: A list of packages that should be removed from or added to the `package.json` file after the project has been set up (only affects the test this option is set for). Example:
```js
packages: [
{ name: 'ember-cli-qunit', delete: true },
{ name: 'ember-cli-mocha', dev: true, version: '~1.0.2' }
]
```
* __files__ _(array)_: Array of files to assert, represented by objects with `file`, `exists`, `contains`, or `doesNotContain` properties.
Example object:
API Reference
------------------------------------------------------------------------------
```js
files: [
{
file: 'path-to-file.js',
contains: ['file contents to compare'],
doesNotContain: ['file contents that shouldn\'t be present'],
exists: true //default true
}
]
```
* __throws__ _(string / / regexp / / or object)_: Expected error message or excerpt to assert. Optionally, can be an object containing a `message` and `type` property. The `type` is a string of the error name.
Example String:
This project exports two major API endpoints for you to use:
```js
throws: 'Expected error message text.'
```
Example RegExp:
- `require('ember-cli-blueprint-test-helpers/chai')`
```js
throws: /Expected error message text./
```
Example object:
This endpoint exports the [Chai](http://chaijs.com/) assertion library
including the [chai-as-promised](https://github.com/domenic/chai-as-promised)
and [chai-files](https://github.com/Turbo87/chai-files) plugins
```js
throws: {
message: 'Expected message',
type: 'SilentError'
}
// or
throws: {
message: /Expected message/,
type: 'SilentError'
}
```
* __beforeGenerate__ _(function)_: Hook to execute before generating blueprint. Can be used for additional setup and assertions.
* __afterGenerate__ _(function)_: Hook to execute after generating blueprint. Can be used for additional setup and assertions.
* __beforeDestroy__ _(function)_: Hook to execute before destroying blueprint. Can be used for additional setup and assertions.
* __afterDestroy__ _(function)_: Hook to execute before destroying blueprint. Can be used for additional teardown and assertions.
- `require('ember-cli-blueprint-test-helpers/helpers')`
Example Tests
-------------
This endpoint exports the functions mentioned in the following API reference
The following is a basic test, asserting `my-blueprint` generated the files in the `files` array and that their content matches, and then that the blueprint was destroyed and that the files in the `files` array were properly removed.
---
```js
var setupTestHooks = require('ember-cli-blueprint-test-helpers/lib/helpers/setup');
var BlueprintHelpers = require('ember-cli-blueprint-test-helpers/lib/helpers/blueprint-helper');
var generateAndDestroy = BlueprintHelpers.generateAndDestroy;
### `setupTestHooks(scope, options)`
describe('Acceptance: ember generate and destroy blueprint', function() {
setupTestHooks(this);
Prepare the test context for the blueprint tests.
**Parameters:**
it('blueprint test', function() {
return generateAndDestroy(['my-blueprint', 'foo'], {
files: [
{
file: 'path/to/file.js',
contains: [
'file contents to match',
'more file contents\n'
]
}
]
});
});
```
- `{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.
Defaults to [`lib/helpers/tmp-env.js`](lib/helpers/tmp-env.js)
To assert that an error is thrown when incorrect input is used, you can use the `throws` option. The throws option simply requires a regex of the full or partial error message.
**Returns:** `{Promise}`
```js
it('adapter application cannot extend from --base-class=application', function() {
return generateAndDestroy(['adapter', 'application', '--base-class=application'], {
throws: /Adapters cannot extend from themself/
});
});
```
---
You can also pass an object containing the message and error type.
### `emberNew(options)`
```js
it('adapter application cannot extend from --base-class=application', function() {
return generateAndDestroy(['adapter', 'application', '--base-class=application'], {
throws: {
message: /Adapters cannot extend from themself/,
type: 'SilentError'
}
});
});
```
Create a new Ember.js app or addon in the current working directory.
To generate another blueprint beforehand, you can use the `afterGenerate` hook to do your actual assertions, like in the example below. Be sure to include the `skipInit` option inside the `afterGenerate` hook to prevent re-initializing the temporary project, which can lead to problems.
**Parameters:**
```js
it('adapter extends from application adapter if present', function() {
return generateAndDestroy(['adapter', 'application'], {
afterGenerate: function() {
return generateAndDestroy(['adapter', 'foo'], {
// prevents this second generateAndDestroy from running init
skipInit: true,
files: [
{
file:'app/adapters/foo.js',
contains: [
"import ApplicationAdapter from './application';"
]
}
]
});
}
});
});
```
- `{Object} [options]` optional parameters
- `{String} [options.target='app']` the type of project to create (`app`, `addon` or `in-repo-addon`)
To setup a test project with a `podModulePrefix` or `usePods` setting, use the following options:
**Returns:** `{Promise}`
```js
it('blueprint test', function() {
return generateAndDestroy(['my-blueprint', 'foo'], {
usePods: true,
podModulePrefix: true
});
});
```
---
To test generating into addons, in-repo-addons, and dummy projects, you can use the `target` option:
### `emberGenerate(args)`
```js
it('blueprint test', function() {
return generateAndDestroy(['my-blueprint', 'foo'], {
// supported options are 'app', 'addon', and 'inRepoAddon'
target: 'addon'
});
});
```
Run a blueprint generator.
**Parameters:**
- `{Array.<String>} args` arguments to pass to `ember generate` (e.g. `['my-blueprint', 'foo']`)
**Returns:** `{Promise}`
---
### `emberDestroy(args)`
Run a blueprint destructor.
**Parameters:**
- `{Array.<String>} args` arguments to pass to `ember destroy` (e.g. `['my-blueprint', 'foo']`)
**Returns:** `{Promise}`
---
### `emberGenerateDestroy(args, assertionCallback)`
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
**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](https://opensource.org/licenses/MIT).
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc