ember-cli-addon-tests
Advanced tools
Comparing version 0.6.3 to 0.7.0
"use strict"; | ||
var RSVP = require('rsvp'); | ||
var path = require('path'); | ||
var debug = require('../utilities/debug'); | ||
@@ -6,0 +5,0 @@ var runEmber = require('../utilities/run-ember'); |
@@ -25,3 +25,3 @@ var fs = require('fs-extra'); | ||
return pristine.cloneApp(appName, options) | ||
return pristine.createApp(appName, options) | ||
.then(function(appPath) { | ||
@@ -28,0 +28,0 @@ app.path = appPath; |
@@ -0,1 +1,3 @@ | ||
/* global beforeEach, afterEach */ | ||
'use strict'; | ||
@@ -18,3 +20,3 @@ | ||
// seem to be possible though. | ||
console.log(logSink.join('\n')); | ||
console.log(logSink.join('\n')); //eslint-disable-line no-console | ||
} | ||
@@ -21,0 +23,0 @@ logSink = []; |
"use strict"; | ||
var path = require('path'); | ||
var debug = require('./debug'); | ||
var temp = require('./temp'); | ||
var chdir = require('./chdir'); | ||
var fs = require('fs-extra'); | ||
var findup = require('findup-sync'); | ||
var existsSync = fs.existsSync; | ||
var Promise = require('rsvp').Promise; | ||
var moveDirectory = require('./move-directory'); | ||
var symlinkDirectory = require('./symlink-directory'); | ||
var runCommand = require('./run-command'); | ||
var runEmber = require('./run-ember'); | ||
var runNew = require('./run-new'); | ||
var mkdirp = require('mkdirp'); | ||
const path = require('path'); | ||
const debug = require('./debug'); | ||
const temp = require('./temp'); | ||
const chdir = require('./chdir'); | ||
const fs = require('fs-extra'); | ||
const findup = require('findup-sync'); | ||
const existsSync = fs.existsSync; | ||
const Promise = require('rsvp').Promise; | ||
const moveDirectory = require('./move-directory'); | ||
const symlinkDirectory = require('./symlink-directory'); | ||
const runCommand = require('./run-command'); | ||
const runEmber = require('./run-ember'); | ||
const runNew = require('./run-new'); | ||
const mkdirp = require('mkdirp'); | ||
const semver = require('semver'); | ||
var previousCwd; | ||
// As of Ember-CLI@2.13.0, it no longer uses Bower by default | ||
const usesBower = semver.lt(require('ember-cli/package').version, '2.13.0'); | ||
const runCommandOptions = { | ||
// Note: We must override the default logOnFailure logging, because we are | ||
// not inside a test. | ||
log: function() { | ||
return; // no output for initial application build | ||
} | ||
}; | ||
function cloneApp(appName, options) { | ||
var tempDir = temp.ensureCreated(); | ||
let previousCwd; | ||
/** | ||
* Creates a new application with the given name. If the application was created | ||
* previously, a fresh clone will be created. | ||
* | ||
* @param {String} appName | ||
* @param {Object} [options] | ||
* @param {String} [options.emberVersion] | ||
* @param {String} [options.emberDataVersion] | ||
*/ | ||
function createApp(appName, options) { | ||
let tempDir = temp.ensureCreated(); | ||
previousCwd = process.cwd(); | ||
debug('previousCwd=%s', previousCwd); | ||
@@ -28,4 +48,4 @@ | ||
var pristineAppPath = path.join(temp.pristinePath, appName); | ||
var underTestAppPath = path.join(temp.underTestPath, appName); | ||
let pristineAppPath = path.join(temp.pristinePath, appName); | ||
let underTestAppPath = path.join(temp.underTestPath, appName); | ||
@@ -39,107 +59,120 @@ // If this app was already tested, delete the copy. | ||
// If a pristine version of the app doesn't exist, create it. | ||
// If a pristine version of the app doesn't exist, create one by installing it. | ||
let appInstallation; | ||
if (!fs.existsSync(pristineAppPath)) { | ||
return installPristineApp(appName, options) | ||
.then(function() { | ||
copyUnderTestApp(pristineAppPath, underTestAppPath); | ||
}) | ||
.then(function() { | ||
chdir(previousCwd); | ||
return underTestAppPath; | ||
}); | ||
appInstallation = installPristineApp(appName, options); | ||
} else { | ||
appInstallation = Promise.resolve(); | ||
} | ||
copyUnderTestApp(pristineAppPath, underTestAppPath); | ||
chdir(previousCwd); | ||
return Promise.resolve(underTestAppPath); | ||
return appInstallation.then(() => { | ||
copyUnderTestApp(pristineAppPath, underTestAppPath); | ||
chdir(previousCwd); | ||
return underTestAppPath; | ||
}); | ||
} | ||
module.exports = { | ||
cloneApp: cloneApp | ||
createApp | ||
}; | ||
function installPristineApp(appName, options) { | ||
var hasNodeModules = hasPristineNodeModules(); | ||
var hasBowerComponents = hasPristineBowerComponents(); | ||
var extraOptions = []; | ||
var emberVersion = options.emberVersion || 'canary'; | ||
var emberDataVersion = options.emberDataVersion || 'emberjs/data#master'; | ||
let hasNodeModules = hasPristineNodeModules(); | ||
let hasBowerComponents = hasPristineBowerComponents(); | ||
// First, determine if we can skip installing npm packages | ||
// or Bower components if we have a pristine set of dependencies | ||
// already. | ||
chdir(temp.pristinePath); | ||
// Fresh install | ||
if (!hasNodeModules && !hasBowerComponents) { | ||
debug("no node_modules or bower_components"); | ||
// bower_components but no node_modules | ||
} else if (!hasNodeModules && hasBowerComponents) { | ||
debug("no node_modules but existing bower_components"); | ||
extraOptions = ['--skip-bower']; | ||
// node_modules but no bower_components | ||
} else if (hasNodeModules && !hasBowerComponents) { | ||
debug("no bower_components but existing node_modules"); | ||
extraOptions = ['--skip-npm']; | ||
// Everything is already there | ||
} else { | ||
debug("existing node_modules and bower_components"); | ||
extraOptions = ['--skip-npm', '--skip-bower']; | ||
// Install a vanilla app and cd into it | ||
let args = generateArgsForEmberNew(hasNodeModules, hasBowerComponents); | ||
let promise = runNew(appName, args) | ||
.catch(handleResult) | ||
.then(() => chdir(path.join(temp.pristinePath, appName))); | ||
let setupOptions = { | ||
appName, | ||
hasNodeModules, | ||
hasBowerComponents, | ||
emberVersion: options.emberVersion || 'canary', | ||
emberDataVersion: options.emberDataVersion || 'emberjs/data#master' | ||
}; | ||
promise = promise | ||
.then(() => nodeModulesSetup(setupOptions)) | ||
.then(() => { | ||
if (usesBower) { | ||
return bowerSetup(setupOptions); | ||
} | ||
}); | ||
// All dependencies should be installed, so symlink them into the app and | ||
// run the addon's blueprint to finish the app creation. | ||
return promise | ||
.then(() => linkDependencies(appName)) | ||
.then(runAddonGenerator); | ||
} | ||
// Generates the arguments to pass to `ember new`. Optionally skipping the | ||
// npm and/or bower installation phases. | ||
function generateArgsForEmberNew(skipNpm, skipBower) { | ||
let extraOptions = []; | ||
if (skipNpm) { | ||
debug('skipping npm'); | ||
extraOptions.push('--skip-npm'); | ||
} | ||
chdir(temp.pristinePath); | ||
if (skipBower) { | ||
debug('skipping bower'); | ||
extraOptions.push('--skip-bower'); | ||
} | ||
var args = extraOptions.concat(runCommandOptions); | ||
return extraOptions.concat(runCommandOptions); | ||
} | ||
var promise = runNew(appName, args) | ||
.catch(handleResult) | ||
.then(function() { | ||
chdir(path.join(temp.pristinePath, appName)); | ||
}) | ||
.then(addEmberDataToDependencies(appName, emberDataVersion)) | ||
.then(removeEmberSourceFromDependencies(appName, emberVersion)); | ||
function nodeModulesSetup(options) { | ||
let appName = options.appName; | ||
let emberVersion = options.emberVersion; | ||
let emberDataVersion = options.emberDataVersion; | ||
let hasNodeModules = options.hasNodeModules; | ||
// If we installed a fresh node_modules or bower_components directory, | ||
// grab those as pristine copies we can use in future runs. | ||
// Modifies the package.json to include correct versions of dependencies | ||
let promise = Promise.resolve() | ||
.then(() => addEmberDataToDependencies(appName, emberDataVersion)) | ||
.then(() => updateEmberSource(appName, emberVersion)); | ||
if (!hasNodeModules) { | ||
promise = promise.then(function() { | ||
promise = promise | ||
.then(() => { | ||
debug('installing ember-disable-prototype-extensions'); | ||
return runCommand('npm', 'install', 'ember-disable-prototype-extensions'); | ||
}) | ||
.then(function() { | ||
.then(() => { | ||
debug("installed ember-disable-prototype-extension"); | ||
}) | ||
.then(function() { | ||
return runCommand('npm', 'install'); | ||
}) | ||
.then(function() { | ||
debug('installed ember-data ' + emberDataVersion); | ||
}) | ||
.then(symlinkAddon(appName)); | ||
.then(() => debug('installed ember-data ' + emberDataVersion)) | ||
.then(() => symlinkAddon(appName)) | ||
.then(() => movePristineNodeModules(appName)); | ||
} | ||
promise = promise.then(addEmberToBowerJSON(appName, emberVersion)) | ||
.then(removeEmberDataFromBowerJSON(appName)) | ||
.then(addAddonUnderTestToDependencies(appName)); | ||
return promise.then(() => addAddonUnderTestToDependencies(appName)); | ||
} | ||
if (!hasBowerComponents) { | ||
promise = promise.then(function() { | ||
return runCommand('bower', 'install'); | ||
}) | ||
.then(function() { | ||
debug('installed ember ' + emberVersion); | ||
}); | ||
} | ||
function bowerSetup(options) { | ||
let appName = options.appName; | ||
let emberVersion = options.emberVersion; | ||
let hasBowerComponents = options.hasBowerComponents; | ||
if (!hasNodeModules) { | ||
promise = promise.then(movePristineNodeModules(appName)); | ||
} | ||
let promise = Promise.resolve() | ||
.then(() => addEmberToBowerJSON(appName, emberVersion)) | ||
.then(() => removeEmberDataFromBowerJSON(appName)); | ||
if (!hasBowerComponents) { | ||
promise = promise.then(movePristineBowerComponents(appName)); | ||
promise = promise | ||
.then(() => runCommand('bower', 'install')) | ||
.then(() => debug('installed ember ' + emberVersion)) | ||
.then(() => movePristineBowerComponents(appName)); | ||
} | ||
return promise.then(linkDependencies(appName)) | ||
// at this point we have all deps available, so we can run ember-cli | ||
.then(runAddonGenerator); | ||
return promise; | ||
} | ||
@@ -156,13 +189,9 @@ | ||
function movePristineNodeModules(appName) { | ||
return function() { | ||
var nodeModulesPath = path.join(temp.pristinePath, appName, 'node_modules'); | ||
moveDirectory(nodeModulesPath, temp.pristineNodeModulesPath); | ||
}; | ||
var nodeModulesPath = path.join(temp.pristinePath, appName, 'node_modules'); | ||
moveDirectory(nodeModulesPath, temp.pristineNodeModulesPath); | ||
} | ||
function movePristineBowerComponents(appName) { | ||
return function() { | ||
var bowerComponentsPath = path.join(temp.pristinePath, appName, 'bower_components'); | ||
moveDirectory(bowerComponentsPath, temp.pristineBowerComponentsPath); | ||
}; | ||
var bowerComponentsPath = path.join(temp.pristinePath, appName, 'bower_components'); | ||
moveDirectory(bowerComponentsPath, temp.pristineBowerComponentsPath); | ||
} | ||
@@ -184,102 +213,101 @@ | ||
function addEmberToBowerJSON(appName, version) { | ||
return function() { | ||
var bowerJSONPath = path.join(temp.pristinePath, appName, 'bower.json'); | ||
var bowerJSON = fs.readJsonSync(bowerJSONPath); | ||
var bowerJSONPath = path.join(temp.pristinePath, appName, 'bower.json'); | ||
var bowerJSON = fs.readJsonSync(bowerJSONPath); | ||
bowerJSON.resolutions = { | ||
"ember": version | ||
}; | ||
bowerJSON.resolutions = { | ||
"ember": version | ||
}; | ||
bowerJSON.dependencies['ember'] = version; | ||
bowerJSON.dependencies['ember'] = version; | ||
fs.writeJsonSync(bowerJSONPath, bowerJSON); | ||
}; | ||
fs.writeJsonSync(bowerJSONPath, bowerJSON); | ||
} | ||
function removeEmberDataFromBowerJSON(appName) { | ||
return function() { | ||
var bowerJSONPath = path.join(temp.pristinePath, appName, 'bower.json'); | ||
var bowerJSON = fs.readJsonSync(bowerJSONPath); | ||
var bowerJSONPath = path.join(temp.pristinePath, appName, 'bower.json'); | ||
var bowerJSON = fs.readJsonSync(bowerJSONPath); | ||
delete bowerJSON.dependencies['ember-data']; | ||
delete bowerJSON.dependencies['ember-data']; | ||
fs.writeJsonSync(bowerJSONPath, bowerJSON); | ||
}; | ||
fs.writeJsonSync(bowerJSONPath, bowerJSON); | ||
} | ||
function symlinkAddon(appName) { | ||
return function() { | ||
var pkg = findAddonPackageJSON(); | ||
var addonPath = findAddonPath(); | ||
var addonSymlinkPath = path.join(temp.pristinePath, appName, 'node_modules', pkg.name); | ||
var pkgScope = path.dirname(pkg.name); | ||
var pkg = findAddonPackageJSON(); | ||
var addonPath = findAddonPath(); | ||
var addonSymlinkPath = path.join(temp.pristinePath, appName, 'node_modules', pkg.name); | ||
var pkgScope = path.dirname(pkg.name); | ||
debug("symlinking %s", pkg.name); | ||
debug("symlinking %s", pkg.name); | ||
if (pkgScope !== '.') { | ||
debug("symlink: creating directory %s for scoped package name", pkgScope); | ||
// In case the package has a scoped name, make sure the scope directoy exists before symlinking | ||
mkdirp.sync(path.join(temp.pristinePath, appName, 'node_modules', pkgScope)); | ||
if (pkgScope !== '.') { | ||
debug("symlink: creating directory %s for scoped package name", pkgScope); | ||
// In case the package has a scoped name, make sure the scope directoy exists before symlinking | ||
mkdirp.sync(path.join(temp.pristinePath, appName, 'node_modules', pkgScope)); | ||
} | ||
if (existsSync(addonSymlinkPath)) { | ||
var stats = fs.lstatSync(addonSymlinkPath); | ||
if (stats.isSymbolicLink()) { | ||
debug("%s is already symlinked", pkg.name); | ||
return; | ||
} | ||
if (existsSync(addonSymlinkPath)) { | ||
var stats = fs.lstatSync(addonSymlinkPath); | ||
if (stats.isSymbolicLink()) { | ||
debug("%s is already symlinked", pkg.name); | ||
return; | ||
} | ||
fs.removeSync(addonSymlinkPath); | ||
} | ||
fs.removeSync(addonSymlinkPath); | ||
} | ||
symlinkDirectory(addonPath, addonSymlinkPath); | ||
}; | ||
symlinkDirectory(addonPath, addonSymlinkPath); | ||
} | ||
function addEmberDataToDependencies(appName, version) { | ||
return function() { | ||
var packageJSONPath = path.join(temp.pristinePath, appName, 'package.json'); | ||
var packageJSONPath = path.join(temp.pristinePath, appName, 'package.json'); | ||
debug('installing ember-data ' + version); | ||
debug('installing ember-data ' + version); | ||
var packageJSON = fs.readJsonSync(packageJSONPath); | ||
var packageJSON = fs.readJsonSync(packageJSONPath); | ||
packageJSON.devDependencies['ember-data'] = version; | ||
packageJSON.devDependencies['ember-data'] = version; | ||
fs.writeJsonSync('package.json', packageJSON); | ||
}; | ||
fs.writeJsonSync('package.json', packageJSON); | ||
} | ||
function removeEmberSourceFromDependencies(appName, version) { | ||
return function() { | ||
var packageJSONPath = path.join(temp.pristinePath, appName, 'package.json'); | ||
function updateEmberSource(appName, version) { | ||
var packageJSONPath = path.join(temp.pristinePath, appName, 'package.json'); | ||
var packageJSON = fs.readJsonSync(packageJSONPath); | ||
var packageJSON = fs.readJsonSync(packageJSONPath); | ||
// If we're not using bower, but the ember version is canary, we change it to | ||
// beta instead. This is because ember-source does not support canary releases. | ||
if (!usesBower && version === 'canary') { | ||
debug('ember-source cannot use canary releases, defaulting to beta'); | ||
version = 'beta'; | ||
} | ||
if (version === 'canary' && packageJSON.devDependencies.hasOwnProperty('ember-source')) { | ||
// ember-source does not support canary builds, therefore we will remove this entry and | ||
// use ember from bower | ||
if (packageJSON.devDependencies.hasOwnProperty('ember-source')) { | ||
// If we're using bower, we need to remove ember-source from package.json, | ||
// otherwise we update to the appropriate version. | ||
if (usesBower) { | ||
debug('removing ember-source from NPM '); | ||
delete packageJSON.devDependencies['ember-source']; | ||
fs.writeJsonSync('package.json', packageJSON); | ||
} else { | ||
debug('updating ember-source version to %s', version); | ||
packageJSON.devDependencies['ember-source'] = version; | ||
} | ||
}; | ||
fs.writeJsonSync('package.json', packageJSON); | ||
} | ||
} | ||
function addAddonUnderTestToDependencies(appName) { | ||
return function() { | ||
var pkg = findAddonPackageJSON(); | ||
var packageJSONPath = path.join(temp.pristinePath, appName, 'package.json'); | ||
var pkg = findAddonPackageJSON(); | ||
var packageJSONPath = path.join(temp.pristinePath, appName, 'package.json'); | ||
debug('installing %s as addon for application', pkg.name); | ||
debug('installing %s as addon for application', pkg.name); | ||
// Read the current version of the FastBoot addon under test, then add that | ||
// to the Ember app's package.json. | ||
var packageJSON = fs.readJsonSync(packageJSONPath); | ||
// Read the current version of the FastBoot addon under test, then add that | ||
// to the Ember app's package.json. | ||
var packageJSON = fs.readJsonSync(packageJSONPath); | ||
packageJSON.devDependencies[pkg.name] = pkg.version; | ||
packageJSON.devDependencies[pkg.name] = pkg.version; | ||
fs.writeJsonSync('package.json', packageJSON); | ||
}; | ||
fs.writeJsonSync('package.json', packageJSON); | ||
} | ||
@@ -328,17 +356,9 @@ | ||
function linkDependencies(appName) { | ||
return function() { | ||
var nodeModulesAppPath = path.join(temp.pristinePath, appName, 'node_modules'); | ||
var bowerComponentsAppPath = path.join(temp.pristinePath, appName, 'bower_components'); | ||
let nodeModulesAppPath = path.join(temp.pristinePath, appName, 'node_modules'); | ||
symlinkDirectory(temp.pristineNodeModulesPath, nodeModulesAppPath); | ||
symlinkDirectory(temp.pristineNodeModulesPath, nodeModulesAppPath); | ||
if (usesBower) { | ||
let bowerComponentsAppPath = path.join(temp.pristinePath, appName, 'bower_components'); | ||
symlinkDirectory(temp.pristineBowerComponentsPath, bowerComponentsAppPath); | ||
}; | ||
} | ||
} | ||
var runCommandOptions = { | ||
// Note: We must override the default logOnFailure logging, because we are | ||
// not inside a test. | ||
log: function() { | ||
return; // no output for initial application build | ||
} | ||
}; |
{ | ||
"name": "ember-cli-addon-tests", | ||
"version": "0.6.3", | ||
"version": "0.7.0", | ||
"description": "A set of integration test helpers for Ember CLI addons", | ||
@@ -20,3 +20,4 @@ "keywords": [ | ||
"scripts": { | ||
"test": "cross-env DEBUG=ember-cli-addon-tests mocha test/acceptance" | ||
"test": "cross-env DEBUG=ember-cli-addon-tests npm run test:mocha", | ||
"test:mocha": "mocha test test/acceptance" | ||
}, | ||
@@ -28,4 +29,4 @@ "dependencies": { | ||
"exists-sync": "0.0.4", | ||
"findup-sync": "^0.4.3", | ||
"fs-extra": "^2.0.0", | ||
"findup-sync": "^1.0.0", | ||
"fs-extra": "^3.0.0", | ||
"fs-promise": "^2.0.0", | ||
@@ -35,2 +36,3 @@ "lodash": "^4.0.0", | ||
"rsvp": "^3.1.0", | ||
"semver": "^5.3.0", | ||
"symlink-or-copy": "^1.1.3", | ||
@@ -41,6 +43,7 @@ "temp": "^0.8.3" | ||
"chai": "^3.5.0", | ||
"cross-env": "^3.1.4", | ||
"ember-cli": "~2.9.0", | ||
"ember-cli-fastboot": "1.0.0-beta.15", | ||
"cross-env": "^4.0.0", | ||
"ember-cli": "~2.13.0", | ||
"ember-cli-fastboot": "1.0.0-beta.18", | ||
"mocha": "^3.1.2", | ||
"mocha-eslint": "^3.0.1", | ||
"request": "^2.75.0" | ||
@@ -47,0 +50,0 @@ }, |
@@ -26,3 +26,3 @@ "use strict"; | ||
.catch(function(e) { | ||
console.log(e); | ||
console.log(e); // eslint-disable-line no-console | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
32955
20
699
1
13
7
+ Addedsemver@^5.3.0
+ Addedfindup-sync@1.0.0(transitive)
+ Addedfs-extra@3.0.1(transitive)
+ Addedjsonfile@3.0.1(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addeduniversalify@0.1.2(transitive)
- Removedfindup-sync@0.4.3(transitive)
Updatedfindup-sync@^1.0.0
Updatedfs-extra@^3.0.0