Skip to content

Commit 75eb78e

Browse files
committed
Add ES module compliance test and CI integration
Add automated testing to catch ES module import issues: - New strict ES module test using Node.js directly - Updated CI pipeline to run ES module compliance check - Added npm script for ES module testing This prevents future regressions where missing .js extensions would break the SDK when consumed by ES module projects.
1 parent 3e44b02 commit 75eb78e

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

.github/workflows/unit-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ jobs:
2525

2626
- name: Run unit tests
2727
run: npm run test:unit
28+
29+
- name: Test ES module compliance
30+
run: npm run test:esm

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
"scripts": {
1212
"build": "tsc",
1313
"lint": "eslint src",
14-
"test": "vitest run",
14+
"test": "npm run build && vitest run",
1515
"test:unit": "vitest run tests/unit",
1616
"test:e2e": "vitest run tests/e2e",
17+
"test:esm": "npm run build && node test-esm-strict.mjs",
1718
"test:watch": "vitest",
1819
"test:coverage": "vitest run --coverage",
1920
"prepublishOnly": "npm run build"

test-esm-strict.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Strict ES module test - runs with Node.js directly
3+
* This will fail if imports don't have proper .js extensions
4+
*/
5+
import { createClient } from './dist/index.js';
6+
7+
console.log('✅ ES module import successful');
8+
console.log('createClient:', typeof createClient);
9+
10+
const client = createClient({
11+
apiKey: 'test-key',
12+
baseURL: 'https://api.test.com'
13+
});
14+
15+
console.log('✅ Client creation successful');
16+
process.exit(0);

tests/esm-compliance.test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Test to verify ES module compliance by importing the built SDK
3+
* This test runs against the compiled output to catch import issues
4+
*/
5+
import { createClient } from '../dist/index.js';
6+
import { describe, it, expect } from 'vitest';
7+
8+
describe('ES Module Compliance', () => {
9+
it('should import the SDK successfully from built dist', () => {
10+
expect(createClient).toBeDefined();
11+
expect(typeof createClient).toBe('function');
12+
});
13+
14+
it('should create a client instance', () => {
15+
const client = createClient({
16+
apiKey: 'test-key',
17+
baseURL: 'https://api.test.com'
18+
});
19+
expect(client).toBeDefined();
20+
});
21+
});

0 commit comments

Comments
 (0)