Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuineng committed Oct 12, 2023
1 parent 8b9d4fa commit 87020a9
Show file tree
Hide file tree
Showing 41 changed files with 294 additions and 106 deletions.
64 changes: 35 additions & 29 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
module.exports = {
root: true,
extends: 'eslint-config-egg/typescript',
globals: {
window: true,
'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: {
'jsdoc/check-tag-names': 0,
'valid-jsdoc': 0,
'no-script-url': 0,
'no-multi-spaces': 0,
'default-case': 0,
'no-case-declarations': 0,
'one-var-declaration-per-line': 0,
'no-restricted-syntax': 0,
'jsdoc/require-param': 0,
'jsdoc/check-param-names': 0,
'import/extensions': 0,
'jsdoc/require-param-type': 0,
'jsdoc/require-param-description': 0,
'jsdoc/check-tag-names': 0,
'jsdoc/require-returns-description': 0,
'arrow-parens': 0,
'prefer-promise-reject-errors': 0,
'no-control-regex': 0,
'no-use-before-define': 0,
'array-callback-return': 0,
'no-bitwise': 0,
'no-self-compare': 0,
'@typescript-eslint/no-var-requires': 0,
'@typescript-eslint/ban-ts-ignore': 0,
'@typescript-eslint/no-use-before-define': 0,
'@typescript-eslint/no-this-alias': 0,
'one-var': 0,
'no-sparse-arrays': 0,
'no-useless-concat': 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
@@ -1,4 +1,4 @@

'use strict';

const { assert } = require('chai');

Expand Down Expand Up @@ -47,7 +47,7 @@ module.exports = wd => {
return this.title().then(realTitle => {
assert(
title === realTitle,
`expect title to be '${title}' but got ${realTitle}`,
`expect title to be '${title}' but got ${realTitle}`
);
});
});
Expand All @@ -63,11 +63,11 @@ module.exports = wd => {
*/
wd.addPromiseChainMethod('assertAttribute', function(attribute, value) {
return this.execute(
`return window.__macaca_current_element.getAttribute('${attribute}')`,
`return window.__macaca_current_element.getAttribute('${attribute}')`
).then(realValue => {
assert(
value === realValue,
`expect attribute ${attribute} to be '${value}' but got '${realValue}'`,
`expect attribute ${attribute} to be '${value}' but got '${realValue}'`
);
});
});
Expand Down
2 changes: 1 addition & 1 deletion lib/helper/coverage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

'use strict';

const fs = require('fs');
const path = require('path');
Expand Down
8 changes: 5 additions & 3 deletions lib/helper/element.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

'use strict';

const fs = require('fs');
const path = require('path');
Expand Down Expand Up @@ -46,13 +46,15 @@ module.exports = wd => {
.get(url)
.execute('return location.protocol')
.then(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 => {
// eslint-disable-next-line no-bitwise
if (~[ 'http:', 'https:' ].indexOf(protocol)) {
setTimeout(resolve, 3000);
} else {
Expand Down Expand Up @@ -92,7 +94,7 @@ module.exports = wd => {
*/
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 Down Expand Up @@ -185,7 +187,7 @@ module.exports = wd => {
${domEventLibSource}
var _element_${uuid} = window.__macaca_current_element;
_macaca_simulate.domEvent(_element_${uuid}, '${eventName}', ${JSON.stringify(
options,
options
)});
`;
return this.execute(script);
Expand Down
2 changes: 1 addition & 1 deletion lib/helper/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

'use strict';

const extendsMixIn = wd => {
require('../next')(wd);
Expand Down
2 changes: 1 addition & 1 deletion lib/helper/macaca-datahub.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

'use strict';

const DataHubClient = require('datahub-nodejs-sdk');

Expand Down
2 changes: 1 addition & 1 deletion lib/helper/reporter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

'use strict';

const path = require('path');
const _ = require('xutil');
Expand Down
2 changes: 1 addition & 1 deletion lib/macaca-wd.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

'use strict';

const helper = require('./helper');
const wd = require('../wd/lib/main');
Expand Down
8 changes: 4 additions & 4 deletions lib/next/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

'use strict';

module.exports = wd => {
[
'page',
'pagePopup',
'browser',
].map(method => {
].forEach(method => {
wd.addPromiseChainMethod(method, function(...params) {
const [ func, ...args ] = params;
return this.next(method, [{ func, args }]);
Expand All @@ -15,7 +15,7 @@ module.exports = wd => {
[
'fileChooser',
'elementStatus',
].map(method => {
].forEach(method => {
wd.addPromiseChainMethod(method, function(...params) {
return this.next(method, params);
});
Expand All @@ -24,7 +24,7 @@ module.exports = wd => {
[
'mouse',
'keyboard',
].map(method => {
].forEach(method => {
wd.addPromiseChainMethod(method, function(...params) {
const [ type, ...args ] = params;
return this.next(method, [{ type, args }]);
Expand Down
2 changes: 1 addition & 1 deletion lib/web/react-router-helper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

'use strict';

const fs = require('fs');
const _ = require('lodash');
Expand Down
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"xutil": "1"
},
"devDependencies": {
"eslint": "7",
"eslint": "8",
"eslint-config-egg": "^12.2.1",
"git-contributor": "1",
"husky": "^1.3.1",
"jsdom": "^11.10.0",
Expand All @@ -50,10 +51,7 @@
"mocha": "*",
"nyc": "^11.6.0",
"stoppable": "^1.1.0",
"vuepress": "^1.9.8",
"ts-node": "^10.9.1",
"typescript": "^4.8.2",
"eslint-config-egg": "^11.0.1"
"vuepress": "^1.9.8"
},
"scripts": {
"docs:dev": "vuepress dev docs",
Expand Down
5 changes: 3 additions & 2 deletions test/alert.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

'use strict';

const assert = require('assert');

Expand All @@ -7,7 +7,8 @@ const { Server } = require('./helper');
const wd = require('../lib/macaca-wd');

describe('test/alert.test.js', function() {
let driver, server;
let driver,
server;
before(() => {
server = new Server();
server.start();
Expand Down
7 changes: 4 additions & 3 deletions test/assert.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

'use strict';

const assert = require('assert');

Expand All @@ -8,7 +8,8 @@ const { elFuncFullType, elFuncSuffix } = require('../wd/lib/utils');
const wd = require('../lib/macaca-wd');

describe('test/asserter.test.js', function() {
let driver, server;
let driver,
server;

const mockServer = async (mockKey, mockValue) => {
server = new Server();
Expand Down Expand Up @@ -57,7 +58,7 @@ describe('test/asserter.test.js', function() {
const { script, args } = server.ctx.request.body;
assert.equal(
script,
"return window.__macaca_current_element.getAttribute('class')",
"return window.__macaca_current_element.getAttribute('class')"
);
assert.equal(args.length, 0);
});
Expand Down
5 changes: 3 additions & 2 deletions test/browser.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

'use strict';

const assert = require('assert');

Expand All @@ -7,7 +7,8 @@ const { Server } = require('./helper');
const wd = require('../lib/macaca-wd');

describe('test/browser.test.js', function() {
let driver, server;
let driver,
server;
before(() => {
server = new Server();
server.start();
Expand Down
7 changes: 4 additions & 3 deletions test/cookie.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

'use strict';

const assert = require('assert');

Expand All @@ -7,7 +7,8 @@ const { Server } = require('./helper');
const wd = require('../lib/macaca-wd');

describe('test/cookie.test.js', function() {
let driver, server;
let driver,
server;
before(() => {
server = new Server();
server.start();
Expand Down Expand Up @@ -71,7 +72,7 @@ describe('test/cookie.test.js', function() {
await driver.deleteCookie('test_cookie');
assert.equal(
server.ctx.url,
'/wd/hub/session/sessionId/cookie/test_cookie',
'/wd/hub/session/sessionId/cookie/test_cookie'
);
assert.equal(server.ctx.method, 'DELETE');
assert.deepEqual(server.ctx.request.body, {});
Expand Down
5 changes: 3 additions & 2 deletions test/excecute.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

'use strict';

const assert = require('assert');

Expand All @@ -7,7 +7,8 @@ const { Server } = require('./helper');
const wd = require('../lib/macaca-wd');

describe('test/execute.test.js', function() {
let driver, server;
let driver,
server;
before(() => {
server = new Server();
server.start();
Expand Down
6 changes: 3 additions & 3 deletions test/helper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

'use strict';

const http = require('http');
const Koa = require('koa');
Expand All @@ -12,7 +12,7 @@ class Server {
{
port: 3456,
},
options || {},
options || {}
);
this.app = new Koa();
this.app.use(bodyParser());
Expand Down Expand Up @@ -40,7 +40,7 @@ class Server {
});
}
this.server = stoppable(
http.createServer(this.app.callback()).listen(this.options.port),
http.createServer(this.app.callback()).listen(this.options.port)
);
}

Expand Down
5 changes: 3 additions & 2 deletions test/screenshot.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

'use strict';

const assert = require('assert');

Expand All @@ -7,7 +7,8 @@ const { Server } = require('./helper');
const wd = require('../lib/macaca-wd');

describe('test/screenshot.test.js', function() {
let driver, server;
let driver,
server;
before(() => {
server = new Server();
server.start();
Expand Down
5 changes: 3 additions & 2 deletions test/session.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

'use strict';

const assert = require('assert');

Expand All @@ -7,7 +7,8 @@ const { Server } = require('./helper');
const wd = require('../lib/macaca-wd');

describe('test/session.test.js', function() {
let driver, server;
let driver,
server;
before(() => {
server = new Server();
server.start();
Expand Down
5 changes: 3 additions & 2 deletions test/source.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

'use strict';

const assert = require('assert');

Expand All @@ -7,7 +7,8 @@ const { Server } = require('./helper');
const wd = require('../lib/macaca-wd');

describe('test/source.test.js', function() {
let driver, server;
let driver,
server;
before(() => {
server = new Server();
server.start();
Expand Down
Loading

0 comments on commit 87020a9

Please sign in to comment.