Skip to content

Commit

Permalink
Improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Mar 18, 2021
1 parent 8e3bb8a commit 55d1198
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
29 changes: 25 additions & 4 deletions test/function/samples/prevent-context-resolve-loop/_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ const path = require('path');
const ID_OTHER_1 = path.join(__dirname, 'other1.js');
const ID_OTHER_2 = path.join(__dirname, 'other2.js');
const ID_OTHER_3 = path.join(__dirname, 'other3.js');
const ID_OTHER_4 = path.join(__dirname, 'other4.js');

const thirdPluginCalls = new Set();

module.exports = {
description: 'prevents infinite loops when several plugins are calling this.resolve in resolveId',
Expand All @@ -12,17 +15,35 @@ module.exports = {
name: 'first',
async resolveId(source, importer) {
const { id } = await this.resolve(source, importer, { skipSelf: true });
if (id === ID_OTHER_2) {
return ID_OTHER_3;
if (id === ID_OTHER_1) {
return ID_OTHER_4;
}
}
},
{
name: 'second',
async resolveId(source, importer) {
const { id } = await this.resolve(source, importer, { skipSelf: true });
if (id === ID_OTHER_1) {
return ID_OTHER_2;
if (id === ID_OTHER_2) {
// To make this more interesting
await this.resolve('./other1', importer, { skipSelf: true });
await this.resolve(source, ID_OTHER_1, { skipSelf: true });
return ID_OTHER_4;
}
}
},
{
name: 'third',
async resolveId(source, importer) {
const hash = `${source}:${importer}`;
if (thirdPluginCalls.has(hash)) {
return null;
}
thirdPluginCalls.add(hash);
const { id } = await this.resolve(source, importer);
thirdPluginCalls.delete(hash);
if (id === ID_OTHER_3) {
return ID_OTHER_4;
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/function/samples/prevent-context-resolve-loop/dep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import third from './other3.js';

assert.strictEqual(third, 4);
5 changes: 3 additions & 2 deletions test/function/samples/prevent-context-resolve-loop/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import first from './other1.js';
import second from './other2.js';
import './dep.js';

assert.strictEqual(first, 3);
assert.strictEqual(second, 3);
assert.strictEqual(first, 4);
assert.strictEqual(second, 4);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 4;

0 comments on commit 55d1198

Please sign in to comment.