Skip to content

Commit bb86601

Browse files
authored
Merge pull request #246 from codeceptjs/some-improvements
- handle errors when cannot load the docs - open the links in new browser tab - improve some scripts
2 parents 4b8f413 + d6ea3de commit bb86601

File tree

5 files changed

+9190
-36360
lines changed

5 files changed

+9190
-36360
lines changed

lib/api/list-actions.js

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,34 @@ const codeceptjsFactory = require('../model/codeceptjs-factory');
88
const { methodsOfObject } = require('codeceptjs/lib/utils');
99

1010
module.exports = (req, res) => {
11+
const { container } = codeceptjsFactory.getInstance();
12+
const docsWebApiFolderPath = path.join(path.dirname(require.resolve('codeceptjs')), '/../docs/webapi');
13+
const docFileList = [];
1114
try {
12-
const { container } = codeceptjsFactory.getInstance();
13-
const docsWebApiFolderPath = path.join(path.dirname(require.resolve('codeceptjs')), '/../docs/webapi');
14-
const docFileList = [];
1515
fs.readdirSync(docsWebApiFolderPath).map(fileName => {
1616
docFileList.push(path.basename(fileName,'.mustache'));
1717
});
18-
const helpers = container.helpers();
19-
const actions = {};
20-
for (const name in helpers) {
21-
const helper = helpers[name];
22-
methodsOfObject(helper).forEach((action) => {
23-
24-
if(docFileList.includes(action)) {
25-
let filePath = path.join(docsWebApiFolderPath, action + '.mustache');
26-
let fn = helper[action].toString().replace(/\n/g,' ').replace(/\{.*\}/gm,'{}');
27-
try{
28-
let docData = fs.readFileSync(filePath, 'utf-8');
29-
let params = parser.parse(fn);
30-
actions[action] = { params: params, actionDoc: docData };
31-
} catch(err) {
32-
debug('Error in fetching doc for file content', fn, err);
33-
}
34-
}
35-
36-
});
37-
}
38-
39-
res.send({ actions });
4018
} catch (e) {
41-
debug(`Could not fetch documentation due to: ${e.message}`);
19+
debug(`No documentation found due to ${e.message}`);
4220
}
21+
const helpers = container.helpers();
22+
const actions = {};
23+
for (const name in helpers) {
24+
const helper = helpers[name];
25+
methodsOfObject(helper).forEach((action) => {
4326

27+
if (docFileList.includes(action)) {
28+
let filePath = path.join(docsWebApiFolderPath, action + '.mustache');
29+
let fn = helper[action].toString().replace(/\n/g, ' ').replace(/\{.*\}/gm, '{}');
30+
try {
31+
let docData = fs.readFileSync(filePath, 'utf-8');
32+
let params = parser.parse(fn);
33+
actions[action] = {params: params, actionDoc: docData};
34+
} catch (err) {
35+
debug('Error in fetching doc for file content', fn, err);
36+
}
37+
}
38+
});
39+
}
40+
res.send({ actions });
4441
};

lib/app.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
const path = require('path');
4-
const { BrowserWindow, app } = require('electron');
4+
const { BrowserWindow, app, shell } = require('electron');
55
const { getPort } = require('./config/env');
66

77
const NAME = 'CodeceptUI';
@@ -24,14 +24,14 @@ function createWindow() {
2424
const x = screenWidth - Math.max(width, 500);
2525
// Create the browser window.
2626
win = new BrowserWindow({
27-
width,
27+
width: screenWidth / 1.2,
2828
height: screenHeight,
2929
minWidth: 500,
3030
x,
3131
y: 0,
3232
title: NAME,
3333
autoHideMenuBar: true,
34-
icon: path.join(__dirname, '../build/icons/64x64.png'),
34+
icon: path.join(__dirname, '/build/icons/64x64.png'),
3535
webPreferences: {
3636
nodeIntegration: true,
3737
nodeIntegrationInWorker: true,
@@ -46,6 +46,11 @@ function createWindow() {
4646
win.on('closed', () => {
4747
win = null;
4848
});
49+
50+
win.webContents.setWindowOpenHandler(({ url }) => {
51+
// open url in a browser and prevent default
52+
shell.openExternal(url);
53+
});
4954
}
5055

5156
// Quit when all windows are closed.

0 commit comments

Comments
 (0)