|
| 1 | +import fs from 'node:fs' |
| 2 | +import path from 'node:path' |
| 3 | + |
| 4 | +import { findUp } from '@redwoodjs/project-config' |
| 5 | + |
| 6 | +describe('fragments graphQLClientConfig', () => { |
| 7 | + test('App.tsx with no graphQLClientConfig', async () => { |
| 8 | + await matchFolderTransform('appGqlConfigTransform', 'config-simple', { |
| 9 | + useJsCodeshift: true, |
| 10 | + }) |
| 11 | + }) |
| 12 | + |
| 13 | + test('App.tsx with existing inline graphQLClientConfig', async () => { |
| 14 | + await matchFolderTransform('appGqlConfigTransform', 'existingPropInline', { |
| 15 | + useJsCodeshift: true, |
| 16 | + }) |
| 17 | + }) |
| 18 | + |
| 19 | + test('App.tsx with existing graphQLClientConfig in separate variable', async () => { |
| 20 | + await matchFolderTransform( |
| 21 | + 'appGqlConfigTransform', |
| 22 | + 'existingPropVariable', |
| 23 | + { |
| 24 | + useJsCodeshift: true, |
| 25 | + } |
| 26 | + ) |
| 27 | + }) |
| 28 | + |
| 29 | + test('App.tsx with existing graphQLClientConfig in separate variable, without cacheConfig property', async () => { |
| 30 | + await matchFolderTransform( |
| 31 | + 'appGqlConfigTransform', |
| 32 | + 'existingPropVariableNoCacheConfig', |
| 33 | + { |
| 34 | + useJsCodeshift: true, |
| 35 | + } |
| 36 | + ) |
| 37 | + }) |
| 38 | + |
| 39 | + test('App.tsx with existing graphQLClientConfig in separate variable with non-standard name', async () => { |
| 40 | + await matchFolderTransform( |
| 41 | + 'appGqlConfigTransform', |
| 42 | + 'existingPropVariableCustomName', |
| 43 | + { |
| 44 | + useJsCodeshift: true, |
| 45 | + } |
| 46 | + ) |
| 47 | + }) |
| 48 | + |
| 49 | + test('test-project App.tsx', async () => { |
| 50 | + const rootFwPath = path.dirname(findUp('lerna.json') || '') |
| 51 | + const testProjectAppTsx = fs.readFileSync( |
| 52 | + path.join( |
| 53 | + rootFwPath, |
| 54 | + '__fixtures__', |
| 55 | + 'test-project', |
| 56 | + 'web', |
| 57 | + 'src', |
| 58 | + 'App.tsx' |
| 59 | + ), |
| 60 | + 'utf-8' |
| 61 | + ) |
| 62 | + await matchInlineTransformSnapshot( |
| 63 | + 'appGqlConfigTransform', |
| 64 | + testProjectAppTsx, |
| 65 | + `import { FatalErrorBoundary, RedwoodProvider } from \"@redwoodjs/web\"; |
| 66 | + import { RedwoodApolloProvider } from \"@redwoodjs/web/apollo\"; |
| 67 | +
|
| 68 | + import FatalErrorPage from \"src/pages/FatalErrorPage\"; |
| 69 | + import Routes from \"src/Routes\"; |
| 70 | +
|
| 71 | + import { AuthProvider, useAuth } from \"./auth\"; |
| 72 | +
|
| 73 | + import \"./scaffold.css\"; |
| 74 | + import \"./index.css\"; |
| 75 | +
|
| 76 | + const graphQLClientConfig = { |
| 77 | + cacheConfig: { |
| 78 | + possibleTypes: possibleTypes.possibleTypes, |
| 79 | + }, |
| 80 | + }; |
| 81 | +
|
| 82 | + const App = () => ( |
| 83 | + <FatalErrorBoundary page={FatalErrorPage}> |
| 84 | + <RedwoodProvider titleTemplate=\"%PageTitle | %AppTitle\"> |
| 85 | + <AuthProvider> |
| 86 | + <RedwoodApolloProvider |
| 87 | + useAuth={useAuth} |
| 88 | + graphQLClientConfig={graphQLClientConfig} |
| 89 | + > |
| 90 | + <Routes /> |
| 91 | + </RedwoodApolloProvider> |
| 92 | + </AuthProvider> |
| 93 | + </RedwoodProvider> |
| 94 | + </FatalErrorBoundary> |
| 95 | + ); |
| 96 | +
|
| 97 | + export default App; |
| 98 | + ` |
| 99 | + ) |
| 100 | + }) |
| 101 | +}) |
0 commit comments