Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Commit

Permalink
Breaking: ChildCompiler now resolve with compilation object even comp…
Browse files Browse the repository at this point in the history
…ilation errors occurs
  • Loading branch information
kisenka committed Oct 10, 2016
1 parent 2c166df commit a31de18
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
8 changes: 1 addition & 7 deletions lib/ChildCompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,7 @@ ChildCompiler.prototype.run = function () {

return new Promise(function (resolve, reject) {
compiler.runAsChild(function (err, entries, compilation) {
if (err) {
return reject(err);
} else {
return compilation.errors.length > 0
? reject(compilation)
: resolve(compilation)
}
return err ? reject(err) : resolve(compilation);
});
});
};
Expand Down
25 changes: 19 additions & 6 deletions test/ChildCompiler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var createCompilation = require('../lib/createCompilation');
var Compiler = require('../lib/ChildCompiler');
var InMemoryCompiler = require('../lib/InMemoryCompiler');
var MemoryFS = require('memory-fs');
var Promise = require('bluebird');

describe('ChildCompiler', () => {
it('should export static fields', () => {
Expand Down Expand Up @@ -49,15 +50,27 @@ describe('ChildCompiler', () => {
.and.have.a.property('then').that.is.a('function');
});

it('should reject if something wrong', () => {
var compiler = new Compiler(createCompilation());
compiler.addEntry('qwe');
return compiler.run().should.rejectedWith(/Entry module not found/)
it('should reject with error if fatal error occurs', () => {
// How make a fatal error?
// TODO
});

it('should resolve with compilation object', () => {
it('should anyway resolve with compilation object even if compilation errors occurs', () => {
var compiler = new Compiler(createCompilation());
return compiler.run().should.eventually.be.instanceOf(Compilation)
var compilerWithError = new Compiler(createCompilation());
compilerWithError.addEntry('qwe');

return Promise.all([
compiler.run()
.should.be.fulfilled
.and.eventually.be.instanceOf(Compilation)
.and.have.a.property('errors').that.lengthOf(0),

compilerWithError.run()
.should.be.fulfilled
.and.eventually.be.instanceOf(Compilation)
.and.have.a.property('errors').that.lengthOf(1)
]);
});
});

Expand Down

0 comments on commit a31de18

Please sign in to comment.