-
Notifications
You must be signed in to change notification settings - Fork 45
Conversation
9ab3d46
to
c28d4aa
Compare
tests/index.spec.js
Outdated
// @ts-ignore - TypeScript refuses to change the type of the mock... | ||
signingCall = jest.fn().mockImplementation( | ||
/** | ||
* @param {SignParams} params | ||
*/ | ||
// eslint-disable-next-line no-unused-vars |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea what has changed here tbh :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure what made tsc
to start to complain, but it seems that it may be able to stop complaining with a bit of help (but I haven't used typescript as much as flowtype and so I don't exclude I may have tricked tsc
to stop complaining in an incorrect way)
The following tweaked version passed npm run typecheck
(and also npm run lint
and npm run test
) for me locally and so may consider if we prefer using this approach as an alternative to the @ts-ignore (not a big deal though):
diff --git a/tests/index.spec.js b/tests/index.spec.js
index 1500c48..a673759 100644
--- a/tests/index.spec.js
+++ b/tests/index.spec.js
@@ -69,17 +69,20 @@ describe(fileURLToPath(import.meta.url), () => {
// @ts-ignore
this.debug = jest.fn();
- // @ts-ignore - TypeScript refuses to change the type of the mock...
- signingCall = jest.fn().mockImplementation(
- // eslint-disable-next-line no-unused-vars
- (params) =>
- new Promise((resolve) => {
- if (options.errorToThrow) {
- throw options.errorToThrow;
- }
- resolve(options.result);
- }),
- );
+ /** @type {(params: SignParams) => Promise<SignResult>} */
+ // eslint-disable-next-line no-unused-vars
+ const mockedSigningCall = (params) =>
+ new Promise((resolve) => {
+ if (options.errorToThrow) {
+ throw options.errorToThrow;
+ }
+ resolve(options.result);
+ });
+
+ /**
+ * @type {jest.Mock<(params: SignParams) => Promise<SignResult>>}
+ */
+ signingCall = jest.fn(this.sign).mockImplementation(mockedSigningCall);
1909603
to
3d984eb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@willdurand this looks great, follows a couple of comments, but they seems mainly nice to have and so I'm approving this version along with submitting those.
I'm happy to give this another look if we decide to integrate some more tweaks from the review comments below.
tests/index.spec.js
Outdated
// @ts-ignore - TypeScript refuses to change the type of the mock... | ||
signingCall = jest.fn().mockImplementation( | ||
/** | ||
* @param {SignParams} params | ||
*/ | ||
// eslint-disable-next-line no-unused-vars |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure what made tsc
to start to complain, but it seems that it may be able to stop complaining with a bit of help (but I haven't used typescript as much as flowtype and so I don't exclude I may have tricked tsc
to stop complaining in an incorrect way)
The following tweaked version passed npm run typecheck
(and also npm run lint
and npm run test
) for me locally and so may consider if we prefer using this approach as an alternative to the @ts-ignore (not a big deal though):
diff --git a/tests/index.spec.js b/tests/index.spec.js
index 1500c48..a673759 100644
--- a/tests/index.spec.js
+++ b/tests/index.spec.js
@@ -69,17 +69,20 @@ describe(fileURLToPath(import.meta.url), () => {
// @ts-ignore
this.debug = jest.fn();
- // @ts-ignore - TypeScript refuses to change the type of the mock...
- signingCall = jest.fn().mockImplementation(
- // eslint-disable-next-line no-unused-vars
- (params) =>
- new Promise((resolve) => {
- if (options.errorToThrow) {
- throw options.errorToThrow;
- }
- resolve(options.result);
- }),
- );
+ /** @type {(params: SignParams) => Promise<SignResult>} */
+ // eslint-disable-next-line no-unused-vars
+ const mockedSigningCall = (params) =>
+ new Promise((resolve) => {
+ if (options.errorToThrow) {
+ throw options.errorToThrow;
+ }
+ resolve(options.result);
+ });
+
+ /**
+ * @type {jest.Mock<(params: SignParams) => Promise<SignResult>>}
+ */
+ signingCall = jest.fn(this.sign).mockImplementation(mockedSigningCall);
Fixes #1078
This PR converts the library to ES modules and this is similar to mozilla/web-ext#2405.
Summary
webpack
, it is usingbabel
like web-extsignAddon
andsignAddonAndExit
with the option of dynamically importing the library in commonjs (await import()
)Public API
I verified the public API by
npm pack
'ing this work andnpm i /path/to/sign-addon-4.1.0.tgz
in a temporary directory. Then I created two scripts, one for commonjs and one for esmodules. The APIs are the same except that commonjs has adefault
, which I think is expected.and: