-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·156 lines (129 loc) · 4.63 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
const queue = require('queue')
const path = require('path')
const os = require('os')
const Sentry = require("@sentry/node");
require('dotenv').config()
const projectDir = process.cwd()
const diffToolDir = path.dirname(__filename)
const resourcesDir = path.join(diffToolDir, 'resources')
const templatesDir = path.join(resourcesDir, 'templates')
const configurationHelper = require('./lib/configurationHelper')(projectDir, diffToolDir)
const configuration = configurationHelper.configuration()
const options = configurationHelper.options(configuration)
const logLevels = ["debug", "log", "warn", "error", "none"];
if (configuration.setup.sentry && configuration.setup.sentry.cdnurl) {
global.logLevel = options.debug;
const Sentry = require("@sentry/node");
Sentry.init({
dsn: configuration.setup.sentry.cdnurl,
});
Sentry.addIntegration(Sentry.captureConsoleIntegration({levels: ['error']}));
} else {
require('better-logging')(console);
console.logLevel = logLevels.indexOf(options.debug)
}
require('events').EventEmitter.defaultMaxListeners = configuration.setup.maxListeners
process.removeAllListeners('warning');
let data = {
'baseUrl': configuration.setup.baseUrl ? configuration.setup.baseUrl : (path.resolve(configuration.setup.documentRoot) + '/'),
'projectPath': projectDir,
'resourcesPath': resourcesDir,
'allCss': path.join(resourcesDir, 'css/all.css'),
'specCss': ''
}
const templateHelper = require('./lib/templateHelper')(configuration, options, projectDir, diffToolDir, data)
const sitemap = require('./lib/sitemap')(configuration, options, projectDir)
const crawler = require('./lib/crawler')(configuration, options, projectDir)
const pdf = require('./lib/pdf')(templatesDir, data, templateHelper)
const screenshot = require('./lib/screenshot')(configuration, options, templateHelper, console)
// Error.stackTraceLimit = options.debug
let browser = [] // array for browserobjects
let browserNames = [] // array contains list of browsernames to process
let sequencesNames = []
let q = queue()
q.concurrency = options.conc
q.autostart = 1
q.on('success', function () {
console.log('remaining: ' + q.length)
})
q.on('end', async function () {
if (options.sequence === '_all_') {
for (var key in configuration.sequences) {
sequencesNames.push(key)
}
} else {
options.sequence.split(',').forEach((sequence) =>
sequencesNames.push(sequence)
)
}
let tempDir = path.resolve(configuration.setup.documentRoot, 'Html')
templateHelper.createDiffList(tempDir, templatesDir, browserNames, data, sequencesNames)
console.log('runtests - ', 'finished')
for (let sequenceName of sequencesNames) {
for (let browserName of configuration.sequences[sequenceName].browser) {
browser[sequenceName][browserName].browser.close()
}
}
let openCommand = 'xdg-open'
switch (os.plattform) {
case 'darwin':
openCommand = 'open'
break
case 'win32':
openCommand = 'start'
break
}
global.console.log(openCommand + ' ' + data.baseUrl + path.join('Html', 'index.html'))
})
function run() {
if (options.sequence === '_all_') {
for (var key in configuration.sequences) {
sequencesNames.push(key)
}
} else {
options.sequence.split(',').forEach((sequence) =>
sequencesNames.push(sequence)
)
}
for (let sequenceName of sequencesNames) {
for (let defaultValue of Object.keys(configuration.default)) {
if (!configuration.sequences[sequenceName][defaultValue]) {
configuration.sequences[sequenceName][defaultValue] = configuration.default[defaultValue]
}
}
}
if (options.browser === '_all_') {
for (var key in configuration.browser) {
browserNames.push(key)
}
} else {
if (typeof options.browser == 'string') {
browserNames.push(options.browser)
} else {
browserNames = options.browser
}
}
templateHelper.createDirectoryStructur(diffToolDir)
templateHelper.distributeHtmlFiles(templatesDir)
let outputDir = path.resolve(configuration.setup.documentRoot, 'Html')
switch (options.mode) {
case 'sitemap':
sitemap.fetch(options.url, options.depth, options.sequenceName)
break
case 'crawl':
crawler.fetch(options.url, options.depth, options.sequenceName, options.conc)
break
default:
for (let sequencesName of sequencesNames) {
switch (options.mode) {
case 'screenshots':
screenshot.create(browser, browserNames, sequencesName, outputDir, q)
break
case 'pdf':
pdf.create(configuration, browserNames, sequencesName, outputDir, options)
break
}
}
}
}
module.exports = run