Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSC: Insert 'use client' in scaffolded components #9998

Merged
merged 4 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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'))
},
}
})

Expand Down Expand Up @@ -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]: [
'<Routes>',
' <Route path="/posts/new" page={NewPostPage} name="newPost" />',
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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]: [
'<Routes>',
' <Route path="/posts/new" page={NewPostPage} name="newPost" />',
' <Route path="/posts/{id:Int}/edit" page={EditPostPage} name="editPost" />',
' <Route path="/posts/{id:Int}" page={PostPage} name="post" />',
' <Route path="/posts" page={PostsPage} name="posts" />',
' <Route path="/" page={HomePage} name="home" />',
' <Route notfound page={NotFoundPage} />',
'</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]: [
'<Routes>',
' <Route path="/posts/new" page={NewPostPage} name="newPost" />',
' <Route path="/posts/{id:Int}/edit" page={EditPostPage} name="editPost" />',
' <Route path="/posts/{id:Int}" page={PostPage} name="post" />',
' <Route path="/posts" page={PostsPage} name="posts" />',
' <Route path="/" page={HomePage} name="home" />',
' <Route notfound page={NotFoundPage} />',
'</Routes>',
].join('\n'),
},
'/'
)
})

afterEach(() => {
vol.fromJSON(scaffoldTemplates)
vol.fromJSON({ 'redwood.toml': '', ...scaffoldTemplates }, '/')
vi.spyOn(fs, 'unlinkSync').mockClear()
})

Expand All @@ -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({
Expand Down Expand Up @@ -191,6 +200,7 @@ describe('rw destroy scaffold', () => {

describe('destroy namespaced scaffold post', () => {
beforeEach(async () => {
vol.fromJSON({ 'redwood.toml': '' }, '/')
vol.fromJSON({
...scaffoldTemplates,
...(await files({
Expand Down Expand Up @@ -244,6 +254,7 @@ describe('rw destroy scaffold', () => {

describe('for typescript files', () => {
beforeEach(async () => {
vol.fromJSON({ 'redwood.toml': '' }, '/')
vol.fromJSON({
...scaffoldTemplates,
...(await files({
Expand Down
Loading
Loading