fake-module-system

2018-10-14 admin

fake-module-system是什么

什么是fake-module-system,A mock module system for testing require extensions

fake-module-system使用教程帮助文档

fake-module-system Build Status Coverage Status

A mock module system for testing require extensions.

Install

$ npm install --save-dev fake-module-system

Usage

import System from 'fake-module-system';

const system = new System({
  './foo.js': 'bar'  // a file named foo.js with content "bar"
}); 

// alternate method instead of setting up content in the constructor. 
system.content['./foo.js'] = 'bar';

let module = system.load('./foo.js');

// A module is not actually evaled, or ran. It just stores the code and filename
assert(module.code === 'bar');
assert(module.file === './foo.js');

// You can add custom require extensions for testing (the whole point of this module).
// This unrealisticly simple one just adds "quz" at the end of every file.
system.extensions['.js'] = appendQuzTransform(); 
module = system.load('./foo.js');
assert(module.code === 'barquz');

// Provides convenience method for installing a simple transform.
// This is handy for verifying how your extension behaves with earlier or later extensions.
system.installTransform((code, filename) => {
  if (shouldTransform(filename)) {
    return filename + ' foo';
  }
});
myTransformUnderTest.install(system.extensions);

Related:

License

MIT © James Talmage

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-42636.html

文章标题:fake-module-system

回到顶部