@samitouri / QOS-React-2 / commits / 906b8f3f95
Fork 0

The library for web and native user interfaces.

Create testing <iframe>s dynamically, according to grunt config.

Ben Newman committed May 29, 2013 at 11:37 UTC 906b8f3f95c77482e432fec84f21c50381a68cf1
4 files changed +33 -43
grunt/config/phantom.js
+4 -1
@@ -4,5 +4,8 @@ exports.run = {
4 port: 8080,
5 harness: "test/phantom-harness.js",
6 // Run `grunt test --debug` to enable in-browser testing.
7 - debug: !!grunt.option("debug")
7 + debug: !!grunt.option("debug"),
8 + tests: [
9 + "**/__tests__/*-test.js"
10 + ]
11 };
grunt/tasks/phantom.js
+8
@@ -37,6 +37,14 @@ function run(config, done) {
37 args.push("--debug");
38 }
39
40 + args.push("--tests");
41 + var tests = grunt.file.expand({
42 + nonull: true,
43 + cwd: "src"
44 + }, config.tests || []).forEach(function(file) {
45 + args.push(file.replace(/\.js$/i, ""));
46 + });
47 +
48 var child = spawn({
49 cmd: phantomjs,
50 args: args
test/index.html
-38
@@ -18,43 +18,5 @@
18 </script>
19 </head>
20 <body>
21 - <iframe src="frame.html" test="core/__tests__/ReactBind-test"></iframe>
22 - <iframe src="frame.html" test="core/__tests__/ReactComponent-test"></iframe>
23 - <iframe src="frame.html" test="core/__tests__/ReactComponentLifeCycle-test"></iframe>
24 - <iframe src="frame.html" test="core/__tests__/ReactCompositeComponent-test"></iframe>
25 - <iframe src="frame.html" test="core/__tests__/ReactCompositeComponentDOMMinimalism-test"></iframe>
26 - <iframe src="frame.html" test="core/__tests__/ReactCompositeComponentMixin-test"></iframe>
27 - <iframe src="frame.html" test="core/__tests__/ReactCompositeComponentSpec-test"></iframe>
28 - <iframe src="frame.html" test="core/__tests__/ReactCompositeComponentState-test"></iframe>
29 - <iframe src="frame.html" test="core/__tests__/ReactCompositeComponentTransferProps-test"></iframe>
30 - <iframe src="frame.html" test="core/__tests__/ReactDOM-test"></iframe>
31 - <iframe src="frame.html" test="core/__tests__/ReactDOMIDOperations-test"></iframe>
32 - <iframe src="frame.html" test="core/__tests__/ReactEvent-test"></iframe>
33 - <iframe src="frame.html" test="core/__tests__/ReactIdentity-test"></iframe>
34 - <iframe src="frame.html" test="core/__tests__/ReactInstanceHandles-test"></iframe>
35 - <iframe src="frame.html" test="core/__tests__/ReactMountDestruction-test"></iframe>
36 - <iframe src="frame.html" test="core/__tests__/ReactMultiChildReconcile-test"></iframe>
37 - <iframe src="frame.html" test="core/__tests__/ReactMultiChildText-test"></iframe>
38 - <iframe src="frame.html" test="core/__tests__/ReactNativeComponent-test"></iframe>
39 - <iframe src="frame.html" test="core/__tests__/ReactProps-test"></iframe>
40 - <iframe src="frame.html" test="core/__tests__/ReactStateSetters-test"></iframe>
41 - <iframe src="frame.html" test="core/__tests__/refs-destruction-test"></iframe>
42 - <iframe src="frame.html" test="core/__tests__/refs-test"></iframe>
43 - <iframe src="frame.html" test="domUtils/__tests__/CSSPropertyOperations-test"></iframe>
44 - <iframe src="frame.html" test="domUtils/__tests__/DOMPropertyOperations-test"></iframe>
45 - <iframe src="frame.html" test="eventPlugins/__tests__/AnalyticsEventPlugin-test"></iframe>
46 - <iframe src="frame.html" test="eventPlugins/__tests__/ResponderEventPlugin-test"></iframe>
47 - <iframe src="frame.html" test="utils/__tests__/ImmutableObject-test"></iframe>
48 - <iframe src="frame.html" test="utils/__tests__/OrderedMap-test"></iframe>
49 - <iframe src="frame.html" test="utils/__tests__/Transaction-test"></iframe>
50 - <iframe src="frame.html" test="utils/__tests__/joinClasses-test"></iframe>
51 - <iframe src="frame.html" test="utils/__tests__/keyMirror-test"></iframe>
52 - <iframe src="frame.html" test="utils/__tests__/mapChildren-test"></iframe>
53 - <iframe src="frame.html" test="utils/__tests__/memoizeStringOnly-test"></iframe>
54 - <iframe src="frame.html" test="utils/__tests__/mergeFuncs-test"></iframe>
55 - <iframe src="frame.html" test="utils/__tests__/objFilter-test"></iframe>
56 - <iframe src="frame.html" test="utils/__tests__/objMap-test"></iframe>
57 - <iframe src="frame.html" test="vendor/error/__tests__/erx-test"></iframe>
58 - <iframe src="frame.html" test="vendor/error/__tests__/ex-test"></iframe>
21 </body>
22 </html>
test/phantom-harness.js
+21 -4
@@ -19,20 +19,36 @@ fs.changeWorkingDirectory(cwd);
19 // Hard to believe PhantomJS has no option parsing module.
20 var port = 8080;
21 var debug = false;
22 -var lastArg;
22 +var tests = [];
23 +var rest = [];
24 while (argv.length > 0) {
25 var arg = argv.pop();
26 if (arg === "--port") {
26 - port = +lastArg;
27 + port = +rest.pop();
28 } else if (arg === "--debug") {
29 debug = true;
30 + } else if (arg === "--tests") {
31 + while (rest.length > 0)
32 + tests.push(rest.pop());
33 }
30 - lastArg = arg;
34 + rest.push(arg);
35 }
36
37 +// Dynamically interpolate the individual test <iframe>s.
38 +var indexHtml = fs.read("index.html").replace(
39 + /<body>([\s\S]*?)<\/body>/im,
40 + function(outer, inner) {
41 + return "<body>" + tests.map(function(test) {
42 + return '\n <iframe src="frame.html" test=' +
43 + JSON.stringify(test) + '></iframe>';
44 + }).join("") + inner + "</body>";
45 + }
46 +);
47 +
48 var server = require("webserver").create();
49 server.listen(port, function(req, res) {
50 var file = req.url.replace(/^\/+/, "");
51 + var content;
52
53 switch (file) {
54 case "react-test.js":
@@ -53,6 +69,7 @@ server.listen(port, function(req, res) {
69 case "":
70 default:
71 file = "index.html";
72 + content = indexHtml; // Prevents calling fs.read again.
73 break;
74 }
75
@@ -65,7 +82,7 @@ server.listen(port, function(req, res) {
82 }
83
84 res.statusCode = 200;
68 - res.write(fs.read(file));
85 + res.write(content || fs.read(file));
86 res.close();
87 });
88