1 | const path = require('path');
|
2 | const assert = require('assert');
|
3 | const execFileSync = require('child_process').execFileSync;
|
4 | const mocha = require('mocha');
|
5 |
|
6 | const { describe, it } = mocha;
|
7 |
|
8 | const execCLI = input =>
|
9 | execFileSync(path.resolve(__dirname, '../../lib/cli.js'), {
|
10 | input,
|
11 | encoding: 'utf8',
|
12 | });
|
13 |
|
14 | describe('jsx', () => {
|
15 | it('jsx 1', () => {
|
16 | const input = `
|
17 | const App = () => (<div><span><a href="http://localhost/index.html">index</a></span></div>);
|
18 | `;
|
19 | const output = `
|
20 | const App = () => (
|
21 | <div>
|
22 | <span><a href="http://localhost/index.html">index</a></span>
|
23 | </div>
|
24 | );
|
25 | `;
|
26 | assert.equal(execCLI(input), output);
|
27 | });
|
28 |
|
29 | it('jsx 2', () => {
|
30 | const input = `
|
31 | const App = () => (<div><Component attribute1="value1" attribute2="value2" attribute3={{a:1,b:2,c:3}}>foo</Component></div>);
|
32 | `;
|
33 | const output = `
|
34 | const App = () => (
|
35 | <div>
|
36 | <Component
|
37 | attribute1="value1"
|
38 | attribute2="value2"
|
39 | attribute3={{ a: 1, b: 2, c: 3 }}
|
40 | >
|
41 | foo
|
42 | </Component>
|
43 | </div>
|
44 | );
|
45 | `;
|
46 | assert.equal(execCLI(input), output);
|
47 | });
|
48 |
|
49 | it('jsx 3', () => {
|
50 | const input = `
|
51 | const App = () => (<div><span><a href="http://wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww">link</a></span><span className="cccccccccccccccccccccccccccccccccccccccccccccccccccccc">{string}</span><span className="dddddddddddddddddddddddddddddddddddddddddddddddddddddd">value={value}</span></div>);
|
52 | `;
|
53 | const output = `
|
54 | const App = () => (
|
55 | <div>
|
56 | <span>
|
57 | <a href="http://wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww">link</a>
|
58 | </span>
|
59 | <span
|
60 | className="cccccccccccccccccccccccccccccccccccccccccccccccccccccc"
|
61 | >
|
62 | {string}
|
63 | </span>
|
64 | <span
|
65 | className="dddddddddddddddddddddddddddddddddddddddddddddddddddddd"
|
66 | >
|
67 | value={value}
|
68 | </span>
|
69 | </div>
|
70 | );
|
71 | `;
|
72 | assert.equal(execCLI(input), output);
|
73 | });
|
74 | });
|