Skip to content

Commit

Permalink
Tests: splitAsync use import()
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Dec 26, 2022
1 parent 60c3a32 commit 59954a5
Showing 1 changed file with 1 addition and 39 deletions.
40 changes: 1 addition & 39 deletions lib/serialize/createModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@

// Exports

// Use implementation which uses `import()` if possible, otherwise use fallback.
// Does not work correctly in Jest - there are separate Mocha tests to cover this.
module.exports = process.env.NODE_ENV !== 'test' ? createModulePromise : createModulePromiseFallback;
module.exports = createModulePromise;

// Implementation using `import()`
let importCounter = 0;

/**
Expand All @@ -37,38 +34,3 @@ function createModulePromise(val, splitPoint) {

return promise;
}

/**
* Fallback module object creator which does not use `import()`.
*
* The module object it creates resembles a native module namespace object in every respect except:
* 1. `require('util').types.isModuleNamespaceObject(moduleObj)` returns `false`
* 2. `moduleObj.default = x` does not throw an error
* 3. `console.log(moduleObj)` output is slightly different
*
* @param {*} val - Value to create module from
* @param {Object} splitPoint - Split point object
* @returns {Promise} - Promise which resolves to module object
*/
function createModulePromiseFallback(val, splitPoint) {
const moduleObj = Object.seal(
Object.create(null, {
default: {
value: val,
writable: true,
enumerable: true,
configurable: false
},
[Symbol.toStringTag]: {
value: 'Module',
writable: false,
enumerable: false,
configurable: false
}
})
);

splitPoint.moduleObj = moduleObj;

return Promise.resolve(moduleObj);
}

0 comments on commit 59954a5

Please sign in to comment.