Skip to content

Commit 94c9746

Browse files
committed
fix(tests): link package in e2e tests
Close #194
1 parent ecd2cf1 commit 94c9746

File tree

6 files changed

+67
-63
lines changed

6 files changed

+67
-63
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ before_install:
1010
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.30.1/install.sh | bash; fi
1111
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then source ~/.nvm/nvm-exec; fi
1212
- nvm install $NODE_VERSION
13-
- npm link npm
1413
- npm config set spin false
1514
install:
1615
- node --version

addon/ng2/tasks/lib-install.js

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

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

21-
init: function() {
22-
this.npm = this.npm || require('npm');
23-
},
2421
run: function(options) {
2522
this.packages = options.packages || [];
2623
this.skipInjection = options.skipInjection || false;
2724
this.autoInjection = options.autoInjection || false;
2825
this.disableLogger();
2926

30-
this.ui.startProgress(chalk.green('Installing 3rd party package:',
27+
this.ui.startProgress(chalk.green('Installing 3rd party package:',
3128
this.packages.join(', ')), chalk.green('.'));
3229

33-
this.npmOptions = {
34-
logLevel: 'error',
35-
logstream: this.ui.outputStream,
36-
color: 'always',
37-
optional: true,
38-
'save-dev': true,
39-
'save-exact': !!options['save-exact']
40-
};
41-
42-
return npm('install', this.packages, this.npmOptions, this.npm)
43-
.then(function(npmresp) {
30+
this.npmOptions = ' --loglevel error --color always --optional --save-dev ' +
31+
'--save-exact ' + !!options['save-exact'];
32+
33+
var npmCommand = 'npm install ' + this.packages.join(' ') + this.npmOptions;
34+
35+
return shellPromise(npmCommand)
36+
.then(function (npmresp) {
37+
4438
if (this.skipInjection) {
4539
return this.announceOKCompletion();
4640
}
4741

4842
if (this.autoInjection) {
4943
var pkg = this.packages[0];
50-
44+
5145
if (existsSync(path.resolve(process.cwd(), 'src', 'app.ts'))) {
5246
var entryPoint = path.resolve(process.cwd(), 'src', 'app.ts');
5347
var packageData = this.parseFile(pkg);
@@ -57,10 +51,10 @@ module.exports = Task.extend({
5751
return this.announceOKCompletion();
5852
}
5953

60-
return this.installProcedure()
61-
.then(function(resp) {
62-
return this.announceOKCompletion();
63-
}.bind(this));
54+
return this.installProcedure();
55+
}.bind(this))
56+
.then(function(resp) {
57+
return this.announceOKCompletion();
6458
}.bind(this));
6559
},
6660

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

86-
return npm('uninstall', allPackages.toUninstall, this.npmOptions, this.npm)
80+
var npmCommand = 'npm uninstall ' + allPackages.toUninstall.join(' ') + this.npmOptions;
81+
82+
return shellPromise(npmCommand)
8783
.then(function() {
8884
return this.processPackages(allPackages.toProcess)
89-
.then(function(resp) {
90-
return resolve(resp);
91-
});
85+
.then(function(resp) {
86+
return resolve(resp);
87+
});
9288
}.bind(this));
9389
}
9490
else {
@@ -133,7 +129,7 @@ module.exports = Task.extend({
133129
return new Promise(function(resolve, reject) {
134130
var packageData;
135131

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

139135
return this.ui.prompt({
@@ -226,7 +222,7 @@ module.exports = Task.extend({
226222
type: 'input',
227223
name: 'sel',
228224
message: msg,
229-
filter: function (val) { return val.trim(); },
225+
filter: function (val) { return val.trim(); },
230226
validate: function(value) {
231227
return value > 0 && value <= packageData[componentKey].length ? true : 'Enter a valid value';
232228
}
@@ -260,8 +256,8 @@ module.exports = Task.extend({
260256
packageName,
261257
packageData[componentKey][componentIndex]);
262258

263-
this.injectItem(componentKey.toLowerCase(),
264-
packageData[componentKey][componentIndex],
259+
this.injectItem(componentKey.toLowerCase(),
260+
packageData[componentKey][componentIndex],
265261
possibleFiles[fileIndex]);
266262

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

337333
if (removeNextLine) {
338334
arr.splice(index, 1);
339-
if (/;/.test(line)) {
340-
removeNextLine = false;
335+
if (/;/.test(line)) {
336+
removeNextLine = false;
341337
}
342338
}
343339
});
@@ -348,12 +344,12 @@ module.exports = Task.extend({
348344
function generateFlatImportLine(arr, fromIndex) {
349345
var lineArr = [];
350346
var lastIndex;
351-
347+
352348
arr.forEach(function(line, index) {
353349
if (index >= fromIndex && !lastIndex) {
354350
lineArr.push(line);
355-
if (/;/.test(line)) {
356-
lastIndex = true;
351+
if (/;/.test(line)) {
352+
lastIndex = true;
357353
}
358354
}
359355
});
@@ -443,7 +439,7 @@ module.exports = Task.extend({
443439

444440
if (/\)/.test(line)) {
445441
replace = line.match(/\((.*?)\)/)[0];
446-
}
442+
}
447443
else {
448444
replace = contentsArr.splice(index, contentsArr.length - 1).join('\n').replace(/\n/g, '');
449445
replace = replace.match(/\((.*?)\)/)[0];
@@ -495,7 +491,7 @@ module.exports = Task.extend({
495491
match = match.replace(/[\[\]]/g, '');
496492
match = match.split(',');
497493
match.push(name);
498-
match = match.filter(function(n) { return n !== ''; } );
494+
match = match.filter(function(n) { return n !== ''; } );
499495
contentsArr[index] = contentsArr[index].replace(replace, '[' + match.join(',') + ']');
500496
}
501497
}.bind(this));
@@ -505,14 +501,14 @@ module.exports = Task.extend({
505501

506502
parseFile: function (packageName) {
507503
var packagePath = path.join(process.cwd(), 'node_modules', packageName, packageName + '.ts');
508-
504+
509505
if (!existsSync(packagePath)) {
510506
return false;
511507
}
512508

513509
var contents = fs.readFileSync(packagePath, 'utf8');
514510
var data = {};
515-
511+
516512
data.Component = [];
517513
data.Directive = [];
518514
data.Pipe = [];

addon/ng2/tasks/lib-uninstall.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

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

22-
init: function() {
23-
this.npm = this.npm || require('npm');
24-
},
2522
run: function(options) {
2623
this.packages = options.packages || [];
2724
this.autoRemove = options.autoRemove || false;
2825
this.disableLogger();
2926

30-
this.ui.startProgress(chalk.green('Uninstalling 3rd party package:',
27+
this.ui.startProgress(chalk.green('Uninstalling 3rd party package:',
3128
this.packages.join(', ')), chalk.green('.'));
3229

33-
this.npmOptions = {
34-
logLevel: 'error',
35-
logstream: this.ui.outputStream,
36-
color: 'always',
37-
optional: true,
38-
'save-dev': true,
39-
'save-exact': !!options['save-exact']
40-
};
41-
4230
this.getPackagesDataBeforeRemoved(this.packages);
4331

44-
return npm('uninstall', this.packages, this.npmOptions, this.npm)
32+
this.npmOptions = ' --loglevel error --color always --optional --save-dev ' +
33+
'--save-exact ' + !!options['save-exact'];
34+
35+
var npmCommand = 'npm uninstall ' + this.packages.join(' ') + this.npmOptions;
36+
37+
return shellPromise(npmCommand)
4538
.then(function(npmresp) {
4639
if (!npmresp.length) {
4740
this.completionErrorMessage = 'No packages uninstalled.';
4841
return this.announceErrorCompletion();
49-
}
42+
}
5043
else {
5144
if (this.autoRemove) {
5245
this.removePackagesFromApp();
@@ -60,7 +53,6 @@ module.exports = Task.extend({
6053
}
6154
}
6255
}.bind(this));
63-
6456
},
6557

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

8779
parseFile: function (packageName) {
8880
var packagePath = path.resolve(process.cwd(), 'node_modules', packageName, packageName + '.ts');
89-
81+
9082
if (!existsSync(packagePath)) {
9183
return false;
9284
}
9385

9486
var contents = fs.readFileSync(packagePath, 'utf8');
9587
var data = {};
96-
88+
9789
data.Directive = [];
9890
data.Pipe = [];
9991
data.Provider = [];
@@ -170,7 +162,7 @@ module.exports = Task.extend({
170162
cleanAfterRemoval: function(contents) {
171163
var bootstrap = false;
172164

173-
contents = contents.filter(function(line) {
165+
contents = contents.filter(function(line) {
174166
if (/bootstrap\(/.test(line)) {
175167
bootstrap = true;
176168
}
@@ -227,4 +219,4 @@ module.exports = Task.extend({
227219
console.log = this.oldLog; // Hack, see above
228220
}
229221

230-
});
222+
});

addon/ng2/utilities/shell-promise.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* jshint node: true */
2+
'use strict';
3+
4+
var Promise = require('ember-cli/lib/ext/promise');
5+
var sh = require('shelljs');
6+
7+
module.exports = function shellPromise(command) {
8+
return new Promise(function(resolve, reject) {
9+
return sh.exec(command, {
10+
silent: true
11+
}, function(code, stdout, stderr) {
12+
if (code !== 0) reject(stderr);
13+
else resolve(stdout);
14+
});
15+
});
16+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"node-notifier": "^4.4.0",
4444
"resolve": "^1.0.0",
4545
"silent-error": "^1.0.0",
46+
"shelljs": "^0.5.3",
4647
"symlink-or-copy": "^1.0.1",
4748
"typescript": "~1.7.3",
4849
"typings": "^0.6.2"
@@ -60,7 +61,6 @@
6061
"minimatch": "^2.0.10",
6162
"mocha": "^2.2.5",
6263
"rewire": "^2.3.4",
63-
"shelljs": "^0.5.3",
6464
"through": "^2.3.8",
6565
"walk-sync": "^0.2.6"
6666
}

tests/e2e/e2e_workflow.spec.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ describe('Basic end-to-end Workflow', function () {
1818
it('Installs angular-cli correctly', function() {
1919
this.timeout(300000);
2020

21+
sh.exec('npm link', {silent: true});
2122
return tmp.setup('./tmp')
2223
.then(function () {
2324
process.chdir('./tmp');
24-
25-
sh.exec('npm i angular-cli -g -C ' + process.cwd(), { silent: true });
2625
expect(fs.existsSync(path.join(process.cwd(), 'bin', 'ng')));
2726
});
2827
});
@@ -40,7 +39,9 @@ describe('Basic end-to-end Workflow', function () {
4039
});
4140

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

0 commit comments

Comments
 (0)