Skip to content

Commit e59283d

Browse files
authored
Make tests more readable by formatting JS output (#72)
1 parent 8c3a3d6 commit e59283d

13 files changed

+338
-105
lines changed

src/__tests__/__snapshots__/attributes-shorthand.test.js.snap

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`JavaScript output: transformed source code 1`] = `"module.exports = <div data-first={true} data-second={true} data-positive={true} data-negative={false} data-check={true}><div data-one={true} data-two={true} /></div>;"`;
3+
exports[`JavaScript output: transformed source code 1`] = `
4+
"module.exports = (
5+
<div
6+
data-first={true}
7+
data-second={true}
8+
data-positive={true}
9+
data-negative={false}
10+
data-check={true}
11+
>
12+
<div data-one={true} data-two={true} />
13+
</div>
14+
);
15+
"
16+
`;
417

518
exports[`html output: generated html 1`] = `
619
<div

src/__tests__/__snapshots__/attributes-transformation.test.js.snap

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,32 @@
22

33
exports[`JavaScript output: transformed source code 1`] = `
44
"const object = {
5-
first: 'one-in-object',
6-
second: 'two-in-object'
5+
first: \\"one-in-object\\",
6+
second: \\"two-in-object\\"
77
};
88
9-
const array = ['arr-one', 'arr-two'];
9+
const array = [\\"arr-one\\", \\"arr-two\\"];
1010
11-
module.exports = <div><div className=\\"one two\\" /><div className=\\"one two\\" /><div className={100} /><div className={array} /><div className={object} /><div className={['one', 'two']} /><div className={['one', 'two'].join(' ')} /><div className={{ first: true }} /><div className=\\"mix one two\\" /><div className={'mix ' + 100} /><div className={'mix ' + array} /><div className={'mix ' + object} /><div className={['mix', 'one', 'two']} /><div className={'mix ' + ['one', 'two'].join(' ')} /><div className={'mix ' + { first: true }} /></div>;"
11+
module.exports = (
12+
<div>
13+
<div className=\\"one two\\" />
14+
<div className=\\"one two\\" />
15+
<div className={100} />
16+
<div className={array} />
17+
<div className={object} />
18+
<div className={[\\"one\\", \\"two\\"]} />
19+
<div className={[\\"one\\", \\"two\\"].join(\\" \\")} />
20+
<div className={{ first: true }} />
21+
<div className=\\"mix one two\\" />
22+
<div className={\\"mix \\" + 100} />
23+
<div className={\\"mix \\" + array} />
24+
<div className={\\"mix \\" + object} />
25+
<div className={[\\"mix\\", \\"one\\", \\"two\\"]} />
26+
<div className={\\"mix \\" + [\\"one\\", \\"two\\"].join(\\" \\")} />
27+
<div className={\\"mix \\" + { first: true }} />
28+
</div>
29+
);
30+
"
1231
`;
1332

1433
exports[`html output: generated html 1`] = `

src/__tests__/__snapshots__/each-else.test.js.snap

