-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test for server directives (#627)
- Loading branch information
Showing
13 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "server-actions-example", | ||
"type": "module", | ||
"exports": { | ||
"./inline": "./dist/inline.js", | ||
"./client": "./dist/client.js" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "*" | ||
}, | ||
"dependencies": { | ||
"react": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use server' | ||
|
||
export async function action1() { | ||
return 'action1' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use client' | ||
|
||
import { action1 } from './action' | ||
|
||
export default function Page() { | ||
return <button onClick={action1}>Action 1</button> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// @ts-ignore externals | ||
import ClientComponent from 'client-component' | ||
|
||
export default function Page() { | ||
async function inlineAction() { | ||
'use server' | ||
return 'inline-action' | ||
} | ||
|
||
return <ClientComponent action={inlineAction} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"compilerOptions": { | ||
"jsx": "react-jsx", | ||
"target": "ES2022" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
!tsconfig.json |
42 changes: 42 additions & 0 deletions
42
test/integration/mixed-directives/__snapshots__/mixed-directives.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`integration - mixed-directives should work with js only project 1`] = ` | ||
{ | ||
"action-server-DOTFC6td.js": "'use server'; | ||
async function action1() { | ||
return 'action1'; | ||
} | ||
export { action1 as a }; | ||
", | ||
"client.js": "'use client'; | ||
import { jsx } from 'react/jsx-runtime'; | ||
import { a as action1 } from './action-server-DOTFC6td.js'; | ||
function Page() { | ||
return /*#__PURE__*/ jsx("button", { | ||
onClick: action1, | ||
children: "Action 1" | ||
}); | ||
} | ||
export { Page as default }; | ||
", | ||
"inline.js": "import { jsx } from 'react/jsx-runtime'; | ||
import ClientComponent from 'client-component'; | ||
// @ts-ignore externals | ||
function Page() { | ||
async function inlineAction() { | ||
'use server'; | ||
return 'inline-action'; | ||
} | ||
return /*#__PURE__*/ jsx(ClientComponent, { | ||
action: inlineAction | ||
}); | ||
} | ||
export { Page as default }; | ||
", | ||
} | ||
`; |
25 changes: 25 additions & 0 deletions
25
test/integration/mixed-directives/mixed-directives.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { readFileSync } from 'fs' | ||
import { createIntegrationTest, getFileNamesFromDirectory } from '../utils' | ||
|
||
describe('integration - mixed-directives', () => { | ||
it('should work with js only project', async () => { | ||
await createIntegrationTest( | ||
{ | ||
directory: __dirname, | ||
}, | ||
async ({ distDir }) => { | ||
const distFiles = await getFileNamesFromDirectory(distDir) | ||
const fileContents = distFiles | ||
.map((file) => [file, readFileSync(`${distDir}/${file}`, 'utf-8')]) | ||
.reduce((acc, pair) => { | ||
return { | ||
...acc, | ||
[pair[0]]: pair[1], | ||
} | ||
}, {}) | ||
|
||
expect(fileContents).toMatchSnapshot(``) | ||
}, | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "mixed-directives", | ||
"type": "module", | ||
"exports": { | ||
"./inline": "./dist/inline.js", | ||
"./client": "./dist/client.js" | ||
}, | ||
"dependencies": { | ||
"react": "*", | ||
"react-dom": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use server' | ||
|
||
export async function action1() { | ||
return 'action1' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use client' | ||
|
||
import { action1 } from './action' | ||
|
||
export default function Page() { | ||
return <button onClick={action1}>Action 1</button> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// @ts-ignore externals | ||
import ClientComponent from 'client-component' | ||
|
||
export default function Page() { | ||
async function inlineAction() { | ||
'use server' | ||
return 'inline-action' | ||
} | ||
|
||
return <ClientComponent action={inlineAction} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"compilerOptions": { | ||
"jsx": "react-jsx", | ||
"target": "ES2022" | ||
} | ||
} |