| 3 | |
| 4 | const renderImport = `import { render } from "@testing-library/react"`; |
| 5 | const generateTestFileContent = (exports: Export[], isRouteFile: boolean) => { |
| 6 | return exports |
| 7 | .map((toImport) => { |
| 8 | const importName = toImport.name; |
| 9 | if (isRouteFile && toImport.isDefault) { |
| 10 | return [ |
| 11 | `describe('${importName} Test suite', () => {`, |
| 12 | ` it('should work', async () => {`, |
| 13 | ` render(<${importName} />);`, |
| 14 | ` expect(${importName}).toBeTruthy();`, |
| 15 | ` });`, |
| 16 | `});`, |
| 17 | ].join("\n"); |
| 18 | } |
| 19 | if (importName === "ErrorBoundary") { |
| 20 | return [ |
| 21 | `describe('${importName} Test suite', () => {`, |
| 22 | ` it('should work', async () => {`, |
| 23 | ` render(<${importName} />);`, |
| 24 | ` expect(${importName}).toBeTruthy();`, |
| 25 | ` });`, |
| 26 | `});`, |
| 27 | ].join("\n"); |
| 28 | } |
| 29 | if (importName === "shouldRevalidate") { |
| 30 | return [ |
| 31 | `describe('${importName} Test suite', () => {`, |
| 32 | ` it('should work', async () => {`, |
| 33 | ` const params = { defaultShouldRevalidate: true, currentUrl: new URL("http://localhost:3000"), nextUrl: new URL("http://localhost:3000"), nextParams: {}, currentParams: {} }`, |
| 34 | ` const result = ${importName}(params);`, |
| 35 | ` expect(result).toBeTruthy();`, |
| 36 | ` });`, |
| 37 | `});`, |
| 38 | ].join("\n"); |
| 39 | } |
| 40 | if (importName === "headers") { |
| 41 | return [ |
| 42 | `describe("${importName} Test suite", () => {`, |
| 43 | ` it("should work", () => {`, |
| 44 | ` expect(`, |
| 45 | ` ${importName}({`, |
| 46 | ` loaderHeaders: new Headers(),`, |
| 47 | ` parentHeaders: new Headers(),`, |
| 48 | ` actionHeaders: new Headers(),`, |
| 49 | ` errorHeaders: new Headers()`, |
| 50 | ` })`, |
| 51 | ` ).toBeTruthy();`, |
| 52 | ` });`, |
| 53 | `});`, |
| 54 | ].join("\n"); |
| 55 | } |
| 56 | if (importName === "meta") { |
| 57 | return [ |
| 58 | `describe("meta Test suite", () => {`, |
| 59 | ` it("should work", () => {`, |
| 60 | ` expect(`, |
| 61 | ` meta({`, |
| 62 | ` params: {},`, |