From 55f922488362021a76e73bffd01484bdb4e386df Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Mon, 12 Feb 2024 18:24:28 +0100 Subject: [PATCH 1/4] RSC: Insert 'use client' in scaffolded components --- packages/cli/src/commands/generate/scaffold/scaffold.js | 5 +++++ .../scaffold/templates/components/NewName.tsx.template | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/commands/generate/scaffold/scaffold.js b/packages/cli/src/commands/generate/scaffold/scaffold.js index 177ef4cf7730..fa2335f34fa5 100644 --- a/packages/cli/src/commands/generate/scaffold/scaffold.js +++ b/packages/cli/src/commands/generate/scaffold/scaffold.js @@ -593,6 +593,10 @@ const componentFiles = async ( outputComponentName ) + const useClientDirective = getConfig().experimental?.rsc?.enabled + ? "'use client'\n\n" + : '' + const template = generateTemplate( customOrDefaultTemplatePath({ side: 'web', @@ -606,6 +610,7 @@ const componentFiles = async ( pascalIdName, intForeignKeys, pascalScaffoldPath, + useClientDirective, ...templateStrings, ...modelRelatedVariables(model), } diff --git a/packages/cli/src/commands/generate/scaffold/templates/components/NewName.tsx.template b/packages/cli/src/commands/generate/scaffold/templates/components/NewName.tsx.template index 79d37c6f57fd..36fe7b553287 100644 --- a/packages/cli/src/commands/generate/scaffold/templates/components/NewName.tsx.template +++ b/packages/cli/src/commands/generate/scaffold/templates/components/NewName.tsx.template @@ -1,4 +1,4 @@ -import type { +${useClientDirective}import type { Create${singularPascalName}Mutation, Create${singularPascalName}Input, Create${singularPascalName}MutationVariables From 2a95538c677e678c38ed82071acae68025448d88 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Mon, 12 Feb 2024 18:25:08 +0100 Subject: [PATCH 2/4] NamesCell.tsx.template --- .../scaffold/templates/components/NamesCell.tsx.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/commands/generate/scaffold/templates/components/NamesCell.tsx.template b/packages/cli/src/commands/generate/scaffold/templates/components/NamesCell.tsx.template index 801e0448026b..b71f4dcef537 100644 --- a/packages/cli/src/commands/generate/scaffold/templates/components/NamesCell.tsx.template +++ b/packages/cli/src/commands/generate/scaffold/templates/components/NamesCell.tsx.template @@ -1,4 +1,4 @@ -import type { Find${pluralPascalName}, Find${pluralPascalName}Variables } from 'types/graphql' +${useClientDirective}import type { Find${pluralPascalName}, Find${pluralPascalName}Variables } from 'types/graphql' import { Link, routes } from '@redwoodjs/router' import type { From b67620e8874162222899e9a3c46a32eab47d86b5 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Mon, 12 Feb 2024 18:26:49 +0100 Subject: [PATCH 3/4] More cell templates --- .../scaffold/templates/components/EditNameCell.tsx.template | 2 +- .../scaffold/templates/components/NameCell.tsx.template | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/commands/generate/scaffold/templates/components/EditNameCell.tsx.template b/packages/cli/src/commands/generate/scaffold/templates/components/EditNameCell.tsx.template index 652d783066ea..227b079a1a06 100644 --- a/packages/cli/src/commands/generate/scaffold/templates/components/EditNameCell.tsx.template +++ b/packages/cli/src/commands/generate/scaffold/templates/components/EditNameCell.tsx.template @@ -1,4 +1,4 @@ -import type { +${useClientDirective}import type { Edit${singularPascalName}By${pascalIdName}, Update${singularPascalName}Input, Update${singularPascalName}MutationVariables diff --git a/packages/cli/src/commands/generate/scaffold/templates/components/NameCell.tsx.template b/packages/cli/src/commands/generate/scaffold/templates/components/NameCell.tsx.template index 2c3fbd6d0b6b..d804292f4fd0 100644 --- a/packages/cli/src/commands/generate/scaffold/templates/components/NameCell.tsx.template +++ b/packages/cli/src/commands/generate/scaffold/templates/components/NameCell.tsx.template @@ -1,4 +1,4 @@ -import type { Find${singularPascalName}By${pascalIdName}, Find${singularPascalName}By${pascalIdName}Variables } from 'types/graphql' +${useClientDirective}import type { Find${singularPascalName}By${pascalIdName}, Find${singularPascalName}By${pascalIdName}Variables } from 'types/graphql' import type { CellSuccessProps, From 7c04177f93d1a0cb41ec4500077fef5f0b1cb07d Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Tue, 13 Feb 2024 00:49:55 +0100 Subject: [PATCH 4/4] Add tests --- .../scaffold/__tests__/scaffold.test.js | 32 ++- .../scaffold/__tests__/scaffoldNoNest.test.js | 55 +++-- .../__snapshots__/scaffold.test.js.snap | 225 ++++++++++++++++++ .../__tests__/editableColumns.test.js | 4 + .../scaffold/__tests__/scaffold.test.js | 63 +++++ .../__tests__/scaffoldCustomIdName.test.js | 4 + .../scaffold/__tests__/scaffoldNoNest.test.js | 3 + .../scaffold/__tests__/scaffoldPath.test.js | 6 + .../__tests__/scaffoldPathMulti.test.js | 6 + .../__tests__/scaffoldPathMultiNoNest.test.js | 6 + .../__tests__/scaffoldPathMultiword.test.js | 6 + .../scaffoldPathMultiwordNoNest.test.js | 6 + .../__tests__/scaffoldPathNoNest.test.js | 6 + .../shouldUseEmptyAsUndefined.test.js | 3 + 14 files changed, 391 insertions(+), 34 deletions(-) diff --git a/packages/cli/src/commands/destroy/scaffold/__tests__/scaffold.test.js b/packages/cli/src/commands/destroy/scaffold/__tests__/scaffold.test.js index 2c6a7587e2a5..e2921314b724 100644 --- a/packages/cli/src/commands/destroy/scaffold/__tests__/scaffold.test.js +++ b/packages/cli/src/commands/destroy/scaffold/__tests__/scaffold.test.js @@ -16,6 +16,7 @@ import { import { files } from '../../../generate/scaffold/scaffold' import { tasks } from '../scaffold' +vi.mock('fs', async () => ({ default: (await import('memfs')).fs })) vi.mock('fs-extra') vi.mock('execa') @@ -32,8 +33,9 @@ vi.mock('../../../../lib/schemaHelpers', async (importOriginal) => { const path = require('path') return { ...originalSchemaHelpers, - getSchema: () => - require(path.join(globalThis.__dirname, 'fixtures', 'post.json')), + getSchema: () => { + return require(path.join(globalThis.__dirname, 'fixtures', 'post.json')) + }, } }) @@ -64,15 +66,21 @@ templateDirectories.forEach((directory) => { describe('rw destroy scaffold', () => { describe('destroy scaffold post', () => { beforeEach(async () => { - vol.fromJSON(scaffoldTemplates) + // This fs is needed for the `files` function imported from `generate` + vol.fromJSON({ 'redwood.toml': '', ...scaffoldTemplates }, '/') + + const postFiles = await files({ + ...getDefaultArgs(defaults), + model: 'Post', + tests: false, + nestScaffoldByModel: true, + }) + + // This fs is needed for all the tests here vol.fromJSON({ + 'redwood.toml': '', ...scaffoldTemplates, - ...(await files({ - ...getDefaultArgs(defaults), - model: 'Post', - tests: false, - nestScaffoldByModel: true, - })), + ...postFiles, [getPaths().web.routes]: [ '', ' ', @@ -118,8 +126,7 @@ describe('rw destroy scaffold', () => { beforeEach(async () => { // clear filesystem so files call works as expected vol.reset() - vol.fromJSON(scaffoldTemplates) - + vol.fromJSON({ 'redwood.toml': '', ...scaffoldTemplates }, '/') vol.fromJSON({ ...scaffoldTemplates, ...(await files({ @@ -193,8 +200,9 @@ describe('rw destroy scaffold', () => { describe('destroy namespaced scaffold post', () => { beforeEach(async () => { - vol.fromJSON(scaffoldTemplates) + // vol.fromJSON(scaffoldTemplates) vol.fromJSON({ + 'redwood.toml': '', ...scaffoldTemplates, ...(await files({ ...getDefaultArgs(defaults), diff --git a/packages/cli/src/commands/destroy/scaffold/__tests__/scaffoldNoNest.test.js b/packages/cli/src/commands/destroy/scaffold/__tests__/scaffoldNoNest.test.js index fb96fd021d49..60b5ce9065a7 100644 --- a/packages/cli/src/commands/destroy/scaffold/__tests__/scaffoldNoNest.test.js +++ b/packages/cli/src/commands/destroy/scaffold/__tests__/scaffoldNoNest.test.js @@ -16,6 +16,7 @@ import { import { files } from '../../../generate/scaffold/scaffold' import { tasks } from '../scaffold' +vi.mock('fs', async () => ({ default: (await import('memfs')).fs })) vi.mock('fs-extra') vi.mock('execa') @@ -64,30 +65,38 @@ templateDirectories.forEach(async (directory) => { describe('rw destroy scaffold', () => { describe('destroy scaffold post', () => { beforeEach(async () => { - vol.fromJSON(scaffoldTemplates) - vol.fromJSON({ - ...scaffoldTemplates, - ...(await files({ - ...getDefaultArgs(defaults), - model: 'Post', - tests: false, - nestScaffoldByModel: false, - })), - [getPaths().web.routes]: [ - '', - ' ', - ' ', - ' ', - ' ', - ' ', - ' ', - '', - ].join('\n'), + // This fs is needed for the `files` function imported from `generate` + vol.fromJSON({ 'redwood.toml': '', ...scaffoldTemplates }, '/') + + const postFiles = await files({ + ...getDefaultArgs(defaults), + model: 'Post', + tests: false, + nestScaffoldByModel: false, }) + + // This fs is needed for all the tests here + vol.fromJSON( + { + ...scaffoldTemplates, + ...postFiles, + [getPaths().web.routes]: [ + '', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + '', + ].join('\n'), + }, + '/' + ) }) afterEach(() => { - vol.fromJSON(scaffoldTemplates) + vol.fromJSON({ 'redwood.toml': '', ...scaffoldTemplates }, '/') vi.spyOn(fs, 'unlinkSync').mockClear() }) @@ -109,15 +118,15 @@ describe('rw destroy scaffold', () => { nestScaffoldByModel: false, }) ) - expect(generatedFiles.length).toEqual(unlinkSpy.mock.calls.length) generatedFiles.forEach((f) => expect(unlinkSpy).toHaveBeenCalledWith(f)) + expect(generatedFiles.length).toEqual(unlinkSpy.mock.calls.length) }) }) describe('for typescript files', () => { beforeEach(async () => { vol.reset() - vol.fromJSON(scaffoldTemplates) + vol.fromJSON({ 'redwood.toml': '', ...scaffoldTemplates }, '/') vol.fromJSON({ ...scaffoldTemplates, ...(await files({ @@ -191,6 +200,7 @@ describe('rw destroy scaffold', () => { describe('destroy namespaced scaffold post', () => { beforeEach(async () => { + vol.fromJSON({ 'redwood.toml': '' }, '/') vol.fromJSON({ ...scaffoldTemplates, ...(await files({ @@ -244,6 +254,7 @@ describe('rw destroy scaffold', () => { describe('for typescript files', () => { beforeEach(async () => { + vol.fromJSON({ 'redwood.toml': '' }, '/') vol.fromJSON({ ...scaffoldTemplates, ...(await files({ diff --git a/packages/cli/src/commands/generate/scaffold/__tests__/__snapshots__/scaffold.test.js.snap b/packages/cli/src/commands/generate/scaffold/__tests__/__snapshots__/scaffold.test.js.snap index 3ccc477e41b3..fd5d6ca39a0f 100644 --- a/packages/cli/src/commands/generate/scaffold/__tests__/__snapshots__/scaffold.test.js.snap +++ b/packages/cli/src/commands/generate/scaffold/__tests__/__snapshots__/scaffold.test.js.snap @@ -1,5 +1,230 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +exports[`'use client' directive > creates a new EditPostCell cell with the 'use client' directive 1`] = ` +"'use client' + +import { navigate, routes } from '@redwoodjs/router' + +import { useMutation } from '@redwoodjs/web' +import { toast } from '@redwoodjs/web/toast' + +import PostForm from 'src/components/Post/PostForm' + +export const QUERY = gql\` + query EditPostById($id: Int!) { + post: post(id: $id) { + id + title + slug + author + body + image + postedAt + isPinned + readTime + rating + upvotes + metadata + hugeNumber + } + } +\` + +const UPDATE_POST_MUTATION = gql\` + mutation UpdatePostMutation($id: Int!, $input: UpdatePostInput!) { + updatePost(id: $id, input: $input) { + id + title + slug + author + body + image + postedAt + isPinned + readTime + rating + upvotes + metadata + hugeNumber + } + } +\` + +export const Loading = () =>
Loading...
+ +export const Failure = ({ error }) => ( +
{error?.message}
+) + +export const Success = ({ post }) => { + const [updatePost, { loading, error }] = useMutation(UPDATE_POST_MUTATION, { + onCompleted: () => { + toast.success('Post updated') + navigate(routes.posts()) + }, + onError: (error) => { + toast.error(error.message) + }, + }) + + const onSave = (input, id) => { + updatePost({ variables: { id, input } }) + } + + return ( +
+
+

+ Edit Post {post?.id} +

+
+
+ +
+
+ ) +} +" +`; + +exports[`'use client' directive > creates a new NewPost component with the 'use client' directive 1`] = ` +"'use client' + +import { navigate, routes } from '@redwoodjs/router' +import { useMutation } from '@redwoodjs/web' + +import { toast } from '@redwoodjs/web/toast' + +import PostForm from 'src/components/Post/PostForm' + +const CREATE_POST_MUTATION = gql\` + mutation CreatePostMutation($input: CreatePostInput!) { + createPost(input: $input) { + id + } + } +\` + +const NewPost = () => { + const [createPost, { loading, error }] = useMutation(CREATE_POST_MUTATION, { + onCompleted: () => { + toast.success('Post created') + navigate(routes.posts()) + }, + onError: (error) => { + toast.error(error.message) + }, + }) + + const onSave = (input) => { + createPost({ variables: { input } }) + } + + return ( +
+
+

New Post

+
+
+ +
+
+ ) +} + +export default NewPost +" +`; + +exports[`'use client' directive > creates a new PostCell cell with the 'use client' directive 1`] = ` +"'use client' + +import Post from 'src/components/Post/Post' + +export const QUERY = gql\` + query FindPostById($id: Int!) { + post: post(id: $id) { + id + title + slug + author + body + image + postedAt + isPinned + readTime + rating + upvotes + metadata + hugeNumber + } + } +\` + +export const Loading = () =>
Loading...
+ +export const Empty = () =>
Post not found
+ +export const Failure = ({ error }) => ( +
{error?.message}
+) + +export const Success = ({ post }) => { + return +} +" +`; + +exports[`'use client' directive > creates a new PostsCell cell with the 'use client' directive 1`] = ` +"'use client' + +import { Link, routes } from '@redwoodjs/router' + +import Posts from 'src/components/Post/Posts' + +export const QUERY = gql\` + query FindPosts { + posts { + id + title + slug + author + body + image + postedAt + isPinned + readTime + rating + upvotes + metadata + hugeNumber + } + } +\` + +export const Loading = () =>
Loading...
+ +export const Empty = () => { + return ( +
+ {'No posts yet. '} + + {'Create one?'} + +
+ ) +} + +export const Failure = ({ error }) => ( +
{error?.message}
+) + +export const Success = ({ posts }) => { + return +} +" +`; + exports[`in javascript (default) mode > creates a edit page 1`] = ` "import EditPostCell from 'src/components/Post/EditPostCell' diff --git a/packages/cli/src/commands/generate/scaffold/__tests__/editableColumns.test.js b/packages/cli/src/commands/generate/scaffold/__tests__/editableColumns.test.js index 91409e62cdbc..261662106a89 100644 --- a/packages/cli/src/commands/generate/scaffold/__tests__/editableColumns.test.js +++ b/packages/cli/src/commands/generate/scaffold/__tests__/editableColumns.test.js @@ -4,12 +4,14 @@ import path from 'path' // Load mocks import '../../../../lib/test' +import { vol } from 'memfs' import { vi, describe, beforeAll, test, expect } from 'vitest' import { getDefaultArgs } from '../../../../lib' import { yargsDefaults as defaults } from '../../helpers' import * as scaffold from '../scaffold' +vi.mock('fs', async () => ({ default: (await import('memfs')).fs })) vi.mock('execa') describe('editable columns', () => { @@ -17,6 +19,8 @@ describe('editable columns', () => { let form beforeAll(async () => { + vol.fromJSON({ 'redwood.toml': '' }, '/') + files = await scaffold.files({ ...getDefaultArgs(defaults), model: 'ExcludeDefault', diff --git a/packages/cli/src/commands/generate/scaffold/__tests__/scaffold.test.js b/packages/cli/src/commands/generate/scaffold/__tests__/scaffold.test.js index 7e63881aaf18..c40c5dcc5634 100644 --- a/packages/cli/src/commands/generate/scaffold/__tests__/scaffold.test.js +++ b/packages/cli/src/commands/generate/scaffold/__tests__/scaffold.test.js @@ -1,6 +1,7 @@ globalThis.__dirname = __dirname import path from 'path' +import { vol } from 'memfs' import { vi, describe, test, expect, beforeAll } from 'vitest' // Load mocks @@ -10,8 +11,13 @@ import { getDefaultArgs } from '../../../../lib' import { yargsDefaults as defaults } from '../../helpers' import * as scaffold from '../scaffold' +vi.mock('fs', async () => ({ default: (await import('memfs')).fs })) vi.mock('execa') +beforeAll(() => { + vol.fromJSON({ 'redwood.toml': '' }, '/') +}) + describe('in javascript (default) mode', () => { let files @@ -743,3 +749,60 @@ describe('tailwind flag', () => { ).toMatchSnapshot() }) }) + +describe("'use client' directive", () => { + let files + + beforeAll(async () => { + vol.fromJSON( + { 'redwood.toml': '[experimental.rsc]\n enabled = true' }, + '/' + ) + + files = await scaffold.files({ + ...getDefaultArgs(defaults), + model: 'Post', + nestScaffoldByModel: true, + }) + }) + + test("creates a new NewPost component with the 'use client' directive", async () => { + expect( + files[ + path.normalize( + '/path/to/project/web/src/components/Post/NewPost/NewPost.jsx' + ) + ] + ).toMatchSnapshot() + }) + + test("creates a new PostCell cell with the 'use client' directive", async () => { + expect( + files[ + path.normalize( + '/path/to/project/web/src/components/Post/PostCell/PostCell.jsx' + ) + ] + ).toMatchSnapshot() + }) + + test("creates a new PostsCell cell with the 'use client' directive", async () => { + expect( + files[ + path.normalize( + '/path/to/project/web/src/components/Post/PostsCell/PostsCell.jsx' + ) + ] + ).toMatchSnapshot() + }) + + test("creates a new EditPostCell cell with the 'use client' directive", async () => { + expect( + files[ + path.normalize( + '/path/to/project/web/src/components/Post/EditPostCell/EditPostCell.jsx' + ) + ] + ).toMatchSnapshot() + }) +}) diff --git a/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldCustomIdName.test.js b/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldCustomIdName.test.js index fdfc8a9e7fa1..610fa82267dd 100644 --- a/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldCustomIdName.test.js +++ b/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldCustomIdName.test.js @@ -1,6 +1,7 @@ globalThis.__dirname = __dirname import path from 'path' +import { vol } from 'memfs' import { vi, describe, beforeAll, test, expect } from 'vitest' // Load mocks @@ -10,12 +11,15 @@ import { getDefaultArgs } from '../../../../lib' import { yargsDefaults as defaults } from '../../helpers' import * as scaffold from '../scaffold' +vi.mock('fs', async () => ({ default: (await import('memfs')).fs })) vi.mock('execa') describe('support custom @id name', () => { let files beforeAll(async () => { + vol.fromJSON({ 'redwood.toml': '' }, '/') + files = await scaffold.files({ ...getDefaultArgs(defaults), typescript: true, diff --git a/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldNoNest.test.js b/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldNoNest.test.js index d6d267f4a905..4e84cef4e8fa 100644 --- a/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldNoNest.test.js +++ b/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldNoNest.test.js @@ -1,6 +1,7 @@ globalThis.__dirname = __dirname import path from 'path' +import { vol } from 'memfs' import { vi, describe, beforeAll, test, expect } from 'vitest' // Load mocks @@ -10,12 +11,14 @@ import { getDefaultArgs } from '../../../../lib' import { yargsDefaults as defaults } from '../../helpers' import * as scaffold from '../scaffold' +vi.mock('fs', async () => ({ default: (await import('memfs')).fs })) vi.mock('execa') describe('in javascript (default) mode', () => { let files beforeAll(async () => { + vol.fromJSON({ 'redwood.toml': '' }, '/') files = await scaffold.files({ ...getDefaultArgs(defaults), model: 'Post', diff --git a/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldPath.test.js b/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldPath.test.js index a62d34b52cea..828600a73fe9 100644 --- a/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldPath.test.js +++ b/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldPath.test.js @@ -1,14 +1,20 @@ globalThis.__dirname = __dirname import path from 'path' +import { vol } from 'memfs' import { vi, describe, beforeAll, test, it, expect } from 'vitest' import '../../../../lib/test' import * as scaffold from '../scaffold' +vi.mock('fs', async () => ({ default: (await import('memfs')).fs })) vi.mock('execa') +beforeAll(() => { + vol.fromJSON({ 'redwood.toml': '' }, '/') +}) + describe('admin/post', () => { let filesLower diff --git a/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldPathMulti.test.js b/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldPathMulti.test.js index ee1f5e980514..c278cac77b8e 100644 --- a/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldPathMulti.test.js +++ b/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldPathMulti.test.js @@ -1,14 +1,20 @@ globalThis.__dirname = __dirname import path from 'path' +import { vol } from 'memfs' import { vi, describe, beforeAll, test, expect } from 'vitest' import '../../../../lib/test' import * as scaffold from '../scaffold' +vi.mock('fs', async () => ({ default: (await import('memfs')).fs })) vi.mock('execa') +beforeAll(() => { + vol.fromJSON({ 'redwood.toml': '' }, '/') +}) + describe('admin/pages/post', () => { let filesNestedLower diff --git a/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldPathMultiNoNest.test.js b/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldPathMultiNoNest.test.js index c24383e6ebec..49cde654245c 100644 --- a/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldPathMultiNoNest.test.js +++ b/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldPathMultiNoNest.test.js @@ -1,14 +1,20 @@ globalThis.__dirname = __dirname import path from 'path' +import { vol } from 'memfs' import { vi, describe, beforeAll, test, expect } from 'vitest' import '../../../../lib/test' import * as scaffold from '../scaffold' +vi.mock('fs', async () => ({ default: (await import('memfs')).fs })) vi.mock('execa') +beforeAll(() => { + vol.fromJSON({ 'redwood.toml': '' }, '/') +}) + describe('admin/pages/post', () => { let filesNestedLower diff --git a/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldPathMultiword.test.js b/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldPathMultiword.test.js index 4cf4a90a35d5..aad59d3ec567 100644 --- a/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldPathMultiword.test.js +++ b/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldPathMultiword.test.js @@ -1,14 +1,20 @@ globalThis.__dirname = __dirname import path from 'path' +import { vol } from 'memfs' import { vi, describe, beforeAll, test, expect } from 'vitest' import '../../../../lib/test' import * as scaffold from '../scaffold' +vi.mock('fs', async () => ({ default: (await import('memfs')).fs })) vi.mock('execa') +beforeAll(() => { + vol.fromJSON({ 'redwood.toml': '' }, '/') +}) + describe('AdminPages/Post', () => { let filesMultiwordUpper diff --git a/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldPathMultiwordNoNest.test.js b/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldPathMultiwordNoNest.test.js index f80468486808..a49b379946d4 100644 --- a/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldPathMultiwordNoNest.test.js +++ b/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldPathMultiwordNoNest.test.js @@ -1,14 +1,20 @@ globalThis.__dirname = __dirname import path from 'path' +import { vol } from 'memfs' import { vi, describe, beforeAll, test, expect } from 'vitest' import '../../../../lib/test' import * as scaffold from '../scaffold' +vi.mock('fs', async () => ({ default: (await import('memfs')).fs })) vi.mock('execa') +beforeAll(() => { + vol.fromJSON({ 'redwood.toml': '' }, '/') +}) + describe('AdminPages/Post', () => { let filesMultiwordUpper diff --git a/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldPathNoNest.test.js b/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldPathNoNest.test.js index 0129fdda8076..7001ec3c92c3 100644 --- a/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldPathNoNest.test.js +++ b/packages/cli/src/commands/generate/scaffold/__tests__/scaffoldPathNoNest.test.js @@ -1,14 +1,20 @@ globalThis.__dirname = __dirname import path from 'path' +import { vol } from 'memfs' import { vi, describe, beforeAll, test, expect } from 'vitest' import '../../../../lib/test' import * as scaffold from '../scaffold' +vi.mock('fs', async () => ({ default: (await import('memfs')).fs })) vi.mock('execa') +beforeAll(() => { + vol.fromJSON({ 'redwood.toml': '' }, '/') +}) + describe('admin/Post', () => { let filesLower diff --git a/packages/cli/src/commands/generate/scaffold/__tests__/shouldUseEmptyAsUndefined.test.js b/packages/cli/src/commands/generate/scaffold/__tests__/shouldUseEmptyAsUndefined.test.js index 2335234e4966..542b5971a0ed 100644 --- a/packages/cli/src/commands/generate/scaffold/__tests__/shouldUseEmptyAsUndefined.test.js +++ b/packages/cli/src/commands/generate/scaffold/__tests__/shouldUseEmptyAsUndefined.test.js @@ -1,6 +1,7 @@ globalThis.__dirname = __dirname import path from 'path' +import { vol } from 'memfs' import { vi, describe, beforeAll, test, expect } from 'vitest' // Load mocks @@ -10,12 +11,14 @@ import { getDefaultArgs } from '../../../../lib' import { yargsDefaults as defaults } from '../../helpers' import * as scaffold from '../scaffold' +vi.mock('fs', async () => ({ default: (await import('memfs')).fs })) vi.mock('execa') describe('relational form field', () => { let form beforeAll(async () => { + vol.fromJSON({ 'redwood.toml': '' }, '/') const files = await scaffold.files({ ...getDefaultArgs(defaults), model: 'Tag',