-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support node 16.12 loaders * Docs * Upgrade node version * Try again * Fixes
- Loading branch information
1 parent
656c754
commit 0868eda
Showing
8 changed files
with
109 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default "King K Rool might actually be a nice guy"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default "King K Rool might actually be a nice guy"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import assert from "assert"; | ||
|
||
describe("load hook", () => { | ||
it(`works with a single load hook`, async () => { | ||
global.nodeLoader.setConfigPromise( | ||
Promise.resolve({ | ||
loaders: [ | ||
{ | ||
load: async function (url, context, defaultLoad) { | ||
if (url.includes("krool.js")) { | ||
const { source: originalSource } = await defaultLoad( | ||
url, | ||
context | ||
); | ||
const finalSource = `${originalSource};\nexport const more = "I mean what did he even do to deserve Donkey Kong's wrath?"`; | ||
return { | ||
format: "module", | ||
source: finalSource, | ||
}; | ||
} else { | ||
return defaultLoad(url, context); | ||
} | ||
}, | ||
}, | ||
], | ||
}) | ||
); | ||
|
||
const ns = await import("./fixtures/krool.js"); | ||
assert.equal(ns.default, "King K Rool might actually be a nice guy"); | ||
|
||
assert.equal( | ||
ns.more, | ||
"I mean what did he even do to deserve Donkey Kong's wrath?" | ||
); | ||
}); | ||
|
||
it(`works with multiple load hooks`, async () => { | ||
global.nodeLoader.setConfigPromise( | ||
Promise.resolve({ | ||
loaders: [ | ||
{ | ||
load: async function (url, context, defaultLoad) { | ||
if (url.includes("krool2.js")) { | ||
const { source: originalSource } = await defaultLoad( | ||
url, | ||
context | ||
); | ||
const finalSource = `${originalSource};\nexport const more = "I mean what did he even do to deserve Donkey Kong's wrath?"`; | ||
return { | ||
format: "module", | ||
source: finalSource, | ||
}; | ||
} else { | ||
return defaultLoad(url, context); | ||
} | ||
}, | ||
}, | ||
{ | ||
load: async function (url, context, defaultLoad) { | ||
if (url.includes("krool2.js")) { | ||
const { source: originalSource } = await defaultLoad( | ||
url, | ||
context | ||
); | ||
const finalSource = `${originalSource};\nexport const evenMore = "What if we got it all wrong and DK is the evil one?"`; | ||
return { | ||
format: "module", | ||
source: finalSource, | ||
}; | ||
} else { | ||
return defaultLoad(url, context); | ||
} | ||
}, | ||
}, | ||
], | ||
}) | ||
); | ||
|
||
const ns = await import("./fixtures/krool2.js"); | ||
assert.equal(ns.default, "King K Rool might actually be a nice guy"); | ||
|
||
assert.equal( | ||
ns.more, | ||
"I mean what did he even do to deserve Donkey Kong's wrath?" | ||
); | ||
|
||
assert.equal( | ||
ns.evenMore, | ||
"What if we got it all wrong and DK is the evil one?" | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters