如何在同一台机器上运行及并发执行多个Intern进程?
Hey there! Let's walk through how to run multiple Intern processes on a single machine—both sequentially and concurrently. Intern is a solid testing framework, but you need to keep a few key things in mind to avoid conflicts between processes.
Running Multiple Processes (Sequentially)
If you just need to run processes one after another, the main goal is to isolate configuration so each process doesn't step on the other's toes:
- Use separate config files: Create distinct config files like
intern.config.auth.jsandintern.config.ui.jsfor different test suites. Run each with:intern run -c intern.config.auth.js # Wait for it to finish, then run the next intern run -c intern.config.ui.js - Override config via CLI: If you want to reuse a base config, override critical settings via command-line arguments to avoid conflicts:
# First process uses port 9000 and outputs to auth-report.html intern run -c intern.config.js --server.port=9000 --reporters[0].outputFile=auth-report.html # Second process uses port 9001 and outputs to ui-report.html intern run -c intern.config.js --server.port=9001 --reporters[0].outputFile=ui-report.html - Avoid report/log overwrites: Always make sure each process writes its test reports, logs, or coverage data to unique files or directories.
Running Multiple Processes Concurrently
For true parallel execution, you'll need a way to launch and manage multiple Intern processes at the same time. Here are the most common approaches:
1. Use concurrently (Cross-Platform)
This npm package makes it easy to run multiple commands in parallel.
First, install it:
npm install --save-dev concurrently
Then add scripts to your package.json:
{ "scripts": { "test:auth": "intern run -c intern.config.auth.js", "test:ui": "intern run -c intern.config.ui.js", "test:parallel": "concurrently \"npm run test:auth\" \"npm run test:ui\"" } }
Run the concurrent tests with:
npm run test:parallel
2. Use Shell/Batch Scripts
On Linux/macOS, you can use a shell script to background processes:
# Launch both processes in the background intern run -c intern.config.auth.js & intern run -c intern.config.ui.js & # Wait for all background processes to finish wait echo "All Intern tests completed!"
On Windows, use a batch file:
start "" "intern run -c intern.config.auth.js" start "" "intern run -c intern.config.ui.js"
Critical Notes for Concurrent Execution
- Port conflicts: Every Intern process that starts a server (like for functional tests) needs a unique
server.portvalue. Double-check your configs or override via CLI to avoid "address already in use" errors. - Resource limits: Don't overload your machine! Each Intern process (especially if running functional tests with browser instances) uses CPU and memory. Start with a small number of concurrent processes and adjust based on your system's capacity.
- Test isolation: If your tests rely on shared resources (like databases, APIs, or file systems), make sure each process uses its own isolated instance. For example, use separate database names or unique test data prefixes to prevent cross-process data contamination.
- Browser instance isolation: For functional tests, if you're using the same browser, specify a unique user data directory (e.g.,
capabilities['moz:firefoxOptions'].args = ['--profile', './ff-profile-1']for Firefox) to avoid conflicts between browser sessions.
内容的提问来源于stack exchange,提问作者Bill Keese

