Skip to content

Commit

Permalink
Fix for ember-cli 4.9+
Browse files Browse the repository at this point in the history
The Watcher API changed in ember-cli 4.9, so we need some compat code
  • Loading branch information
bendemboski committed Jan 28, 2023
1 parent 6e7e940 commit 0d6bd6d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 27 deletions.
27 changes: 21 additions & 6 deletions lib/tasks/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,27 @@ class ElectronTask extends Task {

ui.writeLine(`Environment: ${options.environment}`);

let watcher = new Watcher({
ui,
builder,
analytics: this.analytics,
options,
});
let watcher;
// The watcher API changed in ember-cli@4.9, so we need some compat code
if (Watcher.build) {
// ember-cli >= 4.9
watcher = (
await Watcher.build({
ui,
builder,
analytics: this.analytics,
options,
})
).watcher;
} else {
// ember-cli < 4.9
watcher = new Watcher({
ui,
builder,
analytics: this.analytics,
options,
});
}

let expressServer = new ExpressServer({
ui: this.ui,
Expand Down
32 changes: 11 additions & 21 deletions node-tests/integration/commands/electron-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,36 +34,36 @@ describe('electron command', function () {

let command;

let mockBrocBuilder;
let mockBrocWatcher;
let mockProcess;

let createBuilderStub;
let cleanupBuilderStub;
let createWatcherStub;
let startServerStub;

let buildOutputPath;
let buildEnvironment;

let emitExitStub;

beforeEach(function () {
processArgv = Array.from(process.argv);

mockBrocBuilder = {};
mockBrocWatcher = new MockWatcher();
mockProcess = new MockProcess();

emitExitStub = sinon.stub();

createBuilderStub = sinon
.stub(Builder.prototype, 'setupBroccoliBuilder')
.callsFake(function () {
this.builder = mockBrocBuilder;
});
sinon.stub(Builder.prototype, 'build').resolves();
cleanupBuilderStub = sinon.stub(Builder.prototype, 'cleanup').resolves();
createWatcherStub = sinon
.stub(Watcher.prototype, 'constructBroccoliWatcher')
.returns(mockBrocWatcher);
.callsFake(function () {
// pull values off of builder
buildOutputPath = this.builder.outputPath;
buildEnvironment = this.builder.environment;
return Promise.resolve(mockBrocWatcher);
});
startServerStub = sinon.stub(ExpressServer.prototype, 'start').resolves();
sinon.stub(api, 'start').callsFake(() => {
// make electron process exit right after start promise resolves
Expand Down Expand Up @@ -103,7 +103,6 @@ describe('electron command', function () {

it('works', async function () {
await expect(command.validateAndRun([])).to.be.fulfilled;
expect(createBuilderStub).to.be.calledOnce;
expect(createWatcherStub).to.be.calledOnce;
expect(mockBrocWatcher.currentBuild.then).to.be.calledOnce;
expect(startServerStub).to.be.calledOnce;
Expand Down Expand Up @@ -131,19 +130,10 @@ describe('electron command', function () {
});

it('sets the build output path and environment', async function () {
let outputPath;
let environment;
createBuilderStub.resetBehavior();
createBuilderStub.callsFake(function () {
// pull values off of builder
outputPath = this.outputPath;
environment = this.environment;
});

await expect(command.validateAndRun(['--environment', 'testing'])).to.be
.fulfilled;
expect(outputPath).to.equal(path.join('electron-app', 'ember-dist'));
expect(environment).to.equal('testing');
expect(buildOutputPath).to.equal(path.join('electron-app', 'ember-dist'));
expect(buildEnvironment).to.equal('testing');
});

it('sets up the live reload server with defaults', async function () {
Expand Down

0 comments on commit 0d6bd6d

Please sign in to comment.