Skip to content

Commit 5eca853

Browse files
committed
Fix failing tests
1 parent 76cd853 commit 5eca853

File tree

4 files changed

+35
-26
lines changed

4 files changed

+35
-26
lines changed

jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
testURL: 'http://localhost/'
3+
};

modules/__tests__/mocks/contextComponent.js renamed to modules/__mocks__/ContextComponent.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ const React = require("react");
22

33
let context = {};
44

5-
const component = function() {
5+
function ContextComponent() {
66
context.test = true;
77
return React.createElement("div", null, "I am a context component");
8-
};
8+
}
99

10-
component.context = context;
10+
ContextComponent.context = context;
1111

12-
module.exports = component;
12+
module.exports = ContextComponent;
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const React = require("react");
22

3-
module.exports = function() {
3+
function TestComponent() {
44
return React.createElement("div", null, "I am a test component");
5-
};
5+
}
6+
7+
module.exports = TestComponent;

modules/__tests__/server-test.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,66 @@
1-
const path = require("path");
2-
const childProcess = require("child_process");
1+
const path = require('path');
2+
const childProcess = require('child_process');
33

4-
describe("server", () => {
4+
function mock(name) {
5+
return path.join(__dirname, '..', '__mocks__', name);
6+
}
7+
8+
describe('server', () => {
59
let proc;
610

711
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'
1014
});
1115
});
1216

1317
afterEach(() => {
1418
proc.kill();
1519
});
1620

17-
it("throws an error when component is missing", done => {
21+
it('throws an error when component is missing', done => {
1822
proc.stdin.write(JSON.stringify({}));
1923

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');
2226
done();
2327
});
2428
});
2529

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' }));
2832

29-
proc.stdout.once("data", out => {
33+
proc.stdout.once('data', out => {
3034
expect(JSON.parse(out).error).toEqual(
31-
"Cannot load component: component.js"
35+
'Cannot load component: component.js'
3236
);
3337
done();
3438
});
3539
});
3640

37-
it("renders the component", done => {
41+
it('renders the component', done => {
3842
proc.stdin.write(
3943
JSON.stringify({
40-
component: path.join(__dirname, "mocks", "testComponent.js")
44+
component: mock('TestComponent.js')
4145
})
4246
);
4347

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');
4650
done();
4751
});
4852
});
4953

50-
it("renders a component and exposes additional context", done => {
54+
it('renders a component and exposes additional context', done => {
5155
proc.stdin.write(
5256
JSON.stringify({
53-
component: path.join(__dirname, "mocks", "contextComponent.js")
57+
component: mock('ContextComponent.js')
5458
})
5559
);
5660

57-
proc.stdout.once("data", out => {
61+
proc.stdout.once('data', out => {
5862
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');
6064
expect(result.context).toEqual({ test: true });
6165
done();
6266
});

0 commit comments

Comments
 (0)