Skip to content

Commit d119f6d

Browse files
authored
Standardized tests (#320)
chore: Standardized tests Co-authored-by: ijlee2 <ijlee2@users.noreply.github.com>
1 parent a2e2a4b commit d119f6d

6 files changed

Lines changed: 41 additions & 42 deletions

File tree

packages/ast/template/tests/helpers/handlebars.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
1-
export * from './handlebars.js';
1+
import { AST } from '../../src/index.js';
2+
3+
export function transform(file: string): string {
4+
const traverse = AST.traverse();
5+
6+
const ast = traverse(file, {
7+
AttrNode(node) {
8+
if (node.name !== 'local-class') {
9+
return;
10+
}
11+
12+
if (node.value.type === 'TextNode') {
13+
node.name = 'class';
14+
15+
const attributeValue = node.value.chars.trim();
16+
17+
node.value = AST.builders.mustache(
18+
AST.builders.path(`this.styles.${attributeValue}`),
19+
);
20+
}
21+
},
22+
});
23+
24+
return AST.print(ast);
25+
}
26+
27+
export function traverse(file: string): string {
28+
const traverse = AST.traverse();
29+
30+
const ast = traverse(file);
31+
32+
return AST.print(ast);
33+
}

packages/ast/template/tests/index/transform-base-case.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { assert, normalizeFile, test } from '@codemod-utils/tests';
22

3-
import { transformHandlebars } from '../helpers/index.js';
3+
import { transform } from '../helpers/index.js';
44

55
test('index > transform (base case)', function () {
66
const oldFile = normalizeFile([
@@ -10,7 +10,7 @@ test('index > transform (base case)', function () {
1010
`</div>`,
1111
]);
1212

13-
const newFile = transformHandlebars(oldFile);
13+
const newFile = transform(oldFile);
1414

1515
assert.strictEqual(
1616
newFile,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { assert, test } from '@codemod-utils/tests';
22

3-
import { transformHandlebars } from '../helpers/index.js';
3+
import { transform } from '../helpers/index.js';
44

55
test('index > transform (file is empty)', function () {
66
const oldFile = '';
77

8-
const newFile = transformHandlebars(oldFile);
8+
const newFile = transform(oldFile);
99

1010
assert.strictEqual(newFile, '');
1111
});

packages/ast/template/tests/index/traverse-base-case.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { assert, normalizeFile, test } from '@codemod-utils/tests';
22

3-
import { traverseHandlebars } from '../helpers/index.js';
3+
import { traverse } from '../helpers/index.js';
44

55
test('index > traverse (base case)', function () {
66
const oldFile = normalizeFile([
@@ -10,7 +10,7 @@ test('index > traverse (base case)', function () {
1010
`</div>`,
1111
]);
1212

13-
const newFile = traverseHandlebars(oldFile);
13+
const newFile = traverse(oldFile);
1414

1515
assert.strictEqual(
1616
newFile,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { assert, test } from '@codemod-utils/tests';
22

3-
import { traverseHandlebars } from '../helpers/index.js';
3+
import { traverse } from '../helpers/index.js';
44

55
test('index > traverse (file is empty)', function () {
66
const oldFile = '';
77

8-
const newFile = traverseHandlebars(oldFile);
8+
const newFile = traverse(oldFile);
99

1010
assert.strictEqual(newFile, '');
1111
});

0 commit comments

Comments
 (0)