Closed muke1908 closed 1 year ago
Hey, @muke1908. Would like to work on these tests as well! Might take me a bit longer though. Let me know if thats ok with you.
@estefysc sure, go ahead! Feel free to write if you need any help
@muke1908 perfect! I will. Thanks.
Hey @muke1908 just wanted to double check.. are the tests just for "cryptoUtils", meaning the functions generateKeypairs, encryptMessage, and decryptMessage? Or should I include tests for all the other functions in the file?
@estefysc Yes those three are enough as only they are exported.
@muke1908 ok, perfect. Thanks for your response. Will finish soon for you to review and make suggestions.
@muke1908 I am having issues mocking the window.crypto.subtle dependency. I have done some research, and I have found info that talks about using the node crypto.webcrypto property like so:
const crypto = require('crypto').webcrypto;
global.crypto = crypto;
Would this be ok?
@estefysc You should not use the external module for testing. It needs to be mocked. You can just assign some mock module to global.crypto like
global.crypto = {
subtle: {
generateKey: jest.fn(),
encrypt: jest.fn(),
decrypt: jest.fn(),
importKey: jest.fn(),
exportKey: jest.fn()
}
}
also, you need to add mockReturnvalue to each func. For example, for generateKey:
const subtle = {
generateKey: jest.fn().mockResolvedValue('generatedKeyPair'),
};
globalThis.crypto = {
subtle,
};
it should work
@muke1908 Perfect. Thanks for the explanation. Will work in it.
@muke1908 I tried your suggestion and a couple versions of it, but I am seeing the following error in all cases:
The error below may be caused by using the wrong test environment, see https://jestjs.io/docs/configuration#testenvironment-string.
Consider using the "jsdom" test environment.
ReferenceError: window is not defined
can You push your code and create a PR, I’ll check On Sat 17. Jun 2023 at 23:28, estefysc @.***> wrote:
@muke1908 https://github.com/muke1908 I tried your suggestion and a couple versions of it, but I am seeing the following error in all cases:
The error below may be caused by using the wrong test environment, see https://jestjs.io/docs/configuration#testenvironment-string. Consider using the "jsdom" test environment.
ReferenceError: window is not defined
— Reply to this email directly, view it on GitHub https://github.com/muke1908/chat-e2ee/issues/287#issuecomment-1595864593, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE23SBLI2HHDUBQYAMN4OG3XLYOPZANCNFSM6AAAAAAX2D7QEY . You are receiving this because you were mentioned.Message ID: @.***>
Ok, just did.
Write unit test for cryptoUtils module, mock all necessary external browser dependency. https://github.com/muke1908/chat-e2ee/blob/master/service/src/crypto.ts