This repository has been archived by the owner on Jun 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
index.js
80 lines (64 loc) · 2.23 KB
/
index.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
var fs = require('fs')
var path = require('path')
function serializeOption (value) {
if (typeof value === 'function') {
return value.toString()
}
return JSON.stringify(value)
}
var slimerDir = function () {
var slimerSource = require('slimerjs').path
return path.dirname(slimerSource)
}
var slimerJSExePath = function () {
return path.join(slimerDir(), '/xulrunner/xulrunner.exe')
}
var isWindows = function () {
return /^win/.test(process.platform)
}
var windowsFlags = function (tempDir) {
return [
'-app', path.join(slimerDir(), '/application.ini'),
'-profile', path.join(tempDir, '/slimerjs-profile'),
'-attach-console',
'-no-remote'
]
}
var SlimerJSBrowser = function (baseBrowserDecorator, config, args) {
baseBrowserDecorator(this)
var options = args && args.options || config && config.options || {}
var flags = args && args.flags || config && config.flags || []
this._start = function (url) {
// Create the js file that will open Karma
var captureFile = path.join(this._tempDir, '/capture.js')
var optionsCode = Object.keys(options).map(function (key) {
if (key !== 'settings') { // settings cannot be overridden, it should be extended!
return 'page.' + key + ' = ' + serializeOption(options[key]) + ';'
}
})
if (options.settings) {
optionsCode = optionsCode.concat(Object.keys(options.settings).map(function (key) {
return 'page.settings.' + key + ' = ' + serializeOption(options.settings[key]) + ';'
}))
}
var captureCode = 'var page = require("webpage").create();\n' +
optionsCode.join('\n') + '\npage.open("' + url + '");\n'
fs.writeFileSync(captureFile, captureCode)
if (isWindows()) flags = flags.concat(windowsFlags(this._tempDir))
flags = flags.concat(captureFile)
// Start SlimerJS
this._execCommand(this._getCommand(), flags)
}
}
SlimerJSBrowser.prototype = {
name: 'SlimerJS',
DEFAULT_CMD: {
linux: require('slimerjs').path,
darwin: require('slimerjs').path,
win32: slimerJSExePath()
},
ENV_CMD: 'SLIMERJS_BIN'
}
SlimerJSBrowser.$inject = ['baseBrowserDecorator', 'config.slimerjsLauncher', 'args']
// PUBLISH DI MODULE
module.exports = {'launcher:SlimerJS': ['type', SlimerJSBrowser]}