Lines changed: 62 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,74 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`JavaScript output: transformed source code 1`] = `
4-
"module.exports = <div>{((_pug_nodes, _pug_arr) => {
5-
if (!(_pug_arr == null || Array.isArray(_pug_arr))) throw new Error(\\"Expected \\\\\\"[[1, 2, 3], [], null]\\\\\\" to be an array because it is passed to each.\\");
6-
if (_pug_arr == null || _pug_arr.length === 0) return undefined;
4+
"module.exports = (
5+
<div>
6+
{((_pug_nodes, _pug_arr) => {
7+
if (!(_pug_arr == null || Array.isArray(_pug_arr)))
8+
throw new Error(
9+
'Expected \\"[[1, 2, 3], [], null]\\" to be an array because it is passed to each.'
10+
);
11+
if (_pug_arr == null || _pug_arr.length === 0) return undefined;
712
8-
for (let i = 0; i < _pug_arr.length; i++) {
9-
const list = _pug_arr[i];
10-
_pug_nodes[_pug_nodes.length] = <div key={\\"pug\\" + i + \\":0\\"}>{((_pug_nodes2, _pug_arr2) => {
11-
if (!(_pug_arr2 == null || Array.isArray(_pug_arr2))) throw new Error(\\"Expected \\\\\\"list\\\\\\" to be an array because it is passed to each.\\");
12-
if (_pug_arr2 == null || _pug_arr2.length === 0) return \\"No items in this list\\";
13+
for (let i = 0; i < _pug_arr.length; i++) {
14+
const list = _pug_arr[i];
15+
_pug_nodes[_pug_nodes.length] = (
16+
<div key={\\"pug\\" + i + \\":0\\"}>
17+
{((_pug_nodes2, _pug_arr2) => {
18+
if (!(_pug_arr2 == null || Array.isArray(_pug_arr2)))
19+
throw new Error(
20+
'Expected \\"list\\" to be an array because it is passed to each.'
21+
);
22+
if (_pug_arr2 == null || _pug_arr2.length === 0)
23+
return \\"No items in this list\\";
1324
14-
for (let _pug_index = 0; _pug_index < _pug_arr2.length; _pug_index++) {
15-
const item = _pug_arr2[_pug_index];
16-
_pug_nodes2[_pug_nodes2.length] = <span key={\\"pug\\" + item + \\":0\\"}>{item}</span>;
17-
}
25+
for (
26+
let _pug_index = 0;
27+
_pug_index < _pug_arr2.length;
28+
_pug_index++
29+
) {
30+
const item = _pug_arr2[_pug_index];
31+
_pug_nodes2[_pug_nodes2.length] = (
32+
<span key={\\"pug\\" + item + \\":0\\"}>{item}</span>
33+
);
34+
}
1835
19-
return _pug_nodes2;
20-
})([], list)}{((_pug_nodes3, _pug_arr3) => {
21-
if (!(_pug_arr3 == null || Array.isArray(_pug_arr3))) throw new Error(\\"Expected \\\\\\"list\\\\\\" to be an array because it is passed to each.\\");
22-
if (_pug_arr3 == null || _pug_arr3.length === 0) return [\\"This is \\", <strong key=\\"pug:1:0\\">literally</strong>, \\" the same list!\\"];
36+
return _pug_nodes2;
37+
})([], list)}
38+
{((_pug_nodes3, _pug_arr3) => {
39+
if (!(_pug_arr3 == null || Array.isArray(_pug_arr3)))
40+
throw new Error(
41+
'Expected \\"list\\" to be an array because it is passed to each.'
42+
);
43+
if (_pug_arr3 == null || _pug_arr3.length === 0)
44+
return [
45+
\\"This is \\",
46+
<strong key=\\"pug:1:0\\">literally</strong>,
47+
\\" the same list!\\"
48+
];
2349
24-
for (let _pug_index2 = 0; _pug_index2 < _pug_arr3.length; _pug_index2++) {
25-
const item = _pug_arr3[_pug_index2];
26-
_pug_nodes3[_pug_nodes3.length] = <span key={\\"pug\\" + item + \\":0\\"}>{item}</span>;
27-
}
50+
for (
51+
let _pug_index2 = 0;
52+
_pug_index2 < _pug_arr3.length;
53+
_pug_index2++
54+
) {
55+
const item = _pug_arr3[_pug_index2];
56+
_pug_nodes3[_pug_nodes3.length] = (
57+
<span key={\\"pug\\" + item + \\":0\\"}>{item}</span>
58+
);
59+
}
2860
29-
return _pug_nodes3;
30-
})([], list)}</div>;
31-
}
61+
return _pug_nodes3;
62+
})([], list)}
63+
</div>
64+
);
65+
}
3266
33-
return _pug_nodes;
34-
})([], [[1, 2, 3], [], null])}</div>;"
67+
return _pug_nodes;
68+
})([], [[1, 2, 3], [], null])}
69+
</div>
70+
);
71+
"
3572
`;
3673
3774
exports[`html output: generated html 1`] = `

src/__tests__/__snapshots__/if-else.test.js.snap

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,35 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`JavaScript output: transformed source code 1`] = `
4-
"module.exports = <div>{((_pug_nodes, _pug_arr) => {
5-
if (!(_pug_arr == null || Array.isArray(_pug_arr))) throw new Error(\\"Expected \\\\\\"[1, 2, 3]\\\\\\" to be an array because it is passed to each.\\");
6-
if (_pug_arr == null || _pug_arr.length === 0) return undefined;
4+
"module.exports = (
5+
<div>
6+
{((_pug_nodes, _pug_arr) => {
7+
if (!(_pug_arr == null || Array.isArray(_pug_arr)))
8+
throw new Error(
9+
'Expected \\"[1, 2, 3]\\" to be an array because it is passed to each.'
10+
);
11+
if (_pug_arr == null || _pug_arr.length === 0) return undefined;
712
8-
for (let i = 0; i < _pug_arr.length; i++) {
9-
const v = _pug_arr[i];
10-
_pug_nodes[_pug_nodes.length] = <div key={\\"pug\\" + i + \\":0\\"}>{v === 1 ? \\"One\\" : v === 2 ? \\"Two\\" : \\"Many\\"}{v === 3 ? [<strong key=\\"pug:2:0\\">Three</strong>, \\"is the magic number!\\"] : undefined}{v == 2 ? undefined : [<strong key=\\"pug:5:0\\">Definitely</strong>, \\"not 2\\"]}</div>;
11-
}
13+
for (let i = 0; i < _pug_arr.length; i++) {
14+
const v = _pug_arr[i];
15+
_pug_nodes[_pug_nodes.length] = (
16+
<div key={\\"pug\\" + i + \\":0\\"}>
17+
{v === 1 ? \\"One\\" : v === 2 ? \\"Two\\" : \\"Many\\"}
18+
{v === 3
19+
? [<strong key=\\"pug:2:0\\">Three</strong>, \\"is the magic number!\\"]
20+
: undefined}
21+
{v == 2
22+
? undefined
23+
: [<strong key=\\"pug:5:0\\">Definitely</strong>, \\"not 2\\"]}
24+
</div>
25+
);
26+
}
1227
13-
return _pug_nodes;
14-
})([], [1, 2, 3])}</div>;"
28+
return _pug_nodes;
29+
})([], [1, 2, 3])}
30+
</div>
31+
);
32+
"
1533
`;
1634
1735
exports[`html output: generated html 1`] = `

