Skip to content

Commit 2a1d702

Browse files
committed
refactor(gen:test): runCmd returns a Promise instead of taking a callback
1 parent babb03f commit 2a1d702

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

Diff for: src/test/main.test.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,20 @@ describe('angular-fullstack:app', function() {
108108
return assertOnlyFiles(expectedFiles, path.normalize(dir)).should.eventually.be.fulfilled;
109109
});
110110

111-
it('passes JSCS', function(done) {
112-
runCmd('grunt jscs', done);
111+
it('passes JSCS', function() {
112+
return runCmd('grunt jscs').should.be.fulfilled();
113113
});
114114

115-
it('passes JSHint', function(done) {
116-
runCmd('grunt jshint', done);
115+
it('passes JSHint', function() {
116+
return runCmd('grunt jshint').should.be.fulfilled();
117117
});
118118

119-
it('passes client tests', function(done) {
120-
runCmd('grunt test:client', done);
119+
it('passes client tests', function() {
120+
return runCmd('grunt test:client').should.be.fulfilled();
121121
});
122122

123-
it('passes server tests', function(done) {
124-
runCmd('grunt test:server', done);
123+
it('passes server tests', function() {
124+
return runCmd('grunt test:server').should.be.fulfilled();
125125
});
126126

127127
describe('with a generated endpont', function() {
@@ -135,8 +135,8 @@ describe('angular-fullstack:app', function() {
135135

136136
it('should pass lint');
137137

138-
it('should run server tests successfully', function(done) {
139-
runCmd('grunt test:server', done);
138+
it('should run server tests successfully', function() {
139+
return runCmd('grunt test:server').should.be.fulfilled();
140140
});
141141
});
142142

@@ -151,8 +151,8 @@ describe('angular-fullstack:app', function() {
151151

152152
it('should pass lint');
153153

154-
it('should run server tests successfully', function(done) {
155-
runCmd('grunt test:server', done);
154+
it('should run server tests successfully', function() {
155+
return runCmd('grunt test:server').should.be.fulfilled();
156156
});
157157
});
158158

@@ -167,8 +167,8 @@ describe('angular-fullstack:app', function() {
167167

168168
it('should pass lint');
169169

170-
it('should run server tests successfully', function(done) {
171-
runCmd('grunt test:server', done);
170+
it('should run server tests successfully', function() {
171+
return runCmd('grunt test:server').should.be.fulfilled();
172172
});
173173
});
174174

Diff for: src/test/test-helpers.js

+12-11
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,19 @@ export function copyAsync(src, dest) {
2323
/**
2424
* Run the given command in a child process
2525
* @param {string} cmd - command to run
26-
* @param {doneCallback} done
26+
* @returns {Promise}
2727
*/
28-
export function runCmd(cmd, done) {
29-
exec(cmd, {}, function(err, stdout, stderr) {
30-
if(err) {
31-
console.error(stdout);
32-
throw new Error(`Error running command: ${cmd}`);
33-
done(err);
34-
} else {
35-
if(DEBUG) console.log(stdout);
36-
done();
37-
}
28+
export function runCmd(cmd) {
29+
return new Promise((resolve, reject) => {
30+
exec(cmd, {}, function(err, stdout, stderr) {
31+
if(err) {
32+
console.error(stdout);
33+
return reject(err);
34+
} else {
35+
if(DEBUG) console.log(`${cmd} stdout: ${stdout}`);
36+
return resolve();
37+
}
38+
});
3839
});
3940
}
4041

0 commit comments

Comments
 (0)