Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
ember-cli-blueprint-test-helpers
Advanced tools
Blueprint test helpers for ember-cli. Mocks ember-cli for generate and destroy commands.
ember-cli-blueprint-test-helpers contains several test helpers for testing blueprints.
Install ember-cli-blueprint-test-helpers
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
:
"scripts": {
"nodetest": "node node-tests/nodetest-runner.js"
}
Then you can use npm run nodetest
to run.
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:
node-tests/blueprints/my-blueprint-test.js
The minimum common setup is in the generated test, setup for generating and destroying a blueprint in one test.
The setupTestHooks
convenience method sets up a blueprint test with a timeout as well as before, after, beforeEach, and afterEach hooks:
describe('Acceptance: ember generate', function() {
// pass in test instance, and an optional options object.
setupTestHooks(this, {timeout: 1000});
If you need to override or add to any of the hooks, you may pass a function in the options. The options supported are:
lib/helpers/tmp-env.js
Use generate
, destroy
, or generateAndDestroy
to run a test.
All three methods take the following signature: commandArgs (array), options (object)
The commandArgs should contain any commandline properties and options that would be passed to a generate or destroy command.
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.
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:
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:
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:
throws: 'Expected error message text.'
Example RegExp:
throws: /Expected error message text./
Example object:
throws: {
message: 'Expected message',
type: 'SilentError'
}
// or
throws: {
message: /Expected message/,
type: 'SilentError'
}
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.
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;
describe('Acceptance: ember generate and destroy blueprint', function() {
setupTestHooks(this);
it('blueprint test', function() {
return generateAndDestroy(['my-blueprint', 'foo'], {
files: [
{
file: 'path/to/file.js',
contains: [
'file contents to match',
'more file contents\n'
]
}
]
});
});
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.
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.
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'
}
});
});
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.
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';"
]
}
]
});
}
});
});
To setup a test project with a podModulePrefix
or usePods
setting, use the following options:
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:
it('blueprint test', function() {
return generateAndDestroy(['my-blueprint', 'foo'], {
// supported options are 'app', 'addon', and 'inRepoAddon'
target: 'addon'
});
});
FAQs
Blueprint test helpers for ember-cli. Mocks ember-cli for generate and destroy commands.
The npm package ember-cli-blueprint-test-helpers receives a total of 1,328 weekly downloads. As such, ember-cli-blueprint-test-helpers popularity was classified as popular.
We found that ember-cli-blueprint-test-helpers demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.