Skip to content

Commit 399dba5

Browse files
authored
Merge pull request #999 from bertdeblock/remove-use-of-core-object
Remove use of `core-object` for tasks
2 parents 4cc71fa + 819a6d5 commit 399dba5

4 files changed

Lines changed: 64 additions & 39 deletions

File tree

lib/commands/reset.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ module.exports = {
1010
let ResetTask = require('../tasks/reset');
1111

1212
let resetTask = new ResetTask({
13-
ui: this.ui,
1413
project: this.project,
1514
config,
1615
});

lib/tasks/reset.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
'use strict';
22

3-
const CoreObject = require('core-object');
43
const debug = require('debug')('ember-try:commands:reset');
54
const ScenarioManager = require('../utils/scenario-manager');
65
const DependencyManagerAdapterFactory = require('./../utils/dependency-manager-adapter-factory');
76

8-
module.exports = CoreObject.extend({
7+
module.exports = class ResetTask {
8+
constructor(options) {
9+
this.config = options.config;
10+
this.project = options.project;
11+
}
12+
913
run() {
10-
let dependencyAdapters =
11-
this.dependencyManagerAdapters ||
12-
DependencyManagerAdapterFactory.generateFromConfig(this.config, this.project.root);
14+
let dependencyAdapters = DependencyManagerAdapterFactory.generateFromConfig(
15+
this.config,
16+
this.project.root,
17+
);
1318
debug(
1419
'DependencyManagerAdapters: %s',
1520
dependencyAdapters.map((item) => {
1621
return item.configKey;
1722
}),
1823
);
1924
return new ScenarioManager({ dependencyManagerAdapters: dependencyAdapters }).cleanup();
20-
},
21-
});
25+
}
26+
};

lib/tasks/try-each.js

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
'use strict';
22

3-
const CoreObject = require('core-object');
43
const chalk = require('chalk');
54
const debug = require('debug')('ember-try:task:try-each');
65
const runCommand = require('./../utils/run-command');
76

8-
module.exports = CoreObject.extend({
7+
module.exports = class TryEachTask {
8+
constructor(options) {
9+
this.commandArgs = options.commandArgs;
10+
this.commandOptions = options.commandOptions;
11+
this.config = options.config;
12+
this.dependencyManagerAdapters = options.dependencyManagerAdapters;
13+
this.project = options.project;
14+
this.ui = options.ui;
15+
}
16+
917
async run(scenarios, options) {
1018
// Required lazily to improve startup speed.
1119
let ScenarioManager = require('./../utils/scenario-manager');
@@ -58,7 +66,7 @@ module.exports = CoreObject.extend({
5866

5967
return 1; // Signifies exit code
6068
}
61-
},
69+
}
6270

6371
async _runCommandForThisScenario(scenario) {
6472
if (this._canceling) {
@@ -98,18 +106,18 @@ module.exports = CoreObject.extend({
98106
this._writeFooter(`Result: ${result}`);
99107

100108
return runResults;
101-
},
109+
}
102110

103111
_writeHeader(text) {
104112
let count = 75 - text.length;
105113
let separator = new Array(count + 1).join('=');
106114
this.ui.writeLine(chalk.blue(`\n=== ${text} ${separator}\n`));
107-
},
115+
}
108116

109117
_writeFooter(text) {
110118
this.ui.writeLine(chalk.blue(`\n${text}`));
111119
this.ui.writeLine(chalk.blue('---\n'));
112-
},
120+
}
113121

114122
_determineCommandFor(scenario) {
115123
if (this.commandArgs && this.commandArgs.length) {
@@ -125,35 +133,35 @@ module.exports = CoreObject.extend({
125133
}
126134

127135
return this._defaultCommandArgs();
128-
},
136+
}
129137

130138
_runCommand(options) {
131139
return runCommand(this.project.root, options.commandArgs, options.commandOptions);
132-
},
140+
}
133141

134142
_commandOptions(env) {
135143
let options = this.commandOptions || {};
136144
if (env) {
137145
options.env = Object.assign({}, process.env, env);
138146
}
139147
return options;
140-
},
148+
}
141149

142150
_defaultCommandArgs() {
143151
return ['ember', 'test'];
144-
},
152+
}
145153

146154
_printResults(results) {
147155
new this.ResultSummary({ ui: this.ui, results }).print();
148-
},
156+
}
149157

