Skip to content

Commit 4c3e717

Browse files
committed
test(import): add unit tests for entrypoint detection and runtime import handler
11 tests for extractEntrypoint covering otel wrappers, missing/empty arrays, multiple extensions, and extensionless entries. 8 tests for handleImportRuntime covering entrypoint failure, --entrypoint override, missing --code, nonexistent source path, and duplicate runtime names.
1 parent 8e463b7 commit 4c3e717

3 files changed

Lines changed: 420 additions & 1 deletion

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Tests for import runtime entrypoint detection and --entrypoint flag.
3+
*
4+
* Covers:
5+
* - extractEntrypoint: auto-detection from API entryPoint array
6+
* - --entrypoint flag override via handleImportRuntime
7+
* - Failure when entrypoint cannot be detected and no flag provided
8+
*/
9+
import { extractEntrypoint } from '../import-runtime';
10+
import { describe, expect, it } from 'vitest';
11+
12+
// ============================================================================
13+
// extractEntrypoint — unit tests
14+
// ============================================================================
15+
16+
describe('extractEntrypoint', () => {
17+
it('returns undefined for undefined input', () => {
18+
expect(extractEntrypoint(undefined)).toBeUndefined();
19+
});
20+
21+
it('returns undefined for empty array', () => {
22+
expect(extractEntrypoint([])).toBeUndefined();
23+
});
24+
25+
it('extracts .py file from otel wrapper array', () => {
26+
expect(extractEntrypoint(['opentelemetry-instrument', 'main.py'])).toBe('main.py');
27+
});
28+
29+
it('extracts .py file when it is the only element', () => {
30+
expect(extractEntrypoint(['main.py'])).toBe('main.py');
31+
});
32+
33+
it('returns undefined when only non-file entries exist', () => {
34+
expect(extractEntrypoint(['opentelemetry-instrument'])).toBeUndefined();
35+
});
36+
37+
it('returns undefined for entries without known extensions', () => {
38+
expect(extractEntrypoint(['gunicorn', 'flask-app'])).toBeUndefined();
39+
});
40+
41+
it('extracts .ts file', () => {
42+
expect(extractEntrypoint(['handler.ts'])).toBe('handler.ts');
43+
});
44+
45+
it('extracts .js file', () => {
46+
expect(extractEntrypoint(['index.js'])).toBe('index.js');
47+
});
48+
49+
it('picks the first matching file when multiple exist', () => {
50+
expect(extractEntrypoint(['wrapper', 'app.py', 'fallback.py'])).toBe('app.py');
51+
});
52+
53+
it('extracts file with path prefix', () => {
54+
expect(extractEntrypoint(['opentelemetry-instrument', 'src/main.py'])).toBe('src/main.py');
55+
});
56+
57+
it('returns undefined for extensionless entries', () => {
58+
expect(extractEntrypoint(['python', '-m', 'myapp'])).toBeUndefined();
59+
});
60+
});

0 commit comments

Comments
 (0)