Skip to content

Commit

Permalink
Add CI to test and lint code
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 362315104
  • Loading branch information
AlexLloyd0 authored and copybara-github committed Mar 11, 2021
1 parent 323dbca commit 798cbdc
Show file tree
Hide file tree
Showing 14 changed files with 4,319 additions and 11 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/lint_javascript.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Lint javascript
on:
push:
branches:
- main
paths:
- 'javascript/**'
pull_request:
branches:
- main
paths:
- 'javascript/**'

jobs:
lint_javascript:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Cancel previous
uses: styfle/cancel-workflow-action@0.8.0
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v1

- name: Lint javascript
working-directory: ./javascript
run: |
yarn install --frozen-lockfile
yarn check-lint
yarn check-format
28 changes: 28 additions & 0 deletions .github/workflows/lint_webdriver_java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Lint webdriver_java
on:
push:
branches:
- main
paths:
- 'webdriver_java/**'
pull_request:
branches:
- main
paths:
- 'webdriver_java/**'

jobs:
lint_webdriver_java:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Cancel previous
uses: styfle/cancel-workflow-action@0.8.0
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v2

- name: Lint webdriver_java
uses: axel-op/googlejavaformat-action@v3
with:
args: "--dry-run --set-exit-if-changed"
31 changes: 31 additions & 0 deletions .github/workflows/test_javascript.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Test javascript
on:
push:
branches:
- main
paths:
- 'javascript/**'
pull_request:
branches:
- main
paths:
- 'javascript/**'

jobs:
test_javascript:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Cancel previous
uses: styfle/cancel-workflow-action@0.8.0
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v1

- name: Test javascript
working-directory: ./javascript
run: |
yarn install --frozen-lockfile
yarn test
34 changes: 34 additions & 0 deletions .github/workflows/test_webdriver_java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Test webdriver_java
on:
push:
branches:
- main
paths:
- 'javascript/**'
- 'webdriver_java/**'
pull_request:
branches:
- main
paths:
- 'javascript/**'
- 'webdriver_java/**'

jobs:
test_webdriver_java:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Cancel previous
uses: styfle/cancel-workflow-action@0.8.0
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v2
- name: Setup JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8

- name: Test webdriver_java
run: |
cd webdriver_java
mvn test
6 changes: 6 additions & 0 deletions docs/DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,9 @@ for a reference implementation. The basic flow is:
* Execute the script in the browser
* Run `return window.<semantic locator function>.apply(null, arguments);`
* Parse any failures and throw an appropriate exception

### CI

It's strongly recommended to add Continuous Integration to test and lint your
code. We use GitHub actions - see the existing workflows in
`.github/workflows/*.yml`.
1 change: 1 addition & 0 deletions javascript/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BasedOnStyle: Google
1 change: 1 addition & 0 deletions javascript/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/lib/parser.ts
110 changes: 110 additions & 0 deletions javascript/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
"env": {"browser": true, "es6": true, "node": true},
"parser": "@typescript-eslint/parser",
"parserOptions": {"sourceType": "module"},
"plugins": [
"eslint-plugin-ban",
"eslint-plugin-jsdoc",
"eslint-plugin-import",
"eslint-plugin-prefer-arrow",
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/array-type": ["error", {"default": "array-simple"}],
"@typescript-eslint/ban-ts-comment": "error",
"@typescript-eslint/ban-types": [
"error",
{
"types": {
"Object": {"message": "Use {} or 'object' instead."},
"String": {"message": "Use 'string' instead."},
"Number": {"message": "Use 'number' instead."},
"Boolean": {"message": "Use 'boolean' instead."}
}
}
],
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/consistent-type-definitions": "error",
"@typescript-eslint/explicit-member-accessibility":
["error", {"accessibility": "no-public"}],
"@typescript-eslint/member-delimiter-style": [
"error",
{
"multiline": {"delimiter": "semi", "requireLast": true},
"singleline": {"delimiter": "semi", "requireLast": false}
}
],
"@typescript-eslint/naming-convention": [
"error",
{
"selector": "variable",
"modifiers": ["const"],
"format": ["UPPER_CASE", "camelCase"]
},
{
"selector": "variable",
"format": ["camelCase"]
},
{
"selector": "typeLike",
"format": ["PascalCase"]
}
],
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/no-unused-expressions":
["error", {"allowShortCircuit": true}],
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/semi": ["error", "always"],
"@typescript-eslint/triple-slash-reference": "error",
"arrow-body-style": "error",
"curly": ["error", "multi-line"],
"default-case": "error",
"eqeqeq": ["error", "smart"],
"guard-for-in": "error",
"import/no-default-export": "error",
"jsdoc/check-alignment": "error",
"new-parens": "error",
"no-cond-assign": "error",
"no-debugger": "error",
"no-duplicate-case": "error",
"no-new-wrappers": "error",
"no-return-await": "error",
"no-throw-literal": "error",
"no-unsafe-finally": "error",
"no-unused-labels": "error",
"no-useless-constructor": "off",
"@typescript-eslint/no-useless-constructor": ["error"],
"no-var": "error",
"object-shorthand": "error",
"prefer-const": ["error", {"destructuring": "all"}],
"radix": "error",
"ban/ban": [
"error",
{"name": "fit"},
{"name": "fdescribe"},
{"name": "xit"},
{"name": "xdescribe"},
{"name": "fitAsync"},
{"name": "xitAsync"},
{"name": "fitFakeAsync"},
{"name": "xitFakeAsync"},
{"name": ["it", "skip"]},
{"name": ["it", "only"]},
{"name": ["it", "async", "skip"]},
{"name": ["it", "async", "only"]},
{"name": ["describe", "skip"]},
{"name": ["describe", "only"]},
{"name": ["describeWithDate", "skip"]},
{"name": ["describeWithDate", "only"]},
{
"name": "parseInt",
"message": "Use Number() and Math.floor or Math.trunc"
},
{"name": "parseFloat", "message": "Use Number()"},
{"name": "Array", "message": "Use square brackets"},
{"name": ["*", "innerText"], "message": "Use .textContent instead."}
]
}
}
20 changes: 17 additions & 3 deletions javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@
"build": "yarn && tsc",
"ibuild": "yarn && tsc --watch",
"pretest": "yarn build",
"test": "karma start --browsers ChromeHeadless --single-run",
"prepack": "yarn test"
"test": "karma start --browsers ChromeHeadless,FirefoxHeadless --single-run --no-auto-watch",
"itest": "karma start --browsers Chrome,Firefox",
"prepack": "yarn test",
"fix": "yarn fix-lint && yarn fix-format",
"check-lint": "eslint --ext .ts src test",
"fix-lint": "eslint --ext .ts --fix src test",
"check-format": "clang-format --version; find src test ! -path 'src/lib/parser.ts' | grep '\\.js$\\|\\.ts$' | xargs clang-format --style=file --dry-run -Werror",
"fix-format": "clang-format --version; find src test ! -path 'src/lib/parser.ts' | grep '\\.js$\\|\\.ts$' | xargs clang-format --style=file -i"
},
"repository": {
"type": "git",
Expand All @@ -42,14 +48,22 @@
},
"devDependencies": {
"@types/jasmine": "^3.6.2",
"@typescript-eslint/eslint-plugin": "^3.6.0",
"@typescript-eslint/parser": "^3.6.0",
"clang-format": "^1.4.0",
"eslint": "^7.21.0",
"eslint-plugin-ban": "^1.5.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsdoc": "^32.2.0",
"eslint-plugin-prefer-arrow": "^1.2.3",
"jasmine-core": "^3.6.0",
"karma": "^5.2.3",
"karma-chrome-launcher": "^3.1.0",
"karma-firefox-launcher": "^2.1.0",
"karma-jasmine": "^4.0.1",
"karma-spec-reporter": "0.0.32",
"karma-typescript": "^5.2.0",
"karma-typescript-es6-transform": "^5.2.0",
"karma-typescript-es6-transform": "~5.3.0",
"lit-html": "^1.3.0",
"typescript": "^4.1.3"
}
Expand Down
7 changes: 3 additions & 4 deletions javascript/src/lib/locator_gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function resolveRoot(element: HTMLElement, root?: HTMLElement): HTMLElement|
* semantic nodes).
*/
function closestFullLocator(element: HTMLElement, root: HTMLElement):
{nodes: SemanticNode[], element: HTMLElement}|null {
{nodes: SemanticNode[]; element: HTMLElement}|null {
let first = closestSemanticNode(element, root);
if (first === null) {
return null;
Expand Down Expand Up @@ -165,12 +165,11 @@ function refine(nodes: SemanticNode[], element: HTMLElement, root: HTMLElement):
* `<body>`.
*/
function closestSemanticNode(el: HTMLElement, root: HTMLElement):
{node: SemanticNode, element: HTMLElement}|null {
{node: SemanticNode; element: HTMLElement}|null {
let element: HTMLElement|null = el;
// Exclude body elements as the `{document}` node would alwasys be stripped
// out
while (element !== null &&
root.contains(element) && root !== element) {
while (element !== null && root.contains(element) && root !== element) {
const node = semanticNodeFor(element);
if (node !== null) {
return {node, element};
Expand Down
1 change: 1 addition & 0 deletions javascript/src/lib/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

// clang-format off
// @ts-nocheck
// tslint:disable
import {SemanticLocator, SemanticNode} from "./semantic_locator";
Expand Down
3 changes: 3 additions & 0 deletions javascript/test/lib/table_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import {html, render} from 'lit-html';

import {hasDataInColumn, hasDataInRow, TEST_ONLY} from '../../src/lib/table';

// ESLint can't tell that RenderedGrid is a class and I can't work out a
// configuration which allows this without being too lax
// eslint-disable-next-line @typescript-eslint/naming-convention
const {gridFromTable, RenderedGrid} = TEST_ONLY;

let container: HTMLElement;
Expand Down
Loading

0 comments on commit 798cbdc

Please sign in to comment.