Skip to content

Commit 227ab3c

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

File tree

5 files changed

+95
-92
lines changed

5 files changed

+95
-92
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: 59 additions & 53 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 sh = require('shelljs');
77
var existsSync = require('exists-sync');
88
var chalk = require('chalk');
99
var path = require('path');
@@ -18,50 +18,49 @@ 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) {
44-
if (this.skipInjection) {
45-
return this.announceOKCompletion();
46-
}
30+
this.npmOptions = ' --loglevel error --color always --optional --save-dev ' +
31+
'--save-exact ' + !!options['save-exact'];
4732

48-
if (this.autoInjection) {
49-
var pkg = this.packages[0];
50-
51-
if (existsSync(path.resolve(process.cwd(), 'src', 'app.ts'))) {
52-
var entryPoint = path.resolve(process.cwd(), 'src', 'app.ts');
53-
var packageData = this.parseFile(pkg);
54-
this.importInBootstrap(entryPoint, pkg, packageData);
55-
}
33+
var npmCommand = 'npm install ' + this.packages.join(' ') + this.npmOptions;
34+
35+
return new Promise(function (resolve, reject){
36+
return sh.exec(npmCommand, {silent: true}, function(code, stdout, stderr) {
37+
if (code !== 0) reject();
38+
else resolve(stdout);
39+
});
40+
})
41+
.then(function (npmresp) {
42+
43+
if (this.skipInjection) {
44+
return this.announceOKCompletion();
45+
}
5646

57-
return this.announceOKCompletion();
47+
if (this.autoInjection) {
48+
var pkg = this.packages[0];
49+
50+
if (existsSync(path.resolve(process.cwd(), 'src', 'app.ts'))) {
51+
var entryPoint = path.resolve(process.cwd(), 'src', 'app.ts');
52+
var packageData = this.parseFile(pkg);
53+
this.importInBootstrap(entryPoint, pkg, packageData);
5854
}
5955

60-
return this.installProcedure()
61-
.then(function(resp) {
62-
return this.announceOKCompletion();
63-
}.bind(this));
64-
}.bind(this));
56+
return this.announceOKCompletion();
57+
}
58+
59+
return this.installProcedure();
60+
}.bind(this))
61+
.then(function(resp) {
62+
return this.announceOKCompletion();
63+
}.bind(this));
6564
},
6665

