This directory contains TypeScript tests to verify that the type definitions in marklogic.d.ts work correctly.
Files like basic-types.test.ts, connection-methods.test.ts, type-constraints.test.ts, error-examples.test.ts
- Purpose: Verify that TypeScript code compiles without errors
- Execution: Not executed at runtime - only compiled
- Speed: Very fast (seconds)
- Requirements: No MarkLogic server needed
- Run with:
npm run test:types
These tests validate:
- Type definitions are syntactically correct
- Type constraints work (e.g.,
authTypeonly accepts valid values) - IntelliSense will work for users
- Type errors are caught at compile time
Files like checkConnection-runtime.test.ts
- Purpose: Verify that TypeScript definitions match actual runtime behavior
- Execution: Compiled to JavaScript and executed with mocha
- Speed: Slower (requires MarkLogic)
- Requirements: MarkLogic server running
- Run with:
npm run test:compile && npx mocha test-typescript/*.js
These tests validate:
- Types compile correctly (compile-time check)
- Real API calls return the expected types (runtime check)
- TypeScript definitions accurately reflect the actual JavaScript behavior
npm run test:typesThis runs tsc --noEmit, which checks for TypeScript errors without generating JavaScript files.
npm run test:compile # Compile TypeScript tests to JavaScript
npx mocha test-typescript/*.js # Run compiled tests against MarkLogicOr in one command:
npm run test:compile && npx mocha test-typescript/*.jsCompile-only tests are great for:
- Fast feedback during development
- Catching type definition errors quickly
- CI/CD pre-flight checks (before spinning up MarkLogic)
- Validating that autocomplete/IntelliSense will work
Runtime tests are essential for:
- Ensuring type definitions match actual behavior
- Catching mismatches between declared types and runtime values
- Integration testing with real MarkLogic instances
- Preventing issues like returning
{}when aPromisewas expected
Both approaches complement each other for comprehensive type safety validation.
// This should work fine ✅
const good: DatabaseClientConfig = {
authType: 'digest'
};
// This should fail ❌ (uncomment to test)
// const bad: DatabaseClientConfig = {
// authType: 'invalid-type'
// };When you uncomment the error example and run npm run test:types, you'll see:
error TS2322: Type '"invalid-type"' is not assignable to type 'basic' | 'digest' | ...
This confirms your types are working correctly!
- Create a
.test.tsfile in this directory - Use
/// <reference path="../marklogic.d.ts" />to load types - Import types with:
type MyType = import('marklogic').MyType; - Write code that should compile (or intentionally fail)
- Run
npm run test:typesto verify
- Create a
.test.tsfile in this directory - Use the same reference and import pattern as above
- Import test framework:
import should = require('should'); - Use
describe/itblocks like normal mocha tests - Make actual API calls to MarkLogic
- Compile with
npm run test:compileand run with mocha
Note: Compiled .js files are gitignored and regenerated on each test run.