Skip to content

Commit b58ec54

Browse files
committed
Update test folder structure
1 parent f37a910 commit b58ec54

File tree

8 files changed

+2956
-91
lines changed

8 files changed

+2956
-91
lines changed

__mocks__/contextComponent.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

__mocks__/testComponent.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

__tests__/mocks/contextComponent.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const React = require("react");
2+
3+
let context = {};
4+
5+
const component = function() {
6+
context.test = true;
7+
return React.createElement("div", null, "I am a context component");
8+
};
9+
10+
component.context = context;
11+
12+
module.exports = component;

__tests__/mocks/testComponent.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const React = require("react");
2+
3+
module.exports = function() {
4+
return React.createElement("div", null, "I am a test component");
5+
};

__tests__/server-test.js

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

__tests__/server.spec.js

Lines changed: 0 additions & 74 deletions
This file was deleted.

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@
2626
"react-dom": "^15.0.1"
2727
},
2828
"devDependencies": {
29-
"jest": "^21.2.1",
29+
"jest": "^22.1.4",
3030
"readline-sync": "^1.4.1"
31+
},
32+
"jest": {
33+
"testPathIgnorePatterns": [
34+
"/node_modules/",
35+
"__tests__/mocks"
36+
]
3137
}
3238
}

0 commit comments

Comments
 (0)