Skip to content
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

fix: handle function toString node10 change #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion lib/containerHelpers/dependencyParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = function() {
var fnString = fn.toString();
var parameters = fnString
.replace( /\n/g, ' ' )
.match( /function\s+\w*\s*\((.*?)\)/ )[ 1 ].split( /\s*,\s*/ )
.match( /function\s?\w*\s*\((.*?)\)/ )[ 1 ].split( /\s*,\s*/ )
.map( function( parameterName ) { return parameterName.trim(); } )
.filter( function( parameterName ) { return parameterName.length > 0; } )
.map( function( parameterName ) {
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/lib/containerHelpers/dependencyParserUnitTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ describe( 'lib/dependencyParser', function() {
} );
} );
describe( 'getDependencies', function() {
describe( 'old node compatibility', function() {
it( 'function.toString() is different in node 10', function() {
// https://github.com/nodejs/node/issues/20355
var node9andBelowfunc = function () {};
node9andBelowfunc.toString = function() { return "function () {}"};
dependencyParser.getDependencies(node9andBelowfunc);

var node10andAbovefunc = function (){};
node10andAbovefunc.toString = function() { return "function() {}"};
dependencyParser.getDependencies(node10andAbovefunc);
} );
} );
describe( 'parameters', function() {
it( 'Should have the correct parameters', function() {
var dependencies = dependencyParser.getDependencies( function( callback, parentName, pub, setup, p1, p2 ) {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/lib/containerHelpers/storeUnitTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe( 'lib/containerHelpers/store', function() {
describe( 'getAllResolvingProblems()', function() {
it( 'Should return all resolving problems', function() {
var problems = store.getAllResolvingProblems().sort( function( problem1, problem2 ) {
return problem1 < problem2 ? 1 : -1;
return problem1 < problem2 ? -1 : 1;
} );
assert.deepEqual( problems, [
{ name: 'injectable1', errors: [
Expand Down