150158
_exitAsAppropriate(results) {
151159
let outcomes = results.map((result) => {
152160
return result.result || result.allowedToFail;
153161
});
154162

155163
return this._exitBasedOnCondition(outcomes.indexOf(false) > -1);
156-
},
164+
}
157165

158166
async _optionallyCleanup(options) {
159167
debug('Cleanup');
@@ -166,20 +174,20 @@ module.exports = CoreObject.extend({
166174
debug('Cleanup ScenarioManager');
167175
return await this.ScenarioManager.cleanup();
168176
}
169-
},
177+
}
170178

171179
_exitBasedOnCondition(condition) {
172180
let exitCode = condition ? 1 : 0;
173181
debug('Exit %s', exitCode);
174182
return exitCode;
175-
},
183+
}
176184

177185
_exit(code) {
178186
debug('Exit %s', code);
179187
process.exit(code);
180-
},
188+
}
181189

182190
_on(signal, fn) {
183191
process.on(signal, fn);
184-
},
185-
});
192+
}
193+
};

test/tasks/try-each-test.js

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@ describe('tryEach', () => {
8989
ui: { writeLine: outputFn },
9090
project: { root: tmpdir },
9191
config,
92-
_on() {},
9392
});
9493

94+
tryEachTask._on = () => {};
95+
9596
writeJSONFile('package.json', fixturePackage);
9697
fs.writeFileSync('yarn.lock', '');
9798
fs.mkdirSync('node_modules');
@@ -143,9 +144,10 @@ describe('tryEach', () => {
143144
ui: { writeLine: outputFn },
144145
project: { root: tmpdir },
145146
config,
146-
_on() {},
147147
});
148148

