diff --git a/src/app/oauth-signature.js b/src/app/oauth-signature.js index 02ca156..ae3181b 100644 --- a/src/app/oauth-signature.js +++ b/src/app/oauth-signature.js @@ -1,9 +1,9 @@ ;(function() { 'use strict'; - - // In node there is no global Window object - var isNode = (typeof window === 'undefined'); - + + // Check the existence of module and module.exports to detect node + var isNode = (typeof module != 'undefined' && typeof module.exports != 'undefined'); + function OAuthSignature() { } @@ -277,4 +277,4 @@ } else { window.oauthSignature = oauthSignature; } -})(); \ No newline at end of file +})(); diff --git a/src/app/oauth-signature.tests.js b/src/app/oauth-signature.tests.js index 12d7194..b0993f0 100644 --- a/src/app/oauth-signature.tests.js +++ b/src/app/oauth-signature.tests.js @@ -469,4 +469,12 @@ test('Produces the expected decoded signature when optional token not provided', 'The generated GET signature should match the expected RFC 3986 encoded signature by default'); assert.equal(unencodedSignature, expectedDecodedSignature, 'The generated unencoded GET signature should match the expected unencoded signature'); +}); + +suite('Node or Browser Detection'); +test('Node or Browser properly detected', function () { + var oldIsNode = (typeof window === 'undefined'); + var newIsNode = (typeof module != 'undefined' && typeof module.exports != 'undefined'); + assert.equal(oldIsNode, newIsNode, + 'Both methods of detection should produce the same value'); }); \ No newline at end of file