diff --git a/lib/api/list-actions.js b/lib/api/list-actions.js index b4b3e6d..9e828bc 100644 --- a/lib/api/list-actions.js +++ b/lib/api/list-actions.js @@ -7,33 +7,38 @@ const path = require('path'); const codeceptjsFactory = require('../model/codeceptjs-factory'); const { methodsOfObject } = require('codeceptjs/lib/utils'); -module.exports = (req, res) => { - const { container } = codeceptjsFactory.getInstance(); - const docsWebApiFolderPath = path.join(path.dirname(require.resolve('codeceptjs')), '/../docs/webapi'); - const docFileList = []; - fs.readdirSync(docsWebApiFolderPath).map(fileName => { - docFileList.push(path.basename(fileName,'.mustache')); - }); - const helpers = container.helpers(); - const actions = {}; - for (const name in helpers) { - const helper = helpers[name]; - methodsOfObject(helper).forEach((action) => { - - if(docFileList.includes(action)) { - let filePath = path.join(docsWebApiFolderPath, action + '.mustache'); - let fn = helper[action].toString().replace(/\n/g,' ').replace(/\{.*\}/gm,'{}'); - try{ - let docData = fs.readFileSync(filePath, 'utf-8'); - let params = parser.parse(fn); - actions[action] = { params: params, actionDoc: docData }; - } catch(err) { - debug('Error in fetching doc for file content', fn, err); +module.exports = (req, res) => { + try { + const { container } = codeceptjsFactory.getInstance(); + const docsWebApiFolderPath = path.join(path.dirname(require.resolve('codeceptjs')), '/../docs/webapi'); + const docFileList = []; + fs.readdirSync(docsWebApiFolderPath).map(fileName => { + docFileList.push(path.basename(fileName,'.mustache')); + }); + const helpers = container.helpers(); + const actions = {}; + for (const name in helpers) { + const helper = helpers[name]; + methodsOfObject(helper).forEach((action) => { + + if(docFileList.includes(action)) { + let filePath = path.join(docsWebApiFolderPath, action + '.mustache'); + let fn = helper[action].toString().replace(/\n/g,' ').replace(/\{.*\}/gm,'{}'); + try{ + let docData = fs.readFileSync(filePath, 'utf-8'); + let params = parser.parse(fn); + actions[action] = { params: params, actionDoc: docData }; + } catch(err) { + debug('Error in fetching doc for file content', fn, err); + } } - } - }); + }); + } + + res.send({ actions }); + } catch (e) { + debug(`Could not fetch documentation due to: ${e.message}`); } - - res.send({ actions }); + }; diff --git a/lib/model/codeceptjs-factory.js b/lib/model/codeceptjs-factory.js index 91aa333..c940ea6 100644 --- a/lib/model/codeceptjs-factory.js +++ b/lib/model/codeceptjs-factory.js @@ -161,8 +161,10 @@ module.exports = new class CodeceptjsFactory { const helpersConfig = config.get('helpers'); for (const helperName in container.helpers()) { - if (helpersConfig[helperName]) { + try { container.helpers(helperName)._setConfig(helpersConfig[helperName]); + } catch (e) { + debug(`Cannot run _setConfig due to: ${e.message}`); } }