@samitouri / QOS-React-2 / commits / 5beb481145
Fork 0

The library for web and native user interfaces.

Abandon <iframe> test isolation hack now that we have dumpCache.

This cuts the running time of `grunt phantom:run` from 4.4s to 3.1s on my machine, because we no longer have to load/execute a separate instance of `react-test.js` in a separate `<iframe>` for each test.

Ben Newman committed Jul 19, 2013 at 10:40 UTC 5beb48114567988b7abcedc74ddfaa7d718761d7
5 files changed +16 -45
grunt/config/populist.js
+1 -1
@@ -11,7 +11,7 @@ var jasmine = {
11
12 var test = {
13 rootDirectory: "build/modules",
14 - args: ["test/all:"],
14 + args: ["test/all:harness"],
15 requires: [
16 "**/__tests__/*-test.js"
17 ],
src/test/all.js
+4 -3
@@ -6,9 +6,6 @@ var Ap = Array.prototype;
6 var slice = Ap.slice;
7 var Fp = Function.prototype;
8
9 -var global = Function("return this")();
10 -global.require = require;
11 -
9 if (!Fp.bind) {
10 // PhantomJS doesn't support Function.prototype.bind natively, so
11 // polyfill it whenever this module is required.
@@ -58,3 +55,7 @@ require("reactComponentExpect");
55 require("mocks");
56 require("mock-modules");
57 require("./mock-timers");
58 +
59 +exports.enableTest = function(testID) {
60 + require("../" + testID);
61 +};
test/frame.html deleted
-18
@@ -1,18 +0,0 @@
1 -<!DOCTYPE html>
2 -<html>
3 - <head>
4 - <script>
5 - jasmine = parent.jasmine;
6 - jasmine.exposeFrom(window);
7 -
8 - console = parent.console;
9 - callPhantom = parent.callPhantom;
10 - </script>
11 - <script src="react-test.js"></script>
12 - </head>
13 - <body>
14 - <script>
15 - require(window.frameElement.getAttribute("test"));
16 - </script>
17 - </body>
18 -</html>
test/index.html
+5 -13
@@ -2,21 +2,13 @@
2 <html>
3 <head>
4 <link rel="stylesheet" type="text/css" href="jasmine.css" />
5 - <style type="text/css">
6 - iframe {
7 - visibility: hidden;
8 - position: absolute;
9 - left: -1000px;
10 - top: -1000px;
11 - }
12 - </style>
5 <script src="jasmine.js"></script>
14 - <script>
15 - window.onload = function() {
16 - jasmine.getEnv().execute();
17 - };
18 - </script>
6 + <script src="react-test.js"></script>
7 </head>
8 <body>
9 + <script>
10 + ENABLE_TESTS_HERE
11 + jasmine.getEnv().execute();
12 + </script>
13 </body>
14 </html>
test/phantom-harness.js
+6 -10
@@ -34,14 +34,13 @@ while (argv.length > 0) {
34 rest.push(arg);
35 }
36
37 -// Dynamically interpolate the individual test <iframe>s.
37 +// Dynamically enable the individual tests.
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>";
39 + /^(\s*)ENABLE_TESTS_HERE/m,
40 + function(placeholder, leadingSpace) {
41 + return leadingSpace + tests.map(function(testID) {
42 + return "harness.enableTest(" + JSON.stringify(testID) + ");";
43 + }).join("\n" + leadingSpace);
44 }
45 );
46
@@ -63,9 +62,6 @@ server.listen(port, function(req, res) {
62 file = "../build/" + file;
63 break;
64
66 - case "frame.html":
67 - break;
68 -
65 case "":
66 default:
67 file = "index.html";