src/__tests__/__snapshots__/interpolation.test.js.snap

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,38 @@
22

33
exports[`JavaScript output: transformed source code 1`] = `
44
"function Person({ name }) {
5-
return <div className=\\"person person__profile\\"><h2>{['My name is ', name].join('')}</h2></div>;
5+
return (
6+
<div className=\\"person person__profile\\">
7+
<h2>{[\\"My name is \\", name].join(\\"\\")}</h2>
8+
</div>
9+
);
610
}
711
8-
module.exports = new function () {
9-
this.message = 'Hello everyone';
10-
this.names = ['jack', 'john'];
12+
module.exports = new function() {
13+
this.message = \\"Hello everyone\\";
14+
this.names = [\\"jack\\", \\"john\\"];
1115
const showFirstPerson = true;
1216
13-
return <div className=\\"people people__container\\"><h1>{this.message}</h1><p>Here is a list of people that you might want to follow,{\\"\\\\n\\"}{['one being ', this.names[1], '!'].join('')}</p>{showFirstPerson ? <Person name={this.names[0]} key=\\"pug:0:0\\" /> : undefined}{this.names.map((name, key) => <p key={key}>{['Hi ', name, ', bye ', name].join('')}</p>)}</div>;
14-
}();"
17+
return (
18+
<div className=\\"people people__container\\">
19+
<h1>{this.message}</h1>
20+
<p>
21+
Here is a list of people that you might want to follow,
22+
{\\"\\\\n\\"}
23+
{[\\"one being \\", this.names[1], \\"!\\"].join(\\"\\")}
24+
</p>
25+
{showFirstPerson ? (
26+
<Person name={this.names[0]} key=\\"pug:0:0\\" />
27+
) : (
28+
undefined
29+
)}
30+
{this.names.map((name, key) => (
31+
<p key={key}>{[\\"Hi \\", name, \\", bye \\", name].join(\\"\\")}</p>
32+
))}
33+
</div>
34+
);
35+
}();
36+
"
1537
`;
1638
1739
exports[`html output: generated html 1`] = `

src/__tests__/__snapshots__/multi-line-plain-text.test.js.snap

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`JavaScript output: transformed source code 1`] = `"module.exports = <div>foo{\\"\\\\n\\"}bar</div>;"`;
3+
exports[`JavaScript output: transformed source code 1`] = `
4+
"module.exports = (
5+
<div>
6+
foo
7+
{\\"\\\\n\\"}
8+
bar
9+
</div>
10+
);
11+
"
12+
`;
413

514
exports[`html output: generated html 1`] = `
615
<div>

src/__tests__/__snapshots__/nested-loops.test.js.snap