6766
installProcedure: function() {
@@ -83,13 +82,20 @@ module.exports = Task.extend({
8382
'as authentic: ' + allPackages.toUninstall.join(', ');
8483
this.ui.writeLine(chalk.yellow(msg));
8584

86-
return npm('uninstall', allPackages.toUninstall, this.npmOptions, this.npm)
87-
.then(function() {
88-
return this.processPackages(allPackages.toProcess)
89-
.then(function(resp) {
90-
return resolve(resp);
91-
});
92-
}.bind(this));
85+
var npmCommand = 'npm uninstall ' + allPackages.toUninstall.join(' ') + this.npmOptions;
86+
87+
return new Promise(function (resolve, reject){
88+
return sh.exec(npmCommand, {silent: true}, function(code, stdout, stderr) {
89+
if (code !== 0) reject();
90+
else resolve(stdout);
91+
});
92+
})
93+
.then(function() {
94+
return this.processPackages(allPackages.toProcess)
95+
.then(function(resp) {
96+
return resolve(resp);
97+
});
98+
}.bind(this));
9399
}
94100
else {
95101
return this.processPackages(allPackages.toProcess)
@@ -133,7 +139,7 @@ module.exports = Task.extend({
133139
return new Promise(function(resolve, reject) {
134140
var packageData;
135141

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

139145
return this.ui.prompt({
@@ -226,7 +232,7 @@ module.exports = Task.extend({
226232
type: 'input',
227233
name: 'sel',
228234
message: msg,
229-
filter: function (val) { return val.trim(); },
235+
filter: function (val) { return val.trim(); },
230236
validate: function(value) {
231237
return value > 0 && value <= packageData[componentKey].length ? true : 'Enter a valid value';
232238
}
@@ -260,8 +266,8 @@ module.exports = Task.extend({
260266
packageName,
261267
packageData[componentKey][componentIndex]);
262268

263-
this.injectItem(componentKey.toLowerCase(),
264-
packageData[componentKey][componentIndex],
269+
this.injectItem(componentKey.toLowerCase(),
270+
packageData[componentKey][componentIndex],
265271
possibleFiles[fileIndex]);
266272

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

337343
if (removeNextLine) {
338344
arr.splice(index, 1);
339-
if (/;/.test(line)) {
340-
removeNextLine = false;
345+
if (/;/.test(line)) {
346+
removeNextLine = false;
341347
}
342348
}
343349
});
@@ -348,12 +354,12 @@ module.exports = Task.extend({
348354
function generateFlatImportLine(arr, fromIndex) {
349355
var lineArr = [];
350356
var lastIndex;
351-
357+
352358
arr.forEach(function(line, index) {
353359
if (index >= fromIndex && !lastIndex) {
354360
lineArr.push(line);
355-
if (/;/.test(line)) {
356-
lastIndex = true;
361+
if (/;/.test(line)) {
362+
lastIndex = true;
357363
}
358364
}
359365
});
@@ -443,7 +449,7 @@ module.exports = Task.extend({
443449

444450
if (/\)/.test(line)) {
445451
replace = line.match(/\((.*?)\)/)[0];
446-
}
452+
}
447453
else {
448454
replace = contentsArr.splice(index, contentsArr.length - 1).join('\n').replace(/\n/g, '');
449455
replace = replace.match(/\((.*?)\)/)[0];
@@ -495,7 +501,7 @@ module.exports = Task.extend({
495501
match = match.replace(/[\[\]]/g, '');
496502
match = match.split(',');
497503
match.push(name);
498-
match = match.filter(function(n) { return n !== ''; } );
504+
match = match.filter(function(n) { return n !== ''; } );
499505
contentsArr[index] = contentsArr[index].replace(replace, '[' + match.join(',') + ']');
500506
}
501507
}.bind(this));
@@ -505,14 +511,14 @@ module.exports = Task.extend({
505511

506512
parseFile: function (packageName) {
507513
var packagePath = path.join(process.cwd(), 'node_modules', packageName, packageName + '.ts');
508-
514+
509515
if (!existsSync(packagePath)) {
510516
return false;
511517
}
512518

513519
var contents = fs.readFileSync(packagePath, 'utf8');
514520
var data = {};
515-
521+
516522
data.Component = [];
517523
data.Directive = [];
518524
data.Pipe = [];

addon/ng2/tasks/lib-uninstall.js

Lines changed: 32 additions & 35 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 sh = require('shelljs');
77
var existsSync = require('exists-sync');
88
var chalk = require('chalk');
99
var path = require('path');
@@ -19,48 +19,45 @@ 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)
45-
.then(function(npmresp) {
46-
if (!npmresp.length) {
47-
this.completionErrorMessage = 'No packages uninstalled.';
48-
return this.announceErrorCompletion();
49-
}
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 new Promise(function (resolve, reject){
38+
return sh.exec(npmCommand, {silent: true}, function(code, stdout, stderr) {
39+
if (code !== 0) reject();
40+
else resolve(stdout);
41+
});
42+
})
43+
.then(function(npmresp) {
44+
if (!npmresp.length) {
45+
this.completionErrorMessage = 'No packages uninstalled.';
46+
return this.announceErrorCompletion();
47+
}
48+
else {
49+
if (this.autoRemove) {
50+
this.removePackagesFromApp();
51+
return this.announceOKCompletion();
52+
}
5053
else {
51-
if (this.autoRemove) {
52-
this.removePackagesFromApp();
54+
return this.uninstallProcedure()
55+
.then(function(resp) {
5356
return this.announceOKCompletion();
54-
}
55-
else {
56-
return this.uninstallProcedure()
57-
.then(function(resp) {
58-
return this.announceOKCompletion();
59-
}.bind(this));
60-
}
57+
}.bind(this));
6158
}
62-
}.bind(this));
63-
59+
}
60+
}.bind(this));
6461
},
6562

6663
uninstallProcedure: function() {
@@ -86,14 +83,14 @@ module.exports = Task.extend({
8683

8784
parseFile: function (packageName) {
8885
var packagePath = path.resolve(process.cwd(), 'node_modules', packageName, packageName + '.ts');
89-
86+
9087
if (!existsSync(packagePath)) {
9188
return false;
9289
}
9390

9491
var contents = fs.readFileSync(packagePath, 'utf8');
9592
var data = {};
96-
93+
9794
data.Directive = [];
9895
data.Pipe = [];
9996
data.Provider = [];
@@ -170,7 +167,7 @@ module.exports = Task.extend({
170167
cleanAfterRemoval: function(contents) {
171168
var bootstrap = false;
172169

173-
contents = contents.filter(function(line) {
170+
contents = contents.filter(function(line) {
174171
if (/bootstrap\(/.test(line)) {
175172
bootstrap = true;
176173
}
@@ -227,4 +224,4 @@ module.exports = Task.extend({
227224
console.log = this.oldLog; // Hack, see above
228225
}
229226

230-
});
227+
});

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)