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

Allow jest to run with use server directive #56148

Merged
merged 8 commits into from
Sep 28, 2023
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
20 changes: 10 additions & 10 deletions packages/next/src/build/swc/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,16 @@ function getBaseSWCOptions({
development
),
}),
serverComponents: hasServerComponents
? { isServer: !!isServerLayer }
: undefined,
serverActions: hasServerComponents
? {
// TODO-APP: When Server Actions is stable, we need to remove this flag.
enabled: !!isServerActionsEnabled,
isServer: !!isServerLayer,
}
: undefined,
serverComponents:
hasServerComponents && !jest ? { isServer: !!isServerLayer } : undefined,
serverActions:
hasServerComponents && !jest
? {
// TODO-APP: When Server Actions is stable, we need to remove this flag.
enabled: !!isServerActionsEnabled,
isServer: !!isServerLayer,
}
: undefined,
bundleTarget,
}
}
Expand Down
5 changes: 5 additions & 0 deletions test/production/jest/rsc/app/server-action/action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use server'

export async function action(data) {
console.log(data)
}
9 changes: 9 additions & 0 deletions test/production/jest/rsc/app/server-action/page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { action } from './action'

export default function Page() {
return (
<button data-testid="log" onClick={action}>
log
</button>
)
}
10 changes: 10 additions & 0 deletions test/production/jest/rsc/app/server-action/page.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* @jest-environment jsdom
*/
import { render, screen } from '@testing-library/react'
import Page from './page'

it('works with client-only code', () => {
render(<Page />)
expect(screen.getByTestId('log')).toHaveTextContent('log')
})
Loading