forked from DispatchMe/meteor-phantomjs-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
36 lines (28 loc) · 931 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const phantomjs = Npm.require('phantomjs-prebuilt');
const childProcess = Npm.require('child_process');
const PHANTOMJS_SCRIPT_FILE_NAME = 'phantomjsScript.js';
function startPhantom({
stdout,
stderr,
done,
}) {
const scriptPath = Assets.absoluteFilePath(PHANTOMJS_SCRIPT_FILE_NAME);
if (process.env.METEOR_PHANTOMJS_DEBUG) {
console.log('PhantomJS Path:', phantomjs.path);
console.log('PhantomJS Script Path:', scriptPath);
}
const phantomProcess = childProcess.execFile(phantomjs.path, [scriptPath], {
env: {
ROOT_URL: process.env.ROOT_URL,
},
});
phantomProcess.on('error', (error) => {
throw error;
});
phantomProcess.on('exit', done);
// The PhantomJS script echoes whatever the page prints to the browser console and
// here we echo that once again.
phantomProcess.stdout.on('data', stdout);
phantomProcess.stderr.on('data', stderr);
}
export { startPhantom };