UNPKG

ticket2test

Version:

Pull JIRA ticket information and create a JS test file

38 lines (33 loc) 947 B
const fs = require("fs"); const template = require("./template"); function checkDirectory(directory, callback) { fs.stat(directory, function(err, stats) { //Check if error defined and the error code is "not exists" if (err && err.errno === -2) { //Create the directory, call the callback. fs.mkdir(directory, callback); } else { //just in case there was a different error: callback(err); } }); } function getFilepath() { const readConfig = require("./get-config"); const config = readConfig(); if (config && config.outputDir) { return config.outputDir; } return "./tests"; } module.exports = (id, data) => { const filepath = `${getFilepath()}/${id}.spec.js`; data.id = id; checkDirectory(getFilepath(), error => { if (error) throw error; fs.writeFile(filepath, template(data), err => { if (err) throw err; console.log(`${filepath} Created`); }); }); };