代码拉取完成,页面将自动刷新
const path = require(`path`);
let PnpWebpackPlugin = require(`./index`);
function makeResolver(resolverPlugins, options = {}) {
const {
NodeJsInputFileSystem,
CachedInputFileSystem,
ResolverFactory
} = require('enhanced-resolve');
const resolver = ResolverFactory.createResolver({
fileSystem: new CachedInputFileSystem(new NodeJsInputFileSystem(), 4000),
extensions: ['.js', '.json'],
... options,
});
for (const {apply} of resolverPlugins)
apply(resolver);
return resolver;
}
function makeRequest(resolver, request, issuer) {
return new Promise((resolve, reject) => {
resolver.resolve({}, issuer, request, {}, (err, filepath) => {
if (err) {
reject(err);
} else {
resolve(filepath);
}
});
});
}
describe(`Regular Plugin`, () => {
it(`should correctly resolve a relative require`, async () => {
const resolver = makeResolver([PnpWebpackPlugin]);
const resolution = await makeRequest(resolver, `./index.js`, __dirname);
expect(resolution).toEqual(path.normalize(`${__dirname}/index.js`));
});
it(`shouldn't prevent the 'extensions' option from working`, async () => {
const resolver = makeResolver([PnpWebpackPlugin]);
const resolution = await makeRequest(resolver, `./index`, __dirname);
expect(resolution).toEqual(path.normalize(`${__dirname}/index.js`));
});
it(`shouldn't prevent the 'alias' option from working`, async () => {
const resolver = makeResolver([PnpWebpackPlugin], {alias: {[`foo`]: `./fixtures/index.js`}});
const resolution = await makeRequest(resolver, `foo`, __dirname);
expect(resolution).toEqual(path.normalize(`${__dirname}/fixtures/index.js`));
});
it(`shouldn't prevent the 'modules' option from working`, async () => {
const resolver = makeResolver([PnpWebpackPlugin], {modules: [`./fixtures`]});
const resolution = await makeRequest(resolver, `file`, __dirname);
expect(resolution).toEqual(path.normalize(`${__dirname}/fixtures/file.js`));
});
});
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。