diff --git a/package.json b/package.json index 570b347..1c44a26 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,9 @@ "name": "@financial-times/n-automation", "main": "build/main.js", "dependencies": { - "fs": "0.0.2" + "@financial-times/n-logger": "^5.4.0", + "isomorphic-fetch": "^2.2.1", + "nodemailer": "^2.6.0" }, "repository": { "type": "git", @@ -10,15 +12,16 @@ }, "license": "MIT", "devDependencies": { - "npm-prepublish": "^1.2.1", "babel-cli": "^6.5.1", "babel-plugin-transform-object-assign": "^6.5.0", "babel-preset-es2015": "^6.5.0", "babel-register": "^6.5.1", "chai": "^3.5.0", + "denodeify": "^1.2.1", "eslint": "^2.9.0", "lintspaces-cli": "^0.1.1", "mocha": "^2.2.1", + "npm-prepublish": "^1.2.1", "sinon": "^1.17.4" }, "engines": { diff --git a/src/main.js b/src/main.js index 53c9a52..7108db0 100644 --- a/src/main.js +++ b/src/main.js @@ -7,9 +7,16 @@ const sendSlackNotification = require('./slack'); const logger = require('@financial-times/n-logger').default.logger; function emptyReportsFolder (path) { - logger.info('Deleting old reports...') - - const reportNames = fs.readdirSync(path); + logger.info('Deleting old reports...'); + + let reportNames; + try { + reportNames = fs.readdirSync(path); + } catch (err) { + if (err.code === 'ENOENT') { + return; + } + } logger.info(reportNames); diff --git a/src/reporter.js b/src/reporter.js index 83794c6..0bdb220 100644 --- a/src/reporter.js +++ b/src/reporter.js @@ -1,4 +1,6 @@ -const fs = require('fs') +const denodeify = require('denodeify'); + +const writeFile = denodeify(require('fs').writeFile); function safePath (path) { const lastSlash = path.lastIndexOf('/'); @@ -20,15 +22,15 @@ module.exports = { const outputFolder = safePath(options.output_folder); const prefix = options.filename_prefix; const modules = results.modules; - results.sessionId = options.globals.sessionId; - - - for (const moduleName in modules) { - if (modules.hasOwnProperty(moduleName)) { + results.sessionId = options.globals.test_settings.sessionId; + const writes = Object.keys(modules) + .map(moduleName => { const file = `${outputFolder}${prefix}${moduleName.replace('/', '-')}.json`; - fs.writeFile(file, JSON.stringify(results, null, 4)) - } - } - done(); + return writeFile(file, JSON.stringify(results, null, 4)) + .catch(() => { }); + }); + + Promise.all(writes) + .then(() => { done() }); } };