9b87e6148e4af9de578789216e94f5b43546d0391f4aa33945c024af0e18c7ea4824d7267adeaec47ab2635379f4a7c1c5c5af3a13163fc1d78071bae6be03 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { IncomingMessage, ServerResponse } from 'http';
  2. import { Plugin } from 'vite';
  3. interface ViteMockOptions {
  4. mockPath?: string;
  5. configPath?: string;
  6. ignore?: RegExp | ((fileName: string) => boolean);
  7. watchFiles?: boolean;
  8. localEnabled?: boolean;
  9. prodEnabled?: boolean;
  10. injectFile?: string;
  11. injectCode?: string;
  12. /**
  13. * Automatic recognition, no need to configure again
  14. * @deprecated Deprecated after 2.8.0
  15. */
  16. supportTs?: boolean;
  17. logger?: boolean;
  18. }
  19. interface RespThisType {
  20. req: IncomingMessage;
  21. res: ServerResponse;
  22. parseJson: () => any;
  23. }
  24. type MethodType = 'get' | 'post' | 'put' | 'delete' | 'patch';
  25. type Recordable<T = any> = Record<string, T>;
  26. declare interface MockMethod {
  27. url: string;
  28. method?: MethodType;
  29. timeout?: number;
  30. statusCode?: number;
  31. response?: (this: RespThisType, opt: {
  32. url: Recordable;
  33. body: Recordable;
  34. query: Recordable;
  35. headers: Recordable;
  36. }) => any;
  37. rawResponse?: (this: RespThisType, req: IncomingMessage, res: ServerResponse) => void;
  38. }
  39. interface NodeModuleWithCompile extends NodeModule {
  40. _compile(code: string, filename: string): any;
  41. }
  42. declare function viteMockServe(opt?: ViteMockOptions): Plugin;
  43. export { MethodType, MockMethod, NodeModuleWithCompile, Recordable, RespThisType, ViteMockOptions, viteMockServe };