Skip to content

Commit

Permalink
refactor: support es6 & fix lint (#117)
Browse files Browse the repository at this point in the history
* refactor: support es6 & fix lint
  • Loading branch information
yihuineng authored Oct 12, 2023
1 parent ac1e276 commit ee3dc9e
Show file tree
Hide file tree
Showing 42 changed files with 788 additions and 718 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
**/.*
**/node_modules
**/build
**/test
**/wd/doc
**/logs
**/theme
166 changes: 0 additions & 166 deletions .eslintrc

This file was deleted.

41 changes: 41 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

/* eslint-env node */
const eslintConfig = {
extends: 'eslint-config-egg',
env: {
browser: true,
es6: true,
node: true,
},
settings: {
'import/resolver': {
alias: {
map: [
[ '@', `${__dirname}/src` ],
],
extensions: [ '.js', '.jsx', '.json' ],
},
},
},
parserOptions: {
ecmaVersion: 2020,
ecmaFeatures: {
experimentalObjectRestSpread: true,
},
},
plugins: [
'import'
],
ignorePatterns: [ '*.d.ts' ],
rules: {
'import/extensions': 0,
'jsdoc/require-param-type': 0,
'jsdoc/require-param-description': 0,
'jsdoc/check-tag-names': 0,
'jsdoc/require-returns-description': 0,
},
overrides: [],
};

module.exports = eslintConfig;
8 changes: 4 additions & 4 deletions lib/helper/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = wd => {
* @summary Support: Web(WebView)
* @param {string} text content.
* @type assert
* @returns {Promise.<boolean>}
* @return {Promise.<boolean>}
*/
wd.addElementPromiseChainMethod('hasText', function(...texts) {
return this.text().then(shouldContains(...texts));
Expand All @@ -25,7 +25,7 @@ module.exports = wd => {
* @summary Support: Web(WebView)
* @param {string} text content.
* @type assert
* @returns {Promise.<boolean>}
* @return {Promise.<boolean>}
*/
wd.addPromiseChainMethod('hasElementByCss', function(cssSelector) {
return this.elementByCssIfExists(cssSelector).then(d => {
Expand All @@ -41,7 +41,7 @@ module.exports = wd => {
* @summary Support: Web(WebView)
* @param {string} title - title of the web page.
* @type assert
* @returns {Promise.<boolean>}
* @return {Promise.<boolean>}
*/
wd.addPromiseChainMethod('assertTitle', function(title) {
return this.title().then(realTitle => {
Expand All @@ -59,7 +59,7 @@ module.exports = wd => {
* @param {string} attribute - attribute's name.
* @param {string} value - expected value.
* @type assert
* @returns {Promise.<boolean>}
* @return {Promise.<boolean>}
*/
wd.addPromiseChainMethod('assertAttribute', function(attribute, value) {
return this.execute(
Expand Down
6 changes: 3 additions & 3 deletions lib/helper/coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ program
const xlogger = require('xlogger');

const logger = xlogger.Logger({
closeFile: true
closeFile: true,
});

const cwd = process.cwd();
Expand All @@ -24,9 +24,9 @@ module.exports = wd => {
* @function coverage
* @summary Support: Web(WebView)
* @type utility
* @returns {Promise.<boolean>}
* @return {Promise.<boolean>}
*/
wd.addPromiseChainMethod('coverage', function(context) {
wd.addPromiseChainMethod('coverage', function() {
const tempDir = path.join(cwd, 'coverage', '.temp');
_.mkdir(tempDir);
return this.execute('return window.__coverage__')
Expand Down
38 changes: 18 additions & 20 deletions lib/helper/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,15 @@ module.exports = wd => {
* @summary Support: Web(WebView)
* @param {object} browser options.
* @type utility
* @returns {Promise.<boolean>}
* @return {Promise.<boolean>}
*/
wd.addPromiseChainMethod('initWindow', function(options = {}) {
return this.init(
Object.assign(
{
platformName: 'playwright',
browserName: 'chromium',
deviceScaleFactor: 2
},
options
)
).setWindowSize(options.width, options.height);
return this.init({
platformName: 'playwright',
browserName: 'chromium',
deviceScaleFactor: 2,
...options,
}).setWindowSize(options.width, options.height);
});

/**
Expand All @@ -43,21 +39,23 @@ module.exports = wd => {
* @summary Support: Web(WebView)
* @param {string} the pointed url.
* @type utility
* @returns {Promise.<boolean>}
* @return {Promise.<boolean>}
*/
wd.addPromiseChainMethod('getUrl', function(url) {
return this
.get(url)
.execute('return location.protocol')
.then(protocol => {
if (!~['http:', 'https:'].indexOf(protocol)) {
// eslint-disable-next-line no-bitwise
if (!~[ 'http:', 'https:' ].indexOf(protocol)) {
return new Promise(resolve => {
const handle = () => {
setTimeout(() => {
this.get(url)
.execute('return location.protocol')
.then(protocol => {
if (~['http:', 'https:'].indexOf(protocol)) {
// eslint-disable-next-line no-bitwise
if (~[ 'http:', 'https:' ].indexOf(protocol)) {
setTimeout(resolve, 3000);
} else {
handle();
Expand All @@ -76,7 +74,7 @@ module.exports = wd => {
* @function saveScreenshots
* @summary Support: Web(WebView)
* @type utility
* @returns {Promise.<boolean>}
* @return {Promise.<boolean>}
*/
wd.addPromiseChainMethod('saveScreenshots', function(context, params) {
const filepath = path.join(reportspath, 'screenshots', `${uuid()}.png`);
Expand All @@ -92,11 +90,11 @@ module.exports = wd => {
* @function saveVideos
* @summary Support: Web(WebView)
* @type utility
* @returns {Promise.<boolean>}
* @return {Promise.<boolean>}
*/
wd.addPromiseChainMethod('saveVideos', function(context, params = {}) {
params.video = true;
return this.saveScreenshot(null, params).then((filepath) => {
return this.saveScreenshot(null, params).then(filepath => {
appendToContext(context, `${path.relative(reportspath, filepath)}`);
});
});
Expand All @@ -107,7 +105,7 @@ module.exports = wd => {
* @summary Support: Web(WebView)
* @param {string} content of type.
* @type utility
* @returns {Promise.<boolean>}
* @return {Promise.<boolean>}
*/
wd.addPromiseChainMethod('formInput', function(string) {
const list = Array.prototype.slice.call(string);
Expand Down Expand Up @@ -143,7 +141,7 @@ module.exports = wd => {
* @summary Support: Web(WebView)
* @param {string} content of type.
* @type utility
* @returns {Promise.<boolean>}
* @return {Promise.<boolean>}
*/
wd.addPromiseChainMethod('elementInput', function(string) {
const list = Array.prototype.slice.call(string);
Expand Down Expand Up @@ -181,7 +179,7 @@ module.exports = wd => {
* @param {object} options - options of the event.
* @see https://github.com/macacajs/dom-event-simulate#support-events
* @type utility
* @returns {Promise.<boolean>}
* @return {Promise.<boolean>}
*/
wd.addPromiseChainMethod('domEvent', function(eventName, options) {
const uuid = Date.now();
Expand Down
Loading

0 comments on commit ee3dc9e

Please sign in to comment.