Lines changed: 59 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,74 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`JavaScript output: transformed source code 1`] = `
4-
"module.exports = <div>{((_pug_nodes, _pug_arr) => {
5-
if (!(_pug_arr == null || Array.isArray(_pug_arr))) throw new Error(\\"Expected \\\\\\"[1,2,3]\\\\\\" to be an array because it is passed to each.\\");
6-
if (_pug_arr == null || _pug_arr.length === 0) return undefined;
4+
"module.exports = (
5+
<div>
6+
{((_pug_nodes, _pug_arr) => {
7+
if (!(_pug_arr == null || Array.isArray(_pug_arr)))
8+
throw new Error(
9+
'Expected \\"[1,2,3]\\" to be an array because it is passed to each.'
10+
);
11+
if (_pug_arr == null || _pug_arr.length === 0) return undefined;
712
8-
for (let _pug_index = 0; _pug_index < _pug_arr.length; _pug_index++) {
9-
let _name;
13+
for (let _pug_index = 0; _pug_index < _pug_arr.length; _pug_index++) {
14+
let _name;
1015
11-
const a = _pug_arr[_pug_index];
12-
_pug_nodes[_pug_nodes.length] = (_name = 'a', undefined);
13-
_pug_nodes[_pug_nodes.length] = <div key={\\"pug\\" + a + \\":0\\"}>{_name + ':' + a}{((_pug_nodes2, _pug_arr2) => {
14-
if (!(_pug_arr2 == null || Array.isArray(_pug_arr2))) throw new Error(\\"Expected \\\\\\"[1,2,3]\\\\\\" to be an array because it is passed to each.\\");
15-
if (_pug_arr2 == null || _pug_arr2.length === 0) return undefined;
16+
const a = _pug_arr[_pug_index];
17+
_pug_nodes[_pug_nodes.length] = ((_name = \\"a\\"), undefined);
18+
_pug_nodes[_pug_nodes.length] = (
19+
<div key={\\"pug\\" + a + \\":0\\"}>
20+
{_name + \\":\\" + a}
21+
{((_pug_nodes2, _pug_arr2) => {
22+
if (!(_pug_arr2 == null || Array.isArray(_pug_arr2)))
23+
throw new Error(
24+
'Expected \\"[1,2,3]\\" to be an array because it is passed to each.'
25+
);
26+
if (_pug_arr2 == null || _pug_arr2.length === 0) return undefined;
1627
17-
for (let _pug_index2 = 0; _pug_index2 < _pug_arr2.length; _pug_index2++) {
18-
let _name2;
28+
for (
29+
let _pug_index2 = 0;
30+
_pug_index2 < _pug_arr2.length;
31+
_pug_index2++
32+
) {
33+
let _name2;
1934
20-
const b = _pug_arr2[_pug_index2];
21-
_pug_nodes2[_pug_nodes2.length] = (_name2 = 'b', undefined);
22-
_pug_nodes2[_pug_nodes2.length] = <div key={\\"pug\\" + b + \\":0\\"}>{_name2 + ':' + b}</div>;
23-
}
35+
const b = _pug_arr2[_pug_index2];
36+
_pug_nodes2[_pug_nodes2.length] = ((_name2 = \\"b\\"), undefined);
37+
_pug_nodes2[_pug_nodes2.length] = (
38+
<div key={\\"pug\\" + b + \\":0\\"}>{_name2 + \\":\\" + b}</div>
39+
);
40+
}
2441
25-
return _pug_nodes2;
26-
})([], [1, 2, 3])}{((_pug_nodes3, _pug_arr3) => {
27-
if (!(_pug_arr3 == null || Array.isArray(_pug_arr3))) throw new Error(\\"Expected \\\\\\"[1,2,3]\\\\\\" to be an array because it is passed to each.\\");
28-
if (_pug_arr3 == null || _pug_arr3.length === 0) return undefined;
42+
return _pug_nodes2;
43+
})([], [1, 2, 3])}
44+
{((_pug_nodes3, _pug_arr3) => {
45+
if (!(_pug_arr3 == null || Array.isArray(_pug_arr3)))
46+
throw new Error(
47+
'Expected \\"[1,2,3]\\" to be an array because it is passed to each.'
48+
);
49+
if (_pug_arr3 == null || _pug_arr3.length === 0) return undefined;
2950
30-
for (let i = 0; i < _pug_arr3.length; i++) {
31-
let _name3;
51+
for (let i = 0; i < _pug_arr3.length; i++) {
52+
let _name3;
3253
33-
const c = _pug_arr3[i];
34-
_pug_nodes3[_pug_nodes3.length] = (_name3 = 'c', undefined);
35-
_pug_nodes3[_pug_nodes3.length] = <div key={\\"pug\\" + c + \\":0\\"}>{_name3 + c}</div>;
36-
}
54+
const c = _pug_arr3[i];
55+
_pug_nodes3[_pug_nodes3.length] = ((_name3 = \\"c\\"), undefined);
56+
_pug_nodes3[_pug_nodes3.length] = (
57+
<div key={\\"pug\\" + c + \\":0\\"}>{_name3 + c}</div>
58+
);
59+
}
3760
38-
return _pug_nodes3;
39-
})([], [1, 2, 3])}</div>;
40-
}
61+
return _pug_nodes3;
62+
})([], [1, 2, 3])}
63+
</div>
64+
);
65+
}
4166
42-
return _pug_nodes;
43-
})([], [1, 2, 3])}</div>;"
67+
return _pug_nodes;
68+
})([], [1, 2, 3])}
69+
</div>
70+
);
71+
"
4472
`;
4573

4674
exports[`html output: generated html 1`] = `

0 commit comments

Comments
 (0)