149+
tryEachTask._on = () => {};
150+
149151
writeJSONFile('package.json', fixturePackage);
150152
fs.mkdirSync('node_modules');
151153
return tryEachTask.run(config.scenarios, {}).then((exitCode) => {
@@ -207,9 +209,10 @@ describe('tryEach', () => {
207209
project: { root: tmpdir },
208210
config,
209211
dependencyManagerAdapters: [],
210-
_on() {},
211212
});
212213

214+
tryEachTask._on = () => {};
215+
213216
let exitCode = await tryEachTask.run(config.scenarios, {});
214217

215218
expect(exitCode).to.equal(0, 'exits 0 when all scenarios succeed');
@@ -256,9 +259,10 @@ describe('tryEach', () => {
256259
commandArgs: ['ember', 'serve'],
257260
commandOptions: { timeout: { length: 20000, isSuccess: true } },
258261
dependencyManagerAdapters: [new StubDependencyAdapter()],
259-
_on() {},
260262
});
261263

264+
tryEachTask._on = () => {};
265+
262266
return tryEachTask.run(config.scenarios, {}).then((exitCode) => {
263267
expect(exitCode).to.equal(0, 'exits 0 when all scenarios succeed');
264268
expect(output).to.include('Scenario first: SUCCESS');
@@ -306,9 +310,10 @@ describe('tryEach', () => {
306310
project: { root: tmpdir },
307311
config,
308312
dependencyManagerAdapters: [new StubDependencyAdapter()],
309-
_on() {},
310313
});
311314

315+
tryEachTask._on = () => {};
316+
312317
return tryEachTask.run(config.scenarios, {}).then((exitCode) => {
313318
expect(output).to.include('Scenario first: FAIL (Allowed)');
314319
expect(output).to.include('Scenario second: FAIL (Allowed)');
@@ -355,9 +360,10 @@ describe('tryEach', () => {
355360
project: { root: tmpdir },
356361
config,
357362
dependencyManagerAdapters: [new StubDependencyAdapter()],
358-
_on() {},
359363
});
360364

365+
tryEachTask._on = () => {};
366+
361367
return tryEachTask.run(config.scenarios, {}).then((exitCode) => {
362368
expect(output).to.include('Scenario first: FAIL');
363369
expect(output).to.include('Scenario second: FAIL (Allowed)');
@@ -405,9 +411,10 @@ describe('tryEach', () => {
405411
project: { root: tmpdir },
406412
config,
407413
dependencyManagerAdapters: [new StubDependencyAdapter()],
408-
_on() {},
409414
});
410415

416+
tryEachTask._on = () => {};
417+
411418
return tryEachTask.run(config.scenarios, {}).then((exitCode) => {
412419
expect(output).to.include('Scenario first: SUCCESS');
413420
expect(output).to.include('Scenario second: SUCCESS');
@@ -460,9 +467,10 @@ describe('tryEach', () => {
460467
config,
461468
commandArgs: [],
462469
dependencyManagerAdapters: [new StubDependencyAdapter()],
463-
_on() {},
464470
});
465471

472+
tryEachTask._on = () => {};
473+
466474
return tryEachTask.run(config.scenarios, {}).then((exitCode) => {
467475
expect(exitCode).to.equal(0, 'exits 0 when all scenarios succeed');
468476
expect(output).to.include('Scenario first: SUCCESS');
@@ -506,9 +514,10 @@ describe('tryEach', () => {
506514
config,
507515
commandArgs: ['ember', 'serve'],
508516
dependencyManagerAdapters: [new StubDependencyAdapter()],
509-
_on() {},
510517
});
511518

519+
tryEachTask._on = () => {};
520+
512521
return tryEachTask.run(config.scenarios, {}).then((exitCode) => {
513522
expect(exitCode).to.equal(0, 'exits 0 when all scenarios succeed');
514523
expect(output).to.include('Scenario first: SUCCESS');
@@ -576,9 +585,10 @@ describe('tryEach', () => {
576585
project: { root: tmpdir },
577586
config,
578587
dependencyManagerAdapters: [new StubDependencyAdapter()],
579-
_on() {},
580588
});
581589

590+
tryEachTask._on = () => {};
591+
582592
return tryEachTask.run(config.scenarios, {}).then((exitCode) => {
583593
expect(exitCode).to.equal(0, 'exits 0 when all scenarios succeed');
584594

@@ -624,9 +634,10 @@ describe('tryEach', () => {
624634
config,
625635
commandArgs: ['ember', 'help', '--json', 'true'],
626636
dependencyManagerAdapters: [new StubDependencyAdapter()],
627-
_on() {},
628637
});
629638

639+
tryEachTask._on = () => {};
640+
630641
return tryEachTask.run(config.scenarios, {}).then((exitCode) => {
631642
expect(exitCode).to.equal(0, 'exits 0 when all scenarios succeed');
632643
expect(output).to.include(
@@ -677,9 +688,10 @@ describe('tryEach', () => {
677688
project: { root: tmpdir },
678689
config,
679690
dependencyManagerAdapters: [new StubDependencyAdapter()],
680-
_on() {},
681691
});
682692

693+
tryEachTask._on = () => {};
694+
683695
return tryEachTask.run(config.scenarios, {}).then((exitCode) => {
684696
expect(exitCode).to.equal(0, 'exits 0 when all scenarios succeed');
685697

@@ -730,10 +742,11 @@ describe('tryEach', () => {
730742
project: { root: tmpdir },
731743
config,
732744
dependencyManagerAdapters: [new StubDependencyAdapter()],
733-
_on() {},
734-
_runCommand: mockRunCommand,
735745
});
736746

747+
tryEachTask._on = () => {};
748+
tryEachTask._runCommand = mockRunCommand;
749+
737750
return tryEachTask.run(config.scenarios, {}).then((exitCode) => {
738751
expect(exitCode).to.equal(0, 'exits 0 when all scenarios succeed');
739752
expect(scenarios).to.eql(['first']);

0 commit comments

Comments
 (0)