Skip to content

Commit eaa86a0

Browse files
author
Mariusz Pasinski
committed
feat: make resolvedPath optional as suggested by Kraen
1 parent 8bb6e01 commit eaa86a0

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

packages/host/src/node/babel-plugin/plugin.test.ts

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe("plugin", () => {
4545
const EXPECTED_PKG_NAME = "my-package";
4646

4747
type TestCaseParams = {
48-
resolvedPath: string;
48+
resolvedPath?: string;
4949
originalPath: string;
5050
inputFile: string;
5151
options?: PluginOptions;
@@ -62,30 +62,25 @@ describe("plugin", () => {
6262
);
6363
assert(result);
6464
const { code } = result;
65-
assert(
66-
code && code.includes(`requireNodeAddon("${resolvedPath}", "${EXPECTED_PKG_NAME}", "${originalPath}")`),
67-
`Unexpected code: ${code}`
68-
);
65+
if (!resolvedPath) {
66+
assert(
67+
code && !code.includes(`requireNodeAddon`),
68+
`Unexpected code: ${code}`
69+
);
70+
} else {
71+
assert(
72+
code && code.includes(`requireNodeAddon("${resolvedPath}", "${EXPECTED_PKG_NAME}", "${originalPath}")`),
73+
`Unexpected code: ${code}`
74+
);
75+
}
6976
};
7077

7178
runTestCase({ resolvedPath: "./addon-1.node", originalPath: "./addon-1.node", inputFile: "./addon-1.js" });
7279
runTestCase({ resolvedPath: "./addon-2.node", originalPath: "./addon-2.node", inputFile: "./addon-2.js" });
7380
runTestCase({ resolvedPath: "./addon-1.node", originalPath: "../addon-1.node", inputFile: "./sub-directory/addon-1.js" });
7481
runTestCase({ resolvedPath: "./addon-2.node", originalPath: "../addon-2.node", inputFile: "./sub-directory-3/addon-outside.js" });
7582
runTestCase({ resolvedPath: "./addon-1.node", originalPath: "addon-1", inputFile: "./addon-1-bindings.js" });
76-
77-
{
78-
const result = transformFileSync(
79-
path.join(tempDirectoryPath, "./require-js-file.js"),
80-
{ plugins: [[plugin, { naming: "hash" }]] }
81-
);
82-
assert(result);
83-
const { code } = result;
84-
assert(
85-
code && !code.includes(`requireNodeAddon`),
86-
`Unexpected code: ${code}`
87-
);
88-
}
83+
runTestCase({ resolvedPath: undefined, originalPath: "./addon-1.js", inputFile: "./require-js-file.js" });
8984
});
9085

9186
it("transforms require calls to packages with native entry point", (context) => {

0 commit comments

Comments
 (0)