-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: js library default export to a unique name instead of default ke…
…y in self (#36483)
- Loading branch information
1 parent
9731728
commit 2443b8c
Showing
2 changed files
with
67 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,17 @@ declare const self: WorkerGlobalScope; | |
|
||
describe("Tests to assert install/uninstall flows", function () { | ||
beforeAll(() => { | ||
self.importScripts = jest.fn(() => { | ||
self.importScripts = jest.fn((url: string) => { | ||
if (url.includes("jspdf-autotable")) { | ||
const defaultVar = function () {}; | ||
|
||
defaultVar.Cell = function () {}; | ||
self.Cell = function () {}; | ||
self.default = defaultVar; | ||
|
||
return; | ||
} | ||
|
||
self.lodash = {}; | ||
}); | ||
|
||
|
@@ -150,4 +160,28 @@ describe("Tests to assert install/uninstall flows", function () { | |
method: "Hello", | ||
}); | ||
}); | ||
|
||
it("should install a library with default export", async function () { | ||
const res = await installLibrary({ | ||
data: { | ||
url: "https://cdn.jsdelivr.net/npm/[email protected]/dist/jspdf.plugin.autotable.js", | ||
takenAccessors: [], | ||
takenNamesMap: {}, | ||
}, | ||
method: EVAL_WORKER_ASYNC_ACTION.INSTALL_LIBRARY, | ||
webworkerTelemetry: {}, | ||
}); | ||
|
||
expect(self.importScripts).toHaveBeenCalled(); | ||
expect(mod.makeTernDefs).toHaveBeenCalledWith({}); | ||
|
||
expect(res).toEqual({ | ||
accessor: ["jspdf_plugin_autotable_js"], | ||
defs: { | ||
"!name": "LIB/jspdf_plugin_autotable_js", | ||
jspdf_plugin_autotable_js: undefined, | ||
}, | ||
success: true, | ||
}); | ||
}); | ||
}); |
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