Skip to content

Commit

Permalink
Run compilation sync so that brunch does not read the output too soon
Browse files Browse the repository at this point in the history
I think this fixes madsflensted#6
  • Loading branch information
joakimk committed Feb 9, 2016
1 parent 03d4811 commit 398ec08
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@

var command = 'elm make --yes --output ' + outputFile + ' ' + srcFile;

childProcess.exec(command, { cwd: elmFolder }, function (error, stdout, stderr) {
return callback(error, error ? stderr : '');
});
try {
childProcess.execSync(command, { cwd: elmFolder })
callback(null, "");
} catch (error) {
callback(error, "");
}
};
}).call(this);
24 changes: 12 additions & 12 deletions test/index_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var chai = require('chai')
chai.use(sinonChai);

var ElmCompiler = require('../index')
, exec;
, execSync;

describe('ElmCompiler', function (){
var elmCompiler, baseConfig = {
Expand Down Expand Up @@ -137,15 +137,15 @@ describe('ElmCompiler', function (){
, sampleConfig;

beforeEach(function () {
exec = sinon.stub(childProcess, 'exec');
execSync = sinon.stub(childProcess, 'execSync');

sampleConfig = JSON.parse(JSON.stringify(baseConfig));
sampleConfig.plugins.elmBrunch.outputFolder = 'test/output/folder';
sampleConfig.plugins.elmBrunch.mainModules = ['Test.elm'];
});

afterEach(function () {
exec.restore();
execSync.restore();
});

describe('when an elm folder has not been given', function () {
Expand All @@ -164,7 +164,7 @@ describe('ElmCompiler', function (){
expect(error).to.not.be.ok;
});
expected = 'elm make --yes --output test/output/folder/test.js Test.elm';
expect(childProcess.exec).to.have.been.calledWith(expected, {cwd: null});
expect(childProcess.execSync).to.have.been.calledWith(expected, {cwd: null});
});
});

Expand All @@ -184,7 +184,7 @@ describe('ElmCompiler', function (){
expect(error).to.not.be.ok;
});
expected = 'elm make --yes --output test/output/folder/test.js Test.elm';
expect(childProcess.exec).to.have.been.calledWith(expected, {cwd: 'test/elm/folder'});
expect(childProcess.execSync).to.have.been.calledWith(expected, {cwd: 'test/elm/folder'});
});

it('normalises the brunch file path to the elmFolder path', function () {
Expand All @@ -193,7 +193,7 @@ describe('ElmCompiler', function (){
expect(error).to.not.be.ok;
});
expected = 'elm make --yes --output test/output/folder/test.js Test.elm';
expect(childProcess.exec).to.have.been.calledWith(expected, {cwd: 'test/elm/folder'});
expect(childProcess.execSync).to.have.been.calledWith(expected, {cwd: 'test/elm/folder'});
});
});

Expand All @@ -211,7 +211,7 @@ describe('ElmCompiler', function (){
expect(data).to.equal('');
});
expected = '';
expect(childProcess.exec).to.not.have.been.called;
expect(childProcess.execSync).to.not.have.been.called;
});

it('should compile main modules', function () {
Expand All @@ -220,7 +220,7 @@ describe('ElmCompiler', function (){
expect(error).to.not.be.ok;
});
expected = 'elm make --yes --output test/output/folder/test.js Test.elm';
expect(childProcess.exec).to.have.been.calledWith(expected, {cwd: null});
expect(childProcess.execSync).to.have.been.calledWith(expected, {cwd: null});
});

it('should compile dependencies together with main modules', function () {
Expand All @@ -234,7 +234,7 @@ describe('ElmCompiler', function (){
});

expected = 'elm make --yes --output test/output/folder/test.js Test.elm Dep1.elm Dep2.elm';
expect(childProcess.exec).to.have.been.calledWith(expected, {cwd: null});
expect(childProcess.execSync).to.have.been.calledWith(expected, {cwd: null});
});

it('should compile a main module when a dependency is given', function () {
Expand All @@ -249,13 +249,13 @@ describe('ElmCompiler', function (){
elmCompiler.compile(content, 'Dep2.elm', function(error) {
expect(error).to.not.be.ok;
});
expect(childProcess.exec).not.to.have.been.called
expect(childProcess.execSync).not.to.have.been.called

elmCompiler.compile(content, 'Dep2.elm', function(error) {
expect(error).to.not.be.ok;
});
expected = 'elm make --yes --output test/output/folder/test.js Test.elm Dep1.elm Dep2.elm';
expect(childProcess.exec).to.have.been.calledWith(expected, {cwd: null});
expect(childProcess.execSync).to.have.been.calledWith(expected, {cwd: null});
});
});

Expand All @@ -272,7 +272,7 @@ describe('ElmCompiler', function (){
expect(error).to.not.be.ok;
});
expected = 'elm make --yes --output test/output/folder/test.js Test.elm';
expect(childProcess.exec).to.have.been.calledWith(expected, {cwd: null});
expect(childProcess.execSync).to.have.been.calledWith(expected, {cwd: null});
});
});
});
Expand Down

0 comments on commit 398ec08

Please sign in to comment.