From 976961d1f096b01b2b1dec3966718bb0f2a76320 Mon Sep 17 00:00:00 2001 From: Scott Gress Date: Mon, 30 Jan 2017 11:44:55 -0600 Subject: [PATCH 1/2] Fix nesting test to work on Windows --- test/lowlvl-sync-usage.test.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/test/lowlvl-sync-usage.test.js b/test/lowlvl-sync-usage.test.js index 4bfc2ca..ff33d4b 100644 --- a/test/lowlvl-sync-usage.test.js +++ b/test/lowlvl-sync-usage.test.js @@ -129,7 +129,10 @@ describe('basic usage of synchronous, low-level function', function(){ keepDirectoryPath: true }); - assert.deepEqual(controllers, { + var nestKey = path.join('level1', 'level2', 'level3', 'nestedController'); + + var expected = { + 'main-Controller': { index: 1, show: 2, @@ -140,12 +143,13 @@ describe('basic usage of synchronous, low-level function', function(){ 'other-Controller': { index: 1, show: 'nothing' - }, - - 'level1/level2/level3/nestedController': { - nestingLevel: 3 } - }); + + }; + + expected[nestKey] = { nestingLevel: 3}; + + assert.deepEqual(controllers, expected); }); }); From 6d549857fc0018950c5951cd41a95e2f8ee15509 Mon Sep 17 00:00:00 2001 From: Tyler Waters Date: Fri, 8 Sep 2017 22:30:40 -0700 Subject: [PATCH 2/2] Map default export to module for es-module interoperability --- lib/help-include-all-sync.js | 4 ++- test/esmodules.test.js | 32 +++++++++++++++++++ test/fixtures/es-modules/module-default.js | 2 ++ .../es-modules/sub-dir/another-module.js | 2 ++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 test/esmodules.test.js create mode 100644 test/fixtures/es-modules/module-default.js create mode 100644 test/fixtures/es-modules/sub-dir/another-module.js diff --git a/lib/help-include-all-sync.js b/lib/help-include-all-sync.js index e928038..bdc0d9d 100644 --- a/lib/help-include-all-sync.js +++ b/lib/help-include-all-sync.js @@ -268,7 +268,9 @@ module.exports = function includeAll(options) { // Require the module. try { - _modules[keyName] = require(filepath); + var _module = require(filepath) + if (_module.default) { _module = _module.default } + _modules[keyName] = _module; } catch (e) { // Skip this module silently if `ignoreRequireFailures` is enabled. if (options.ignoreRequireFailures) { return; } diff --git a/test/esmodules.test.js b/test/esmodules.test.js new file mode 100644 index 0000000..cf71477 --- /dev/null +++ b/test/esmodules.test.js @@ -0,0 +1,32 @@ +/** + * Module dependencies + */ + +var assert = require('assert'); +var path = require('path'); +var loader = require('../'); + + + +describe('es modules, default is a default export', function(){ + + + it('should return the default export as default - lowlevel', function () { + + var modules = loader({ + dirname: path.resolve(__dirname, './fixtures/es-modules'), + filter: /(.+\.js)$/ + }) + + assert.deepEqual(modules, { + 'module-default.js': true, + 'sub-dir': { + 'another-module.js': true + } + }); + + });// + + +});// + diff --git a/test/fixtures/es-modules/module-default.js b/test/fixtures/es-modules/module-default.js new file mode 100644 index 0000000..3a947ad --- /dev/null +++ b/test/fixtures/es-modules/module-default.js @@ -0,0 +1,2 @@ + +exports.default = true diff --git a/test/fixtures/es-modules/sub-dir/another-module.js b/test/fixtures/es-modules/sub-dir/another-module.js new file mode 100644 index 0000000..3a947ad --- /dev/null +++ b/test/fixtures/es-modules/sub-dir/another-module.js @@ -0,0 +1,2 @@ + +exports.default = true