@applitools/test-server
Advanced tools
Comparing version 1.0.6 to 1.0.7
@@ -6,2 +6,8 @@ # Changelog | ||
## 1.0.7 - 2021/11/10 | ||
- add built-in middlewares | ||
- add multiple middlewares support | ||
- add https support | ||
## 1.0.6 - 2021/10/30 | ||
@@ -8,0 +14,0 @@ |
{ | ||
"name": "@applitools/test-server", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"homepage": "https://github.com/applitools/eyes.sdk.javascript1#readme", | ||
@@ -41,2 +41,3 @@ "bugs": { | ||
"express": "4.17.1", | ||
"handlebars": "4.7.7", | ||
"morgan": "1.10.0", | ||
@@ -43,0 +44,0 @@ "yargs": "17.0.1" |
@@ -7,6 +7,9 @@ 'use strict' | ||
const {resolve} = require('path') | ||
const fs = require('fs') | ||
const cors = require('cors') | ||
const https = require('https') | ||
const utils = require('@applitools/utils') | ||
function testServer(argv = {}) { | ||
const {staticPath = resolve('./test/fixtures'), port = 0, allowCors, showLogs, middlewareFile} = argv | ||
let {staticPath = resolve('./test/fixtures'), port = 0, allowCors, showLogs, middlewares, key, cert} = argv | ||
@@ -19,5 +22,11 @@ const app = express() | ||
if (middlewareFile) { | ||
const middleware = require(middlewareFile) | ||
app.use(middleware.generateMiddleware ? middleware.generateMiddleware(argv) : middleware) | ||
if (middlewares) { | ||
middlewares = utils.types.isString(middlewares) ? JSON.parse(middlewares) : middlewares | ||
middlewares.forEach(data => { | ||
const middleware = utils.types.isFunction(data) | ||
? data | ||
: require(utils.types.isString(data) ? `./middlewares/${data}-middleware.js` : data.path) | ||
app.use(utils.types.isFunction(middleware.create) ? middleware.create(argv) : middleware) | ||
}) | ||
} | ||
@@ -55,21 +64,43 @@ | ||
return new Promise((resolve, reject) => { | ||
const server = app.listen(port, err => { | ||
if (err) { | ||
log('error starting test server', err) | ||
reject(err) | ||
} else { | ||
const serverPort = server.address().port | ||
const close = server.close.bind(server) | ||
log(`test server running at port: ${serverPort}`) | ||
resolve({port: serverPort, close}) | ||
} | ||
server.on('error', err => { | ||
if (err.code === 'EADDRINUSE') { | ||
log(`error: test server could not start at port ${server.address().port}: port is already in use.`) | ||
let server | ||
if (key && cert) { | ||
server = https | ||
.createServer( | ||
{ | ||
key: fs.readFileSync(key), | ||
cert: fs.readFileSync(cert), | ||
}, | ||
app, | ||
) | ||
.listen(port, err => { | ||
if (err) { | ||
log('error starting test server', err) | ||
reject(err) | ||
} else { | ||
const close = server.close.bind(server) | ||
log(`test server running at port: ${port}`) | ||
resolve({port, close}) | ||
} | ||
}) | ||
} else { | ||
server = app.listen(port, err => { | ||
if (err) { | ||
log('error starting test server', err) | ||
reject(err) | ||
} else { | ||
log('error in test server:', err) | ||
const serverPort = server.address().port | ||
const close = server.close.bind(server) | ||
log(`test server running at port: ${serverPort}`) | ||
resolve({port: serverPort, close}) | ||
} | ||
reject(err) | ||
}) | ||
} | ||
server.on('error', err => { | ||
if (err.code === 'EADDRINUSE') { | ||
log(`error: test server could not start at port ${server.address().port}: port is already in use.`) | ||
} else { | ||
log('error in test server:', err) | ||
} | ||
reject(err) | ||
}) | ||
@@ -76,0 +107,0 @@ }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
24297
14
232
8
3
+ Addedhandlebars@4.7.7
+ Addedhandlebars@4.7.7(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedneo-async@2.6.2(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addeduglify-js@3.19.3(transitive)
+ Addedwordwrap@1.0.0(transitive)