Skip to content

Commit

Permalink
Auto merge of #5396 - ember-cli:pr-5315, r=stefanpenner
Browse files Browse the repository at this point in the history
Pr 5315
  • Loading branch information
homu committed Jan 27, 2016
2 parents 27fa058 + cc2bc3d commit e642886
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/utilities/find-build-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ module.exports = function(file) {

process.chdir(baseDir);

var buildFile = require(buildFilePath);
var buildFile = null;
try {
buildFile = require(buildFilePath);
} catch(err) {
err.message = 'Could not require \'' + file + '\': '+err.message;
throw err;
}

return buildFile;
};
44 changes: 44 additions & 0 deletions tests/unit/utilities/find-build-file-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use strict';

var expect = require('chai').expect;
var fs = require('fs-extra');
var tmp = require('../../helpers/tmp');
var findBuildFile = require('../../../lib/utilities/find-build-file');

describe('find-build-file', function() {
var tmpPath, tmpFilename, tmpFilePath;
var currentWorkingDir = process.cwd();

beforeEach(function() {
tmpPath = process.cwd()+'/tmp/';
tmpFilename = 'ember-cli-build.js';
tmpFilePath = tmpPath + tmpFilename;
return tmp.setup(tmpPath)
.then(function(){
process.chdir(tmpPath);
});
});

afterEach(function() {
delete require.cache[require.resolve(tmpFilePath)];
return tmp.teardown(tmpPath).then(function(){
process.chdir(currentWorkingDir);
});
});

it('does not throws an error when the file is valid syntax', function() {
fs.writeFileSync(tmpFilename, 'module.exports = function(){return {\'a\': \'A\', \'b\': \'B\'};}', { encoding: 'utf8' });

expect(function() {
findBuildFile(tmpFilename);
}).to.not.throw();
});

it('throws an SyntaxError if the file contains a syntax mistake', function(){
fs.writeFileSync(tmpFilename, 'module.exports = function(){return {\'a\': \'A\' \'b\': \'B\'};}', { encoding: 'utf8' });

expect(function() {
findBuildFile(tmpFilename);
}).to.throw(SyntaxError, /Could not require '.*':/);
});
});

0 comments on commit e642886

Please sign in to comment.