-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch.test.ts
More file actions
50 lines (39 loc) · 1.41 KB
/
Copy pathpatch.test.ts
File metadata and controls
50 lines (39 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { describe, expect, it } from 'vitest';
import { computePatch } from '../src/rewriter/patch';
const createContext = (
content: string,
fromVersion: string,
toVersion: string,
): Parameters<typeof computePatch>[0] => ({
filePath: 'Dockerfile',
originalContent: content,
fromVersion,
toVersion,
});
describe('computePatch', () => {
it('replaces matching versions while preserving suffixes', () => {
const context = createContext(
'FROM python:3.12.5-slim\nARG PYTHON_VERSION="3.12.5"',
'3.12.5',
'3.12.6',
);
const result = computePatch(context);
expect(result.changed).toBe(true);
expect(result.updatedContent).toBe('FROM python:3.12.6-slim\nARG PYTHON_VERSION="3.12.6"');
expect(result.replacements).toHaveLength(2);
expect(result.fromVersion).toBe('3.12.5');
expect(result.toVersion).toBe('3.12.6');
});
it('ignores files without matches', () => {
const context = createContext('python=3.12.5', '3.13.1', '3.13.2');
const result = computePatch(context);
expect(result.changed).toBe(false);
expect(result.updatedContent).toBe(context.originalContent);
});
it('skips replacements when track differs', () => {
const context = createContext('python=3.12.5', '3.12.5', '3.13.1');
const result = computePatch(context);
expect(result.changed).toBe(false);
expect(result.updatedContent).toBe(context.originalContent);
});
});