@nodebug/emailer
Advanced tools
Comparing version 0.0.6 to 0.0.9
@@ -1,7 +0,7 @@ | ||
const fs = require('fs') | ||
const { readdirSync } = require('fs') | ||
const nodemailer = require('nodemailer') | ||
const { log } = require('@nodebug/logger') | ||
const config = require('@nodebug/config')('emailer') | ||
const path = require('path') | ||
const { extname } = require('path') | ||
const { directory } = require('./files') | ||
const generateHtmlReport = require('./htmler') | ||
@@ -39,17 +39,18 @@ | ||
function attachments() { | ||
let attachmentCount = 0 | ||
function getAttachments() { | ||
const files = [] | ||
const directoryPath = path.dirname( | ||
path.resolve(config.f.replace('json:', '')), | ||
) | ||
fs.readdirSync(directoryPath).forEach((file) => { | ||
if (path.extname(file) === '.html') { | ||
files.push({ | ||
path: `${directoryPath}/${file}`, | ||
}) | ||
} | ||
}) | ||
// files.push({ | ||
// path: `${directoryPath}logs/combined.log`, | ||
// }); | ||
if (directory !== undefined) { | ||
readdirSync(directory).forEach((file) => { | ||
if (extname(file) === '.html') { | ||
files.push({ | ||
path: `${directory}/${file}`, | ||
}) | ||
} | ||
}) | ||
// files.push({ | ||
// path: `${directory}logs/combined.log`, | ||
// }); | ||
} | ||
attachmentCount = files.length | ||
return files | ||
@@ -64,3 +65,3 @@ } | ||
text: body(), | ||
attachments: attachments(), | ||
attachments: getAttachments(), | ||
auth: { | ||
@@ -76,7 +77,14 @@ user: config.user.username, | ||
async function sendEmail(environment) { | ||
my.environment = environment | ||
await generateHtmlReport() | ||
const message = options() | ||
if (config.emailReport === true || config.e === true) { | ||
my.environment = environment | ||
if (attachmentCount <= 0) { | ||
log.info( | ||
`No reports were found in ${directory} to email. Exiting emailer.`, | ||
) | ||
return false | ||
} | ||
const gmailer = transporter(config.user.id, config.user.secret) | ||
gmailer.sendMail(options(), (error, info) => { | ||
gmailer.sendMail(message, (error, info) => { | ||
if (error) { | ||
@@ -89,2 +97,3 @@ throw error | ||
} | ||
return true | ||
} | ||
@@ -91,0 +100,0 @@ |
const { generate } = require('cucumber-html-reporter') | ||
const { log } = require('@nodebug/logger') | ||
const config = require('@nodebug/config')('emailer') | ||
const { resolve, dirname } = require('path') | ||
const exists = require('fs').existsSync | ||
const jsonfile = require('jsonfile').readFileSync | ||
const { existsSync } = require('fs') | ||
const { readFileSync } = require('jsonfile') | ||
const { directory, report } = require('./files') | ||
const jsonFile = resolve(config.f.replace('json:', '')) | ||
const dirName = dirname(jsonFile) | ||
module.exports = () => { | ||
if (!exists(jsonFile)) { | ||
log.error(`Cucumber report not found at path ${jsonFile}`) | ||
throw new ReferenceError(`Cucumber report not found at path ${jsonFile}`) | ||
if (!existsSync(report)) { | ||
log.info( | ||
`Cucumber report path should be passed using the -f command line argument`, | ||
) | ||
log.info(`Cucumber report not found at path ${report}`) | ||
return false | ||
} | ||
@@ -28,10 +28,10 @@ | ||
generate({ | ||
return generate({ | ||
theme: 'bootstrap', | ||
jsonFile, | ||
output: `${dirName}/${reportName}.html`, | ||
jsonFile: report, | ||
output: `${directory}/${reportName}.html`, | ||
reportSuiteAsScenarios: true, | ||
launchReport: true, | ||
metadata: jsonfile(jsonFile)[0].metadata, | ||
metadata: readFileSync(report)[0].metadata, | ||
}) | ||
} |
{ | ||
"name": "@nodebug/emailer", | ||
"version": "0.0.6", | ||
"version": "0.0.9", | ||
"author": { | ||
@@ -5,0 +5,0 @@ "name": "Node Bug", |
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
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
5346
6
146