Skip to content

Commit 550cdc4

Browse files
committed
Skip the Conformance tests if Node is not installed
1 parent 805ea7f commit 550cdc4

File tree

2 files changed

+37
-45
lines changed

2 files changed

+37
-45
lines changed

tests/ModelContextProtocol.ConformanceTests/ConformanceTests.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,14 @@ public ValueTask DisposeAsync()
6262
}
6363

6464
[Fact]
65-
[Trait("Execution", "Manual")] // Requires Node.js/npm to be installed
6665
public async Task RunConformanceTests()
6766
{
67+
// Check if Node.js is installed
68+
if (!IsNodeInstalled())
69+
{
70+
throw new SkipException("Node.js is not installed. Skipping conformance tests.");
71+
}
72+
6873
// Run the conformance test suite
6974
var result = await RunNpxConformanceTests();
7075

@@ -157,4 +162,33 @@ public async Task RunConformanceTests()
157162
Error: errorBuilder.ToString()
158163
);
159164
}
165+
166+
private static bool IsNodeInstalled()
167+
{
168+
try
169+
{
170+
var startInfo = new ProcessStartInfo
171+
{
172+
FileName = "node",
173+
Arguments = "--version",
174+
RedirectStandardOutput = true,
175+
RedirectStandardError = true,
176+
UseShellExecute = false,
177+
CreateNoWindow = true
178+
};
179+
180+
using var process = Process.Start(startInfo);
181+
if (process == null)
182+
{
183+
return false;
184+
}
185+
186+
process.WaitForExit(5000);
187+
return process.ExitCode == 0;
188+
}
189+
catch
190+
{
191+
return false;
192+
}
193+
}
160194
}

tests/ModelContextProtocol.ConformanceTests/README.md

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,47 +13,5 @@ The conformance tests verify that the C# MCP server implementation adheres to th
1313

1414
## Running the Tests
1515

16-
Since these tests require Node.js/npm to be installed, they are marked as manual tests and excluded from the default test run.
17-
18-
### Run conformance tests explicitly
19-
20-
```bash
21-
# Run only conformance tests
22-
dotnet test tests/Conformance/ModelContextProtocol.ConformanceTests --filter 'Execution=Manual'
23-
24-
# Or run all manual tests across the solution
25-
dotnet test --filter 'Execution=Manual'
26-
```
27-
28-
### Skip conformance tests (default behavior)
29-
30-
```bash
31-
# Normal test run excludes Manual tests
32-
dotnet test --filter '(Execution!=Manual)'
33-
34-
# Or simply
35-
dotnet test
36-
```
37-
38-
## How It Works
39-
40-
1. **ClassInitialize** - Starts the ConformanceServer on port 3001 and waits for it to be ready
41-
2. **Test Execution** - Runs `npx @modelcontextprotocol/conformance server --url http://localhost:3001`
42-
3. **Result Reporting** - Parses the conformance test output and reports pass/fail to MSTest
43-
4. **ClassCleanup** - Shuts down the ConformanceServer
44-
45-
## Troubleshooting
46-
47-
If the tests fail:
48-
49-
1. Ensure Node.js and npm are installed: `node --version && npm --version`
50-
2. Check that port 3001 is not already in use
51-
3. Review the test output for specific conformance test failures
52-
4. The ConformanceServer logs are captured in the test output
53-
54-
## Implementation Details
55-
56-
- **Test Framework**: xUnit v3 with Microsoft.Testing.Platform
57-
- **Server**: ASP.NET Core-based ConformanceServer with HTTP transport
58-
- **Test Runner**: Uses `npx` to run the official MCP conformance test suite
59-
- **Lifecycle**: Uses xUnit's `IAsyncLifetime` to manage server startup/shutdown per test class
16+
These tests will run as part of the standard `dotnet test` command if Node.js is installed
17+
but will be skipped if Node.js is not detected.

0 commit comments

Comments
 (0)