|
1 | | -const path = require("path"); |
2 | | -const childProcess = require("child_process"); |
| 1 | +const path = require('path'); |
| 2 | +const childProcess = require('child_process'); |
3 | 3 |
|
4 | | -describe("server", () => { |
| 4 | +function mock(name) { |
| 5 | + return path.join(__dirname, '..', '__mocks__', name); |
| 6 | +} |
| 7 | + |
| 8 | +describe('server', () => { |
5 | 9 | let proc; |
6 | 10 |
|
7 | 11 | beforeEach(() => { |
8 | | - proc = childProcess.spawn(path.join(__dirname, "..", "cli.js"), { |
9 | | - stdio: "pipe" |
| 12 | + proc = childProcess.spawn(path.join(__dirname, '..', 'cli.js'), { |
| 13 | + stdio: 'pipe' |
10 | 14 | }); |
11 | 15 | }); |
12 | 16 |
|
13 | 17 | afterEach(() => { |
14 | 18 | proc.kill(); |
15 | 19 | }); |
16 | 20 |
|
17 | | - it("throws an error when component is missing", done => { |
| 21 | + it('throws an error when component is missing', done => { |
18 | 22 | proc.stdin.write(JSON.stringify({})); |
19 | 23 |
|
20 | | - proc.stdout.once("data", out => { |
21 | | - expect(JSON.parse(out).error).toEqual("Missing { component } in request"); |
| 24 | + proc.stdout.once('data', out => { |
| 25 | + expect(JSON.parse(out).error).toEqual('Missing { component } in request'); |
22 | 26 | done(); |
23 | 27 | }); |
24 | 28 | }); |
25 | 29 |
|
26 | | - it("throws an error when component cannot be found", done => { |
27 | | - proc.stdin.write(JSON.stringify({ component: "component.js" })); |
| 30 | + it('throws an error when component cannot be found', done => { |
| 31 | + proc.stdin.write(JSON.stringify({ component: 'component.js' })); |
28 | 32 |
|
29 | | - proc.stdout.once("data", out => { |
| 33 | + proc.stdout.once('data', out => { |
30 | 34 | expect(JSON.parse(out).error).toEqual( |
31 | | - "Cannot load component: component.js" |
| 35 | + 'Cannot load component: component.js' |
32 | 36 | ); |
33 | 37 | done(); |
34 | 38 | }); |
35 | 39 | }); |
36 | 40 |
|
37 | | - it("renders the component", done => { |
| 41 | + it('renders the component', done => { |
38 | 42 | proc.stdin.write( |
39 | 43 | JSON.stringify({ |
40 | | - component: path.join(__dirname, "mocks", "testComponent.js") |
| 44 | + component: mock('TestComponent.js') |
41 | 45 | }) |
42 | 46 | ); |
43 | 47 |
|
44 | | - proc.stdout.once("data", out => { |
45 | | - expect(JSON.parse(out).html).toMatch("I am a test component"); |
| 48 | + proc.stdout.once('data', out => { |
| 49 | + expect(JSON.parse(out).html).toMatch('I am a test component'); |
46 | 50 | done(); |
47 | 51 | }); |
48 | 52 | }); |
49 | 53 |
|
50 | | - it("renders a component and exposes additional context", done => { |
| 54 | + it('renders a component and exposes additional context', done => { |
51 | 55 | proc.stdin.write( |
52 | 56 | JSON.stringify({ |
53 | | - component: path.join(__dirname, "mocks", "contextComponent.js") |
| 57 | + component: mock('ContextComponent.js') |
54 | 58 | }) |
55 | 59 | ); |
56 | 60 |
|
57 | | - proc.stdout.once("data", out => { |
| 61 | + proc.stdout.once('data', out => { |
58 | 62 | const result = JSON.parse(out); |
59 | | - expect(result.html).toMatch("I am a context component"); |
| 63 | + expect(result.html).toMatch('I am a context component'); |
60 | 64 | expect(result.context).toEqual({ test: true }); |
61 | 65 | done(); |
62 | 66 | }); |
|
0 commit comments