ember-cli-blueprint-test-helpers
Advanced tools
Comparing version 0.9.0 to 0.10.0
@@ -5,10 +5,6 @@ 'use strict'; | ||
var Mocha = require('mocha'); | ||
var Promise = require('ember-cli/lib/ext/promise'); | ||
var RSVP = require('RSVP'); | ||
var rimraf = require('rimraf'); | ||
var mochaOnlyDetector = require('mocha-only-detector'); | ||
if (process.env.EOLNEWLINE) { | ||
require('os').EOL = '\n'; | ||
} | ||
rimraf.sync('.node_modules-tmp'); | ||
@@ -18,3 +14,3 @@ rimraf.sync('.bower_components-tmp'); | ||
var root = 'node-tests/{blueprints,acceptance,unit}'; | ||
var _checkOnlyInTests = Promise.denodeify(mochaOnlyDetector.checkFolder.bind(null, root + '/**/*{-test}.js')); | ||
var _checkOnlyInTests = RSVP.denodeify(mochaOnlyDetector.checkFolder.bind(null, root + '/**/*{-test}.js')); | ||
var optionOrFile = process.argv[2]; | ||
@@ -65,3 +61,3 @@ var mocha = new Mocha({ | ||
} else { | ||
return Promise.resolve(); | ||
return RSVP.Promise.resolve(); | ||
} | ||
@@ -68,0 +64,0 @@ } |
@@ -14,4 +14,5 @@ var Promise = require('ember-cli/lib/ext/promise'); | ||
this.addPackageToProject('rimraf', '^2.4.3'), | ||
this.addPackageToProject('rsvp','^3.0.17') | ||
]); | ||
} | ||
}; |
@@ -9,5 +9,5 @@ 'use strict'; | ||
var expect = require('chai').expect; | ||
var existsSync = require('exists-sync'); | ||
var walkSync = require('walk-sync'); | ||
var assertFile = require('ember-cli-internal-test-helpers/lib/helpers/assert-file'); | ||
var assertFileToNotExist = require('ember-cli-internal-test-helpers/lib/helpers/assert-file-to-not-exist'); | ||
var tmpenv = require('./tmp-env'); | ||
@@ -32,8 +32,5 @@ var debug = require('debug')('ember-cli:testing'); | ||
if(options.throws) { | ||
command.catch(assertThrows.bind(null, options.throws)); | ||
} else { | ||
command.catch(function(err) { throw err;}); | ||
if (options.throws) { | ||
return assertThrows(command, options, options.throws); | ||
} | ||
return command; | ||
@@ -57,5 +54,3 @@ } | ||
if (options.throws) { | ||
command.catch(assertThrows.bind(null, options.throws)); | ||
} else { | ||
command.catch(function(err) { throw err;}); | ||
return assertThrows(command, options, options.throws); | ||
} | ||
@@ -88,6 +83,4 @@ return command; | ||
if(options.throws) { | ||
command.catch(assertThrows.bind(null, options.throws)); | ||
} else { | ||
command.catch(function(err) { throw err;}); | ||
if (options.throws) { | ||
return assertThrows(command, options, options.throws); | ||
} | ||
@@ -147,3 +140,3 @@ return command; | ||
}) | ||
.then(resultContents.bind(null, options, tmpenv)) | ||
.then(resultContents.bind(null, options, tmpenv), throwResult.bind(null, options)) | ||
.then(afterProcess) | ||
@@ -185,3 +178,26 @@ .then(teardownProject.bind(null, options)) | ||
} | ||
/** | ||
Rejection handler to extract error from results object and rethrow | ||
Also asserts the result error type before rethrow | ||
@function throwResult | ||
@param {Object} [options] | ||
@param {Object|String|RegExp} [options.throws] | ||
@param {Object} [err] result received by reject promise | ||
@throws {Error} | ||
*/ | ||
function throwResult(options, err) { | ||
if (options && options.throws && err && err.statusCode) { | ||
if (err.errorLog && err.errorLog.length) { | ||
// assert the error type if we've defined one to check | ||
if (options.throws.type) { | ||
expect(err.errorLog[0].name).to.equal(options.throws.type); | ||
} | ||
throw err.errorLog[0]; | ||
} | ||
} | ||
throw err; | ||
} | ||
/** | ||
Process assertions from hook | ||
@@ -209,3 +225,3 @@ @function processAssertions | ||
} else { | ||
return assertFileNotExists(file.file); | ||
return assertFileToNotExist(file.file); | ||
} | ||
@@ -223,3 +239,3 @@ }); | ||
files.forEach(function(file) { | ||
return assertFileNotExists(file.file); | ||
return assertFileToNotExist(file.file); | ||
}); | ||
@@ -229,15 +245,5 @@ } | ||
/** | ||
Assert file doesn't exist | ||
@function assertFileNotExists | ||
@param {String} [file] | ||
@return {Chai.Assertion} | ||
*/ | ||
function assertFileNotExists(file) { | ||
var filePath = path.resolve(process.cwd(), file); | ||
return expect(!existsSync(filePath), 'expected ' + file + ' not to exist').to.be.ok; | ||
} | ||
/** | ||
Assert specific error is thrown. | ||
@function assertThrows | ||
@param {Promise} [promise] promise to assert | ||
@param {RegExp|Object} [assertion] message or error to match | ||
@@ -247,14 +253,16 @@ @param {Object} [err] error to assert | ||
*/ | ||
function assertThrows(assertion, err) { | ||
function assertThrows(promise, options, assertion) { | ||
var message; | ||
if (assertion instanceof RegExp) { | ||
message = assertion; | ||
} else if (assertion.message){ | ||
message = assertion.message; | ||
} else if (assertion.message) { | ||
if (assertion.message instanceof RegExp){ | ||
message = assertion.message; | ||
} else { | ||
message = new RegExp(assertion.message); | ||
} | ||
} else { | ||
message = new RegExp(assertion); | ||
} | ||
expect(err.message).to.match(message); | ||
if (assertion.name) { | ||
expect(err.name).to.match(assertion.name); | ||
} | ||
return expect(promise).to.be.rejectedWith(message); | ||
} | ||
@@ -306,4 +314,4 @@ /** | ||
getProjectRoot: getProjectRoot, | ||
assertFileNotExists: assertFileNotExists, | ||
assertFileNotExists: assertFileToNotExist, | ||
assertThrows: assertThrows | ||
}; |
{ | ||
"name": "ember-cli-blueprint-test-helpers", | ||
"version": "0.9.0", | ||
"version": "0.10.0", | ||
"description": "Blueprint test helpers for ember-cli. Mocks ember-cli for generate and destroy commands.", | ||
@@ -32,2 +32,4 @@ "main": "index.js", | ||
"fs-extra": "^0.24.0", | ||
"glob": "5.0.13", | ||
"rsvp": "^3.0.17", | ||
"tmp-sync": "^1.0.0", | ||
@@ -34,0 +36,0 @@ "walk-sync": "^0.2.5" |
ember-cli-blueprint-test-helpers | ||
================================ | ||
[![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) | ||
[![Build status](https://ci.appveyor.com/api/projects/status/github/ember-cli/ember-cli-blueprint-test-helpers?svg=true)](https://ci.appveyor.com/project/embercli/ember-cli-blueprint-test-helpers/branch/master) | ||
About | ||
@@ -35,3 +38,3 @@ ----- | ||
``` | ||
node-tests/blueprints/my-blueprint-nodetest.js | ||
node-tests/blueprints/my-blueprint-test.js | ||
``` | ||
@@ -77,3 +80,3 @@ The minimum common setup is in the generated test, setup for generating and destroying a blueprint in one test. | ||
* __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 | ||
@@ -85,4 +88,4 @@ packages: [ | ||
``` | ||
* __files__ _(array)_: Array of files to assert, represented by objects with `file`, `exists`, `contains`, or `doesNotContain` properties. | ||
Example object: | ||
* __files__ _(array)_: Array of files to assert, represented by objects with `file`, `exists`, `contains`, or `doesNotContain` properties. | ||
Example object: | ||
@@ -92,5 +95,5 @@ ```js | ||
{ | ||
file: 'path-to-file.js', | ||
contains: ['file contents to compare'], | ||
doesNotContain: ['file contents that shouldn\'t be present'], | ||
file: 'path-to-file.js', | ||
contains: ['file contents to compare'], | ||
doesNotContain: ['file contents that shouldn\'t be present'], | ||
exists: true //default true | ||
@@ -100,14 +103,25 @@ } | ||
``` | ||
* __throws__ _(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 RegExp: | ||
* __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: | ||
```js | ||
/Expected error message text./ | ||
``` | ||
Example object: | ||
throws: 'Expected error message text.' | ||
``` | ||
Example RegExp: | ||
```js | ||
{ | ||
message: /Expected message/, | ||
throws: /Expected error message text./ | ||
``` | ||
Example object: | ||
```js | ||
throws: { | ||
message: 'Expected message', | ||
type: 'SilentError' | ||
} | ||
// or | ||
throws: { | ||
message: /Expected message/, | ||
type: 'SilentError' | ||
} | ||
``` | ||
@@ -162,3 +176,3 @@ * __beforeGenerate__ _(function)_: Hook to execute before generating blueprint. Can be used for additional setup and assertions. | ||
return generateAndDestroy(['adapter', 'application', '--base-class=application'], { | ||
throws: { | ||
throws: { | ||
message: /Adapters cannot extend from themself/, | ||
@@ -165,0 +179,0 @@ type: 'SilentError' |
@@ -56,3 +56,3 @@ 'use strict'; | ||
var appPackage = getPackage('../../', 'app'); | ||
expect(appPackage).to.contain('/node-tests/fixtures/app/package'); | ||
expect(appPackage).to.contain(path.join('node-tests', 'fixtures', 'app', 'package')); | ||
}); | ||
@@ -62,3 +62,3 @@ | ||
var appPackage = getPackage('../../', 'addon'); | ||
expect(appPackage).to.contain('/node-tests/fixtures/addon/package'); | ||
expect(appPackage).to.contain(path.join('node-tests', 'fixtures', 'addon', 'package')); | ||
}); | ||
@@ -83,2 +83,2 @@ }); | ||
}); | ||
}); |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
38379
25
855
223
6
11
+ Addedglob@5.0.13
+ Addedrsvp@^3.0.17
+ Addedglob@5.0.13(transitive)
+ Addedminimatch@2.0.10(transitive)