Skip to content

Commit 9813bc2

Browse files
committed
chore: add testing framework and update README for testing instructions
- Introduced Vitest for unit testing with configuration in vitest.config.ts. - Added comprehensive testing guide in TESTING.md. - Updated package.json to include test scripts. - Implemented cursor-based pagination in request.ts and corresponding tests. - Enhanced README with CI badge and testing instructions.
1 parent b836c5a commit 9813bc2

14 files changed

Lines changed: 2668 additions & 111 deletions

File tree

.github/workflows/README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# GitHub Actions Workflows
2+
3+
This directory contains automated CI/CD workflows for the Currents MCP Server project.
4+
5+
## Available Workflows
6+
7+
### `test.yml` - Unit Tests
8+
9+
Runs the unit test suite on every push and pull request.
10+
11+
**Triggers:**
12+
13+
- Push to any branch
14+
- Pull requests to any branch
15+
16+
**What it does:**
17+
18+
1. Checks out the code
19+
2. Sets up Node.js (tests on both Node 20.x and 22.x)
20+
3. Installs dependencies using `npm ci`
21+
4. Runs the test suite with `npm run test:run`
22+
5. Generates code coverage reports
23+
6. Optionally uploads coverage to Codecov (requires `CODECOV_TOKEN` secret)
24+
25+
**Matrix Strategy:**
26+
The workflow runs tests on multiple Node.js versions to ensure compatibility:
27+
28+
- Node.js 20.x (LTS)
29+
- Node.js 22.x (Latest)
30+
31+
**Coverage Reports:**
32+
Coverage reports are generated for all Node versions, but only uploaded from Node 20.x to avoid duplicate reports. Coverage files are located in `mcp-server/coverage/`.
33+
34+
## Secrets
35+
36+
The following secrets can be configured in your repository settings:
37+
38+
- `CODECOV_TOKEN` (optional): Token for uploading coverage reports to Codecov. If not set, the upload step will be skipped without failing the build.
39+
40+
## Local Testing
41+
42+
To run the same tests locally that run in CI:
43+
44+
```bash
45+
cd mcp-server
46+
npm ci
47+
npm run test:run
48+
npm run test:coverage
49+
```
50+
51+
## Troubleshooting
52+
53+
### Tests fail in CI but pass locally
54+
55+
- Ensure you're using the same Node.js version as CI (check the matrix versions)
56+
- Run `npm ci` instead of `npm install` to ensure exact dependency versions
57+
- Check for race conditions or timing issues in tests
58+
59+
### Coverage upload fails
60+
61+
- Verify the `CODECOV_TOKEN` secret is set correctly
62+
- The workflow is configured to not fail if coverage upload fails (`fail_ci_if_error: false`)
63+
64+
### Workflow doesn't trigger
65+
66+
- Ensure the `.github/workflows/` directory is in the root of your repository
67+
- Check that your branch protection rules aren't preventing the workflow from running
68+
- Verify the workflow file has proper YAML syntax
69+
70+
## Adding New Workflows
71+
72+
To add a new workflow:
73+
74+
1. Create a new `.yml` file in this directory
75+
2. Define the workflow name, triggers, and jobs
76+
3. Test it on a feature branch before merging to main
77+
4. Document it in this README
78+
79+
For more information on GitHub Actions syntax, see the [official documentation](https://docs.github.com/en/actions).

.github/workflows/test.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Unit Tests
2+
3+
on:
4+
push:
5+
branches: ["**"]
6+
pull_request:
7+
branches: ["**"]
8+
9+
jobs:
10+
test:
11+
name: Run Unit Tests
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
node-version: [20.x, 22.x]
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Setup Node.js ${{ matrix.node-version }}
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
cache: "npm"
27+
cache-dependency-path: mcp-server/package-lock.json
28+
29+
- name: Install dependencies
30+
working-directory: ./mcp-server
31+
run: npm ci
32+
33+
- name: Run tests
34+
working-directory: ./mcp-server
35+
run: npm run test:run
36+
37+
- name: Run tests with coverage
38+
working-directory: ./mcp-server
39+
run: npm run test:coverage
40+
41+
- name: Upload coverage reports
42+
if: matrix.node-version == '20.x'
43+
uses: codecov/codecov-action@v4
44+
with:
45+
files: ./mcp-server/coverage/coverage-final.json
46+
flags: unittests
47+
name: codecov-umbrella
48+
fail_ci_if_error: false
49+
env:
50+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ build
44
.currents-debug
55
test-results
66
playwright-report
7-
.cursor
7+
.cursor
8+
coverage

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Currents MCP Server
22

3+
![Unit Tests](https://github.com/currents-dev/currents-mcp/actions/workflows/test.yml/badge.svg)
4+
35
This is a MCP server that allows you to provide test results context to your AI agents by connecting them to Currents. Useful for asking AI to fix or optimize tests failing in CI.
46

57
[![Install MCP Server](https://cursor.com/deeplink/mcp-install-dark.svg)](https://cursor.com/en/install-mcp?name=currents&config=eyJjb21tYW5kIjoibnB4IC15IEBjdXJyZW50cy9tY3AiLCJlbnYiOnsiQ1VSUkVOVFNfQVBJX0tFWSI6InlvdXItYXBpLWtleSJ9fQ%3D%3D)
@@ -94,7 +96,12 @@ We welcome contributions of all kinds—bug fixes, features, and documentation u
9496
```bash
9597
npm run build
9698
```
97-
4. Run locally (stdio):
99+
4. Run tests:
100+
```bash
101+
npm test
102+
```
103+
See [TESTING.md](./mcp-server/TESTING.md) for more details on testing.
104+
5. Run locally (stdio):
98105
```bash
99106
npm start
100107
```
@@ -125,18 +132,19 @@ Example snippet for a client config:
125132
```
126133

127134
### Test tools locally
135+
128136
To test the tools locally without any LLM, you can use the following command:
137+
129138
```bash
130139
npm run build
131140
```
132141

133142
then run the tools script:
143+
134144
```bash
135145
node scripts/call-tools.js
136146
```
137147

138-
139-
140148
### Making Changes
141149

142150
- Create a feature branch:
@@ -147,6 +155,11 @@ then run the tools script:
147155
```bash
148156
npm run build && npm start
149157
```
158+
- Write tests for your changes in `*.test.ts` files alongside your code
159+
- Run tests to ensure everything works:
160+
```bash
161+
npm test
162+
```
150163
- Keep changes focused and documented (add comments/types where helpful).
151164

152165
### Commit and PR Guidelines

mcp-server/TESTING.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Testing Guide
2+
3+
This project uses [Vitest](https://vitest.dev/) for unit testing.
4+
5+
## Running Tests
6+
7+
### Run tests in watch mode (default)
8+
9+
```bash
10+
npm test
11+
```
12+
13+
### Run tests once (CI mode)
14+
15+
```bash
16+
npm run test:run
17+
```
18+
19+
### Run tests with UI
20+
21+
```bash
22+
npm run test:ui
23+
```
24+
25+
### Run tests with coverage
26+
27+
```bash
28+
npm run test:coverage
29+
```
30+
31+
## Writing Tests
32+
33+
Test files should be placed alongside the source files they test, using the naming convention:
34+
35+
- `*.test.ts` for TypeScript tests
36+
- `*.spec.ts` for specification tests
37+
38+
### Example Test Structure
39+
40+
```typescript
41+
import { describe, it, expect, vi, beforeEach } from "vitest";
42+
43+
describe("MyModule", () => {
44+
beforeEach(() => {
45+
// Setup before each test
46+
});
47+
48+
it("should do something", () => {
49+
// Test implementation
50+
expect(true).toBe(true);
51+
});
52+
});
53+
```
54+
55+
## Mocking
56+
57+
Vitest provides powerful mocking capabilities:
58+
59+
### Mocking modules
60+
61+
```typescript
62+
vi.mock("./module.js", () => ({
63+
someFunction: vi.fn(),
64+
}));
65+
```
66+
67+
### Mocking fetch
68+
69+
```typescript
70+
global.fetch = vi.fn().mockResolvedValue({
71+
ok: true,
72+
json: async () => ({ data: "test" }),
73+
});
74+
```
75+
76+
## Configuration
77+
78+
The test configuration is in `vitest.config.ts`. Key settings:
79+
80+
- **Environment**: Node.js
81+
- **Globals**: Enabled (no need to import `describe`, `it`, `expect`)
82+
- **Coverage Provider**: v8
83+
- **Test Pattern**: `**/*.{test,spec}.{ts,tsx}`
84+
85+
## Coverage
86+
87+
Coverage reports are generated in the `coverage/` directory when running `npm run test:coverage`.
88+
89+
Coverage thresholds and exclusions can be configured in `vitest.config.ts`.

0 commit comments

Comments
 (0)