Skip to content

Commit ab0ad6d

Browse files
committed
Refactor microsyntax test
1 parent 8476c16 commit ab0ad6d

File tree

1 file changed

+60
-24
lines changed

1 file changed

+60
-24
lines changed

tests/transform-microsyntax.test.ts

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,68 @@
11
import type * as babel from '@babel/types';
22

33
import { parseTemplateBindings } from '../src/index.js';
4-
import type { NGMicrosyntaxKeyedExpression } from '../src/types.js';
4+
import type {
5+
NGMicrosyntaxKeyedExpression,
6+
NGMicrosyntaxNode,
7+
} from '../src/types.js';
58
import { snapshotAst } from './helpers.js';
69

7-
test.each`
8-
input | types
9-
${''} | ${[]}
10-
${' let hero '} | ${['NGMicrosyntaxLet']}
11-
${' let hero = hello '} | ${['NGMicrosyntaxLet']}
12-
${' let hero of heroes '} | ${['NGMicrosyntaxLet', 'NGMicrosyntaxKeyedExpression']}
13-
${' let hero ; of : heroes '} | ${['NGMicrosyntaxLet', 'NGMicrosyntaxKeyedExpression']}
14-
${' as b '} | ${['NGMicrosyntaxAs']}
15-
${' a '} | ${['NGMicrosyntaxExpression']}
16-
${' a as b '} | ${['NGMicrosyntaxExpression']}
17-
${' a , b '} | ${['NGMicrosyntaxExpression', 'NGMicrosyntaxKey']}
18-
${' a ; b '} | ${['NGMicrosyntaxExpression', 'NGMicrosyntaxKey']}
19-
${' a ; b c '} | ${['NGMicrosyntaxExpression', 'NGMicrosyntaxKeyedExpression']}
20-
${' a ; b : c '} | ${['NGMicrosyntaxExpression', 'NGMicrosyntaxKeyedExpression']}
21-
${' a ; b : c as d '} | ${['NGMicrosyntaxExpression', 'NGMicrosyntaxKeyedExpression']}
22-
${' a ; b as c '} | ${['NGMicrosyntaxExpression', 'NGMicrosyntaxAs']}
23-
${' let "a" = "b" ; "c" as "d" '} | ${['NGMicrosyntaxLet', 'NGMicrosyntaxAs']}
24-
${' let "\\"" '} | ${['NGMicrosyntaxLet']}
25-
`('$input', ({ input, types }) => {
26-
const ast = parseTemplateBindings(input);
27-
expect(snapshotAst(ast, input)).toMatchSnapshot();
28-
expect(ast.body.map((node) => node.type)).toEqual(types);
29-
});
10+
const testCases: {
11+
input: string;
12+
types: NGMicrosyntaxNode['type'][];
13+
only?: true;
14+
}[] = [
15+
{ input: '', types: [] },
16+
{ input: ' let hero ', types: ['NGMicrosyntaxLet'] },
17+
{ input: ' let hero = hello ', types: ['NGMicrosyntaxLet'] },
18+
{
19+
input: ' let hero of heroes ',
20+
types: ['NGMicrosyntaxLet', 'NGMicrosyntaxKeyedExpression'],
21+
},
22+
{
23+
input: ' let hero ; of : heroes ',
24+
types: ['NGMicrosyntaxLet', 'NGMicrosyntaxKeyedExpression'],
25+
},
26+
{ input: ' as b ', types: ['NGMicrosyntaxAs'] },
27+
{ input: ' a ', types: ['NGMicrosyntaxExpression'] },
28+
{ input: ' a as b ', types: ['NGMicrosyntaxExpression'] },
29+
{ input: ' a , b ', types: ['NGMicrosyntaxExpression', 'NGMicrosyntaxKey'] },
30+
{ input: ' a ; b ', types: ['NGMicrosyntaxExpression', 'NGMicrosyntaxKey'] },
31+
{
32+
input: ' a ; b c ',
33+
types: ['NGMicrosyntaxExpression', 'NGMicrosyntaxKeyedExpression'],
34+
},
35+
{
36+
input: ' a ; b : c ',
37+
types: ['NGMicrosyntaxExpression', 'NGMicrosyntaxKeyedExpression'],
38+
},
39+
{
40+
input: ' a ; b : c as d ',
41+
types: ['NGMicrosyntaxExpression', 'NGMicrosyntaxKeyedExpression'],
42+
},
43+
{
44+
input: ' a ; b as c ',
45+
types: ['NGMicrosyntaxExpression', 'NGMicrosyntaxAs'],
46+
},
47+
{
48+
input: ' let "a" = "b" ; "c" as "d" ',
49+
types: ['NGMicrosyntaxLet', 'NGMicrosyntaxAs'],
50+
},
51+
{ input: ' let "\\"" ', types: ['NGMicrosyntaxLet'] },
52+
];
53+
54+
const IS_CI = Boolean(process.env.CI);
55+
for (const { input, types, only } of testCases) {
56+
if (IS_CI && only) {
57+
throw new Error(`Unexpected 'only' property`);
58+
}
59+
60+
(only ? test.only : test)(`'${input}'`, () => {
61+
const ast = parseTemplateBindings(input);
62+
expect(snapshotAst(ast, input)).toMatchSnapshot();
63+
expect(ast.body.map((node) => node.type)).toEqual(types);
64+
});
65+
}
3066

3167
test('Shorthand', () => {
3268
const code = 'someTmpl; context: {app}';

0 commit comments

Comments
 (0)