Skip to content

Commit d308561

Browse files
committed
feat(tests): add TTS test, fix offline tests for mocks
1 parent f16d74f commit d308561

19 files changed

Lines changed: 454 additions & 802 deletions

jest.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,8 @@ module.exports = {
4747
// Clear mocks between tests
4848
clearMocks: true,
4949
restoreMocks: true,
50+
51+
// Force Jest to exit after tests complete
52+
// This prevents hanging caused by lingering HTTP connections (TLSWRAP handles)
53+
forceExit: true,
5054
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
"docs:json": "typedoc --entryPoints src/index.ts --includes src/packages/**/*.ts --json docs/spec.json --emit none",
5656
"test": "jest",
5757
"test:unit": "jest --testPathPattern=tests/unit",
58+
"test:e2e": "jest --testPathPattern=tests/e2e",
59+
"test:e2e:offline": "node scripts/test-offline.js",
5860
"test:watch": "jest --watch",
5961
"test:coverage": "jest --coverage",
6062
"test:ci": "jest --ci --coverage --watchAll=false"
@@ -82,7 +84,6 @@
8284
"jest-environment-jsdom": "^29.7.0",
8385
"markdownlint": "^0.35.0",
8486
"markdownlint-cli": "^0.42.0",
85-
"nock": "^13.5.4",
8687
"nodemon": "^3.0.1",
8788
"npm-run-all": "^4.1.5",
8889
"prettier": "^2.5.1",

pnpm-lock.yaml

Lines changed: 0 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/test-offline.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env node
2+
3+
/* eslint-env node */
4+
/* eslint-disable @typescript-eslint/no-var-requires, import/no-commonjs */
5+
6+
/**
7+
* Test script to verify e2e tests work properly offline
8+
* This script simulates offline conditions and runs the tests
9+
*/
10+
11+
const { spawn } = require("child_process");
12+
13+
console.log("🧪 Testing Deepgram JS SDK e2e tests in offline mode\n");
14+
15+
// Environment variables to ensure offline testing
16+
const env = {
17+
...process.env,
18+
JEST_SILENT: "false",
19+
NODE_ENV: "test",
20+
// Remove any real API key to force mock usage
21+
DEEPGRAM_API_KEY: "mock-api-key-for-offline-testing",
22+
};
23+
24+
// Test command
25+
const testCommand = "npm";
26+
const testArgs = ["test", "--", "tests/e2e/", "--verbose"];
27+
28+
console.log("🎭 Running e2e tests with mocked API calls...");
29+
console.log(`Command: ${testCommand} ${testArgs.join(" ")}\n`);
30+
31+
const testProcess = spawn(testCommand, testArgs, {
32+
env,
33+
stdio: "inherit",
34+
shell: true,
35+
});
36+
37+
testProcess.on("close", (code) => {
38+
if (code === 0) {
39+
console.log("\n✅ All e2e tests passed in offline mode!");
40+
console.log("🎉 Your tests are properly configured to work without internet connection.");
41+
console.log("\n💡 To run tests with real API calls (for updating snapshots):");
42+
console.log(" npm test -- tests/e2e/ --updateSnapshot");
43+
console.log("\n🔧 To force real API calls without updating snapshots:");
44+
console.log(" DEEPGRAM_FORCE_REAL_API=true npm test -- tests/e2e/");
45+
} else {
46+
console.log(`\n❌ Tests failed with exit code ${code}`);
47+
console.log("🔍 This indicates there might be network dependencies that need to be mocked.");
48+
}
49+
});
50+
51+
testProcess.on("error", (error) => {
52+
console.error("❌ Failed to run tests:", error);
53+
process.exit(1);
54+
});

tests/__fixtures__/e2e-requests.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,41 @@ export const transcriptionOptions = {
5555
keyterm: ["spacewalk"],
5656
},
5757
} as const;
58+
59+
/**
60+
* Common TTS options used across multiple tests
61+
*/
62+
export const commonTTSOptions = {
63+
model: "aura-2-thalia-en",
64+
encoding: "mp3",
65+
} as const;
66+
67+
/**
68+
* Test text sources for TTS scenarios
69+
*/
70+
export const testTextSources = {
71+
greeting: { text: "Hello, how can I help you today?" },
72+
longText: {
73+
text: "This is a longer text sample for testing text-to-speech functionality with multiple sentences. It should demonstrate how the API handles longer content.",
74+
},
75+
multiline: { text: "Line one.\nLine two.\nLine three with more content." },
76+
} as const;
77+
78+
/**
79+
* Alternative TTS options for different test scenarios
80+
*/
81+
export const ttsOptions = {
82+
basic: {
83+
model: "aura-2-thalia-en",
84+
},
85+
highQuality: {
86+
model: "aura-2-thalia-en",
87+
encoding: "linear16",
88+
sample_rate: 48000,
89+
},
90+
compressed: {
91+
model: "aura-2-thalia-en",
92+
encoding: "mp3",
93+
bit_rate: 128000,
94+
},
95+
} as const;

0 commit comments

Comments
 (0)