You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I see value out of generating faker-js mocks for my clients. However, when using the tags-split option, they get bundled into the same file alongside msw generated code.
I could rip out the msw dependencies and functions once generated, but it means I'll have to re-do this each time after an API update
Feature request
It would be useful to be able to specify the output.mock.type to be justfaker. This will allow me to build out some custom mocking strategy using the mock faker functions, as opposed to relying on msw.
Desired Output
When using tags-split, and something like output.mock.type: 'faker':
msw will simply import the mocks from the mocks file
Acknowledgements
Reading the documentation it's clear that just generating faker mocks doesn't fulfil the definition of what a "mock" is within an Orval context, as it assumes it also covers the implementation of the mock (i.e. msw or cypress etc.)
Many of the current configuration specified in output.mock are redundant for a mock.type: 'faker'
The text was updated successfully, but these errors were encountered:
// codemod/clean_orval_msw.tsimport{API,ASTPath,FileInfo,VariableDeclaration}from'jscodeshift';exportdefaultfunctiontransformer(file: FileInfo,api: API){constj=api.jscodeshift;constroot=j(file.source);// removes the 'msw' dependency importroot.find(j.ImportDeclaration).filter((path)=>path.value.source.value==='msw').remove();// removes the 'getFooMockHandler' functions, but leaves a `export {}` declarationroot.find(j.VariableDeclaration).filter((path)=>{constname=maybeGetMockHandlerFunctionName(path);returnname!=null;}).forEach((path)=>{constname=maybeGetMockHandlerFunctionName(path);// removes usages of each `getFooMockHandler` methodroot.find(j.CallExpression).filter((callPaths)=>{constcallee=callPaths.value.callee;if(callee.type!=='Identifier'){returnfalse;}returncallee.name===name;}).remove();}).remove();// removes the // removes the `export {}` declarationsroot.find(j.ExportNamedDeclaration).filter((path)=>path.value.declaration==null).remove();returnroot.toSource();}functionmaybeGetMockHandlerFunctionName(path: ASTPath<VariableDeclaration>): string|undefined{constdeclaration=path.value.declarations[0];if(declaration.type!=='VariableDeclarator'){returnundefined;}constid=declaration.id;if(id.type!=='Identifier'){returnundefined;}if(!id.name.endsWith('MockHandler')){returnundefined;}returnid.name;}
Hey team 👋
Problem
I'm currently using Orval to generate API clients for a React Native project. However, React Native has limited capability / support for MSW:
I see value out of generating faker-js mocks for my clients. However, when using the
tags-split
option, they get bundled into the same file alongsidemsw
generated code.I could rip out the
msw
dependencies and functions once generated, but it means I'll have to re-do this each time after an API updateFeature request
It would be useful to be able to specify the
output.mock.type
to be justfaker
. This will allow me to build out some custom mocking strategy using the mock faker functions, as opposed to relying on msw.Desired Output
When using
tags-split
, and something likeoutput.mock.type: 'faker'
:Will give me just a file that contains the
faker-js
implementations, and not anymsw
dependenciesWhen using
tags-split
, andoutput.mock.type: 'msw'
:msw will simply import the mocks from the mocks file
Acknowledgements
msw
orcypress
etc.)output.mock
are redundant for amock.type: 'faker'
The text was updated successfully, but these errors were encountered: