Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 31 additions & 26 deletions lib/api/list-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

};
4 changes: 3 additions & 1 deletion lib/model/codeceptjs-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
}

Expand Down