Skip to content

feat: set error file path into error message #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
sudo: false
language: node_js
node_js:
- '6'
- '4'
- '3'
- '2'
- '1'
script: "make test-travis"
after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ proto._load = function (target, field, options) {
}

var names = properties.join('.');
var mod = interopRequire(item.fullpath);
var mod;
try {
mod = interopRequire(item.fullpath);
} catch (err) {
err.message = '[loading] load file: ' + item.fullpath + ', error: ' + err.message;
throw err;
}
// if exist initializer function, run it;
if (initializer) {
mod = initializer(mod);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"jshint": "*",
"mocha": "*",
"pedding": "1",
"should": "4"
"should": "9"
},
"files": [
"index.js",
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/syntax_error/error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
modulde.exports = function (a) {
yield a;
}
14 changes: 12 additions & 2 deletions test/loading.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('loading.test.js', function () {
.into(app, 'proxyClasses');
(function() {
app.proxyClasses.UserProxy();
}).should.throw('Class constructors cannot be invoked without \'new\'');
}).should.throw(/cannot be invoked without 'new'/);
var instance = new app.proxyClasses.UserProxy();
instance.getUser().should.eql({ name: 'xiaochen.gaoxc' });
});
Expand Down Expand Up @@ -154,7 +154,9 @@ describe('loading.test.js', function () {
return new exports(app);
}
});
app.dao.should.have.property('TestClass', {user: { name: 'kai.fangk'}});
app.dao.should.have.property('TestClass');
app.dao.TestClass.user.should.eql({ name: 'kai.fangk'});
// app.dao.should.have.property('TestClass', {user: { name: 'kai.fangk'}});
app.dao.should.have.property('testFunction', {user: { name: 'kai.fangk'}});
app.dao.should.have.property('testReturnFunction', {user: { name: 'kai.fangk'}});
});
Expand All @@ -166,6 +168,14 @@ describe('loading.test.js', function () {
app.model.mod.should.eql({ a: 1 });
});

it('should contain syntax error filepath', function() {
var app = {};
var fixtures = path.join(__dirname, './fixtures/syntax_error');
(function () {
loading(fixtures).into(app, 'model');
}).should.throw(/\[loading\] load file: .*?test\/fixtures\/syntax_error\/error\.js, error:/);
});

// feature detection
function supportEs6Class() {
'use strict';
Expand Down