-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransformFileContent_test.ts
85 lines (73 loc) · 2.08 KB
/
transformFileContent_test.ts
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { assertEquals } from 'jsr:@std/assert';
import { transformFileContent } from './transformFileContent.ts';
import type { ComponentInfo } from './types.ts';
Deno.test({
name: 'transformFileContent - replaces all case variations in content',
async fn() {
const testContent = `
import { Something } from './utils';
export const MyComponent = () => {
const myComponent = useMyComponent();
return <div className="my-component">
<span>{my_component}</span>
</div>;
};
export default MyComponent;
`;
const testFile = './test_component.tsx';
await Deno.writeTextFile(testFile, testContent);
const componentInfo: ComponentInfo = {
name: 'MyComponent',
variations: {
pascal: 'MyComponent',
camel: 'myComponent',
kebab: 'my-component',
snake: 'my_component',
},
};
const transformed = await transformFileContent(testFile, componentInfo);
// Clean up
await Deno.remove(testFile);
// Verify transformations
assertEquals(
transformed.includes('export const {{pascalCaseName}}'),
true,
'Should replace PascalCase'
);
assertEquals(
transformed.includes('const {{camelCaseName}}'),
true,
'Should replace camelCase'
);
assertEquals(
transformed.includes('className="{{kebabCaseName}}"'),
true,
'Should replace kebab-case'
);
assertEquals(
transformed.includes('{{{snakeCaseName}}}'),
true,
'Should replace snake_case'
);
},
});
Deno.test({
name: 'transformFileContent - handles files with no matches',
async fn() {
const testContent = 'No component names here!';
const testFile = './test_no_matches.ts';
await Deno.writeTextFile(testFile, testContent);
const componentInfo: ComponentInfo = {
name: 'MyComponent',
variations: {
pascal: 'MyComponent',
camel: 'myComponent',
kebab: 'my-component',
snake: 'my_component',
},
};
const transformed = await transformFileContent(testFile, componentInfo);
await Deno.remove(testFile);
assertEquals(transformed, testContent, 'Content should remain unchanged');
},
});