Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: Mocking types for unit test #239

Open
Rvice opened this issue Feb 7, 2023 · 8 comments
Open

Request: Mocking types for unit test #239

Rvice opened this issue Feb 7, 2023 · 8 comments

Comments

@Rvice
Copy link
Contributor

Rvice commented Feb 7, 2023

Not sure if this is the right place, but it would be nice to get some mock support for unit testing. Is there any plan of this or a recommendation other than writing all the mocks out for jest?

@MrRob
Copy link
Collaborator

MrRob commented Feb 8, 2023

@Rvice I don't have any plans for unit testing here. I have tried setting up testing in NetSuite a couple of times (using https://www.npmjs.com/package/@oracle/suitecloud-unit-testing and https://github.com/KyleJonesWinsted/suitecloud-unit-testing-stubs) but haven't ever had any luck with it actually being useful. Happy to take a look though if anybody has any ideas for improvement here!

@darrenhillconsulting
Copy link
Contributor

darrenhillconsulting commented Feb 8, 2023 via email

@Rvice
Copy link
Contributor Author

Rvice commented Feb 8, 2023

I'm close to a baseline with TeamCity, finally got the output working properly and using two tsconfig.ts to separate tests from production code (two different source/output dirs). That way it does not pollute NS with the test code. Issue I'm running into is the mocks with trying to rewrite the example from @oracle/suitecloud-unit-testing in typescript.

Based on what I'm seeing, I see the "stubs" that are in the @oracle/suitecloud-unit-testing, just getting a failure when trying to use those directly on the record.load mock operation.

@darrenhillconsulting
Copy link
Contributor

darrenhillconsulting commented Feb 8, 2023 via email

@Rvice
Copy link
Contributor Author

Rvice commented Feb 8, 2023

I attempted to "convert" the example from @oracle/suitecloud-unit-testing, but it crashes at record.load.mockReturnValue

I assume this is because my tsconfig is pointing 'N/**' to the HITC defines instead of the suitecloud-unit-testing, but trying to make the swap also doesn't seem to work.

@ShawnTalbert
Copy link
Contributor

NFT has unit testing - maybe take a look at what's going on there.

@bendemeyer
Copy link

bendemeyer commented Jul 25, 2023

I've been able to get unit testing working pretty well by providing my own type declarations for @oracle/suitecloud-unit-testing package. It's mostly just lots of declarations like this:

declare module '@oracle/suitecloud-unit-testing/stubs/log/log' {
    import type logType from '@hitc/netsuite-types/N/log';
    const log: typeof logType;
    export default log;
}

Of course you may want to play around with that module name and your tsconfig path settings/jest moduleNameMapper, but the basic idea should be sound.

I don't know if it would make sense to add something like that to this project, but maybe a separate project that uses this one to provide type declarations for @oracle/suitecloud-unit-testing would be useful.

@ShawnTalbert
Copy link
Contributor

I agree, mocking would make more sense as a separate repo - keep this one focused on what it does best.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants