masklinn committed 41a7605

Replace tempfile for IPC communication by straightforward stdout-reading

Comments (0)

Files changed (2)


 var fs = require('fs');
-// The temporary file used for communications.
-var tmpfile = phantom.args[0];
 // The page .html file to load.
-var url = phantom.args[1];
+var url = phantom.args[0];
 // Extra, optionally overridable stuff.
-var options = JSON.parse(phantom.args[2] || {});
+var options = JSON.parse(phantom.args[1] || {});
 // Default options.
 if (!options.timeout) { options.timeout = 5000; }
 var sendMessage = function(arg) {
   var args = Array.isArray(arg) ? arg : [];
   last = new Date();
-  fs.write(tmpfile, JSON.stringify(args) + '\n', 'a');
+  console.log(JSON.stringify(args));
 // This allows grunt to abort if the PhantomJS version isn't adequate.


     def run(self, result):
         result._exc_info_to_string = _exc_info_to_string
-            # Create IPC file
-            # FIXME: not sure if mkstemp or NamedTemporaryFile can be used to have an other process write in the file
-            path = tempfile.mktemp()
-            # Ensure file exists
-            with open(path, 'a'): pass
-            try:
-                with open(path, 'r') as pipe:
-                    self._run(pipe, result)
-            finally:
-                os.remove(path)
+            self._run(result)
             del result._exc_info_to_string
-    def _run(self, pipe, result):
+    def _run(self, result):
         phantom = subprocess.Popen([
             '--config=%s' % os.path.join(ROOT, 'phantomjs.json'),
-            os.path.join(ROOT, 'bootstrap.js'),
-  , self.testfile,
+            os.path.join(ROOT, 'bootstrap.js'), self.testfile,
                 'timeout': self.timeout,
                 'inject': os.path.join(ROOT, 'qunit-phantomjs-bridge.js')
-        ])
+        ], stdout=subprocess.PIPE)
         while True:
-            line = pipe.readline()
+            line = phantom.stdout.readline()
             if line:
                 if self.process(line, result):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.