Skip to content

fix(tests): link package in e2e tests #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ before_install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.30.1/install.sh | bash; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then source ~/.nvm/nvm-exec; fi
- nvm install $NODE_VERSION
- npm link npm
- npm config set spin false
install:
- node --version
Expand Down
72 changes: 34 additions & 38 deletions addon/ng2/tasks/lib-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

var Promise = require('ember-cli/lib/ext/promise');
var Task = require('ember-cli/lib/models/task');
var npm = require('ember-cli/lib/utilities/npm');
var shellPromise = require ('../utilities/shell-promise');
var existsSync = require('exists-sync');
var chalk = require('chalk');
var path = require('path');
Expand All @@ -18,36 +18,30 @@ module.exports = Task.extend({
completionOKMessage: '',
completionErrorMessage: 'Error installing packages. Did you misspelt it?',

init: function() {
this.npm = this.npm || require('npm');
},
run: function(options) {
this.packages = options.packages || [];
this.skipInjection = options.skipInjection || false;
this.autoInjection = options.autoInjection || false;
this.disableLogger();

this.ui.startProgress(chalk.green('Installing 3rd party package:',
this.ui.startProgress(chalk.green('Installing 3rd party package:',
this.packages.join(', ')), chalk.green('.'));

this.npmOptions = {
logLevel: 'error',
logstream: this.ui.outputStream,
color: 'always',
optional: true,
'save-dev': true,
'save-exact': !!options['save-exact']
};

return npm('install', this.packages, this.npmOptions, this.npm)
.then(function(npmresp) {
this.npmOptions = ' --loglevel error --color always --optional --save-dev ' +
'--save-exact ' + !!options['save-exact'];

var npmCommand = 'npm install ' + this.packages.join(' ') + this.npmOptions;

return shellPromise(npmCommand)
.then(function (npmresp) {

if (this.skipInjection) {
return this.announceOKCompletion();
}

if (this.autoInjection) {
var pkg = this.packages[0];

if (existsSync(path.resolve(process.cwd(), 'src', 'app.ts'))) {
var entryPoint = path.resolve(process.cwd(), 'src', 'app.ts');
var packageData = this.parseFile(pkg);
Expand All @@ -57,10 +51,10 @@ module.exports = Task.extend({
return this.announceOKCompletion();
}

return this.installProcedure()
.then(function(resp) {
return this.announceOKCompletion();
}.bind(this));
return this.installProcedure();
}.bind(this))
.then(function(resp) {
return this.announceOKCompletion();
}.bind(this));
},

Expand All @@ -83,12 +77,14 @@ module.exports = Task.extend({
'as authentic: ' + allPackages.toUninstall.join(', ');
this.ui.writeLine(chalk.yellow(msg));

return npm('uninstall', allPackages.toUninstall, this.npmOptions, this.npm)
var npmCommand = 'npm uninstall ' + allPackages.toUninstall.join(' ') + this.npmOptions;

return shellPromise(npmCommand)
.then(function() {
return this.processPackages(allPackages.toProcess)
.then(function(resp) {
return resolve(resp);
});
.then(function(resp) {
return resolve(resp);
});
}.bind(this));
}
else {
Expand Down Expand Up @@ -133,7 +129,7 @@ module.exports = Task.extend({
return new Promise(function(resolve, reject) {
var packageData;

var msg = 'Customize the injection of ' +
var msg = 'Customize the injection of ' +
chalk.yellow(path.basename(packageName)) + '? (Y/n)';

return this.ui.prompt({
Expand Down Expand Up @@ -226,7 +222,7 @@ module.exports = Task.extend({
type: 'input',
name: 'sel',
message: msg,
filter: function (val) { return val.trim(); },
filter: function (val) { return val.trim(); },
validate: function(value) {
return value > 0 && value <= packageData[componentKey].length ? true : 'Enter a valid value';
}
Expand Down Expand Up @@ -260,8 +256,8 @@ module.exports = Task.extend({
packageName,
packageData[componentKey][componentIndex]);

this.injectItem(componentKey.toLowerCase(),
packageData[componentKey][componentIndex],
this.injectItem(componentKey.toLowerCase(),
packageData[componentKey][componentIndex],
possibleFiles[fileIndex]);

this.ui.writeLine(chalk.green('Successfully injected.'));
Expand Down Expand Up @@ -336,8 +332,8 @@ module.exports = Task.extend({

if (removeNextLine) {
arr.splice(index, 1);
if (/;/.test(line)) {
removeNextLine = false;
if (/;/.test(line)) {
removeNextLine = false;
}
}
});
Expand All @@ -348,12 +344,12 @@ module.exports = Task.extend({
function generateFlatImportLine(arr, fromIndex) {
var lineArr = [];
var lastIndex;

arr.forEach(function(line, index) {
if (index >= fromIndex && !lastIndex) {
lineArr.push(line);
if (/;/.test(line)) {
lastIndex = true;
if (/;/.test(line)) {
lastIndex = true;
}
}
});
Expand Down Expand Up @@ -443,7 +439,7 @@ module.exports = Task.extend({

if (/\)/.test(line)) {
replace = line.match(/\((.*?)\)/)[0];
}
}
else {
replace = contentsArr.splice(index, contentsArr.length - 1).join('\n').replace(/\n/g, '');
replace = replace.match(/\((.*?)\)/)[0];
Expand Down Expand Up @@ -495,7 +491,7 @@ module.exports = Task.extend({
match = match.replace(/[\[\]]/g, '');
match = match.split(',');
match.push(name);
match = match.filter(function(n) { return n !== ''; } );
match = match.filter(function(n) { return n !== ''; } );
contentsArr[index] = contentsArr[index].replace(replace, '[' + match.join(',') + ']');
}
}.bind(this));
Expand All @@ -505,14 +501,14 @@ module.exports = Task.extend({

parseFile: function (packageName) {
var packagePath = path.join(process.cwd(), 'node_modules', packageName, packageName + '.ts');

if (!existsSync(packagePath)) {
return false;
}

var contents = fs.readFileSync(packagePath, 'utf8');
var data = {};

data.Component = [];
data.Directive = [];
data.Pipe = [];
Expand Down
34 changes: 13 additions & 21 deletions addon/ng2/tasks/lib-uninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

var Promise = require('ember-cli/lib/ext/promise');
var Task = require('ember-cli/lib/models/task');
var npm = require('ember-cli/lib/utilities/npm');
var shellPromise = require ('../utilities/shell-promise');
var existsSync = require('exists-sync');
var chalk = require('chalk');
var path = require('path');
Expand All @@ -19,34 +19,27 @@ module.exports = Task.extend({
completionOKMessage: '',
completionErrorMessage: 'Error uninstalling packages. Did you misspelt it?',

init: function() {
this.npm = this.npm || require('npm');
},
run: function(options) {
this.packages = options.packages || [];
this.autoRemove = options.autoRemove || false;
this.disableLogger();

this.ui.startProgress(chalk.green('Uninstalling 3rd party package:',
this.ui.startProgress(chalk.green('Uninstalling 3rd party package:',
this.packages.join(', ')), chalk.green('.'));

this.npmOptions = {
logLevel: 'error',
logstream: this.ui.outputStream,
color: 'always',
optional: true,
'save-dev': true,
'save-exact': !!options['save-exact']
};

this.getPackagesDataBeforeRemoved(this.packages);

return npm('uninstall', this.packages, this.npmOptions, this.npm)
this.npmOptions = ' --loglevel error --color always --optional --save-dev ' +
'--save-exact ' + !!options['save-exact'];

var npmCommand = 'npm uninstall ' + this.packages.join(' ') + this.npmOptions;

return shellPromise(npmCommand)
.then(function(npmresp) {
if (!npmresp.length) {
this.completionErrorMessage = 'No packages uninstalled.';
return this.announceErrorCompletion();
}
}
else {
if (this.autoRemove) {
this.removePackagesFromApp();
Expand All @@ -60,7 +53,6 @@ module.exports = Task.extend({
}
}
}.bind(this));

},

uninstallProcedure: function() {
Expand All @@ -86,14 +78,14 @@ module.exports = Task.extend({

parseFile: function (packageName) {
var packagePath = path.resolve(process.cwd(), 'node_modules', packageName, packageName + '.ts');

if (!existsSync(packagePath)) {
return false;
}

var contents = fs.readFileSync(packagePath, 'utf8');
var data = {};

data.Directive = [];
data.Pipe = [];
data.Provider = [];
Expand Down Expand Up @@ -170,7 +162,7 @@ module.exports = Task.extend({
cleanAfterRemoval: function(contents) {
var bootstrap = false;

contents = contents.filter(function(line) {
contents = contents.filter(function(line) {
if (/bootstrap\(/.test(line)) {
bootstrap = true;
}
Expand Down Expand Up @@ -227,4 +219,4 @@ module.exports = Task.extend({
console.log = this.oldLog; // Hack, see above
}

});
});
16 changes: 16 additions & 0 deletions addon/ng2/utilities/shell-promise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/* jshint node: true */
'use strict';

var Promise = require('ember-cli/lib/ext/promise');
var sh = require('shelljs');

module.exports = function shellPromise(command) {
return new Promise(function(resolve, reject) {
return sh.exec(command, {
silent: true
}, function(code, stdout, stderr) {
if (code !== 0) reject(stderr);
else resolve(stdout);
});
});
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"node-notifier": "^4.4.0",
"resolve": "^1.0.0",
"silent-error": "^1.0.0",
"shelljs": "^0.5.3",
"symlink-or-copy": "^1.0.1",
"typescript": "~1.7.3",
"typings": "^0.6.2"
Expand All @@ -60,7 +61,6 @@
"minimatch": "^2.0.10",
"mocha": "^2.2.5",
"rewire": "^2.3.4",
"shelljs": "^0.5.3",
"through": "^2.3.8",
"walk-sync": "^0.2.6"
}
Expand Down
5 changes: 3 additions & 2 deletions tests/e2e/e2e_workflow.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ describe('Basic end-to-end Workflow', function () {
it('Installs angular-cli correctly', function() {
this.timeout(300000);

sh.exec('npm link', {silent: true});
return tmp.setup('./tmp')
.then(function () {
process.chdir('./tmp');

sh.exec('npm i angular-cli -g -C ' + process.cwd(), { silent: true });
expect(fs.existsSync(path.join(process.cwd(), 'bin', 'ng')));
});
});
Expand All @@ -40,7 +39,9 @@ describe('Basic end-to-end Workflow', function () {
});

it('Can change current working directory to `test-project`', function() {
this.timeout(300000);
process.chdir(path.join(root, 'test-project'));
sh.exec('npm link angular-cli', {silent: true});
expect(path.basename(process.cwd())).to.equal('test-project');
});

Expand Down