DEV Community

Cover image for Introducing nextjs-server-action-tester
Bijish O B
Bijish O B

Posted on

1

Introducing nextjs-server-action-tester

Why I Built nextjs-server-action-tester πŸ’‘

In a recent project, I was responsible for developing the frontend using Next.js, while a colleague handled the backend logic. As a core Node.js developer, my colleague was accustomed to using Postman for testing API endpoints. However, when it came to server actions in Next.jsβ€”functions that are executed directly on the server and aren't exposed as API endpointsβ€”he found it challenging to test them using traditional tools like Postman.

This challenge sparked the idea to create a tool that could scan a Next.js codebase, identify all server actions, and provide a user interface to test these actions 🎯. The goal was to streamline the testing process for server actions, especially for developers who are more familiar with traditional API testing methods. This led to the creation of nextjs-server-action-tester πŸš€.

What Is nextjs-server-action-tester? πŸ€–

nextjs-server-action-tester is an npm package designed to make the testing of server actions in Next.js projects as straightforward as possible. It automates the process of scanning your project, generates metadata, and creates a user-friendly UI for listing, searching, and executing server functions 🎨. The tool supports both JavaScript and TypeScript, and it comes with customizable configurations and a built-in light/dark mode.

Key Features ✨

1. Automatic Scanning: Scans your Next.js project to identify server actions.
2. UI for Testing: Generates a page within your project where you can list and test server actions.
3. Customizable Configurations: Offers flexibility in how the tool is configured and used within your project.
JavaScript and TypeScript Support: Works seamlessly with both languages.
4. Light/Dark Mode: UI that adapts to your preferred theme.

Libraries Used πŸ› οΈ

1. babel/parser: For parsing JavaScript/TypeScript code into an Abstract Syntax Tree (AST).
2. babel/traverse: For traversing the AST and identifying server actions.
3. fs-extra: For handling file operations during the setup and scanning process.

How to Use nextjs-server-action-tester πŸš€

1. Installation: First, install the package in your Next.js project:

npm install nextjs-server-action-tester

Enter fullscreen mode Exit fullscreen mode

2. Running the Tool: After installation, run the following command to start the scanning and testing process:

npx actions-scan

Enter fullscreen mode Exit fullscreen mode


This command will automatically set up the necessary files, initiate the scanning process, and generate a UI for testing server actions.

3. Testing Server Actions: Open the generated page in your browser (e.g.,http://localhost:3000/list-actions). Here, you can view all detected server actions, search for specific actions, input parameters, and execute them πŸ”.

Why It Improves Developer Experience πŸš€

nextjs-server-action-tester bridges the gap between traditional API testing tools like Postman and the server actions feature in Next.js. It empowers developers, especially those familiar with Node.js and API testing, to test server actions with ease. The tool integrates directly into your project, giving you full control while keeping the development process smooth and efficient.

Links πŸ”—

1. npm Package: nextjs-server-action-tester
2. Demo Video: Watch on YouTube

Contributing 🀝

Contributions are welcome! If you have ideas for improvements or find any issues, feel free to submit a pull request or open an issue on the GitHub repository.

By sharing this tool, I hope to make the development and testing of server actions in Next.js projects more accessible and efficient. Whether you're working on a solo project or collaborating with a team, nextjs-server-action-tester can be a valuable addition to your development toolkit πŸ’Ό.

Tiugo image

Modular, Fast, and Built for Developers

CKEditor 5 gives you full control over your editing experience. A modular architecture means you get high performance, fewer re-renders and a setup that scales with your needs.

Start now

Top comments (0)

Jetbrains image

Build Secure, Ship Fast

Discover best practices to secure CI/CD without slowing down your pipeline.

Read more

AWS GenAI LIVE! | May 14, 2025

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❀️