Skip to content

Commit

Permalink
Last lint PR (#395)
Browse files Browse the repository at this point in the history
* lint and fix unit testing

* detect react version

* testing dom eslint fixes

* lint json files

* lint json files

* lint stubbing recipes

* lint logging in recipes

* lint server communication recipes

* lint fundamentals recipes

* lint vue vuex rest recipe

* all linted

* lint using single command
  • Loading branch information
bahmutov authored Jan 6, 2020
1 parent 9942430 commit b305396
Show file tree
Hide file tree
Showing 160 changed files with 1,665 additions and 6,911 deletions.
14 changes: 12 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
examples/blogs__e2e-snapshots/snapshots.js
examples/blogs__element-coverage/src
examples/preprocessors__typescript-webpack/dist
node_modules
examples/preprocessors__flow-browserify
examples/blogs__testing-redux-store/src
**/node_modules
**/vendor
# don't ignore hidden files, useful for formatting json config files
!.*
# most TS configs have comments, which generates lint warnings
tsconfig.json
# generated files
.cache
examples/blogs__testing-redux-store/dist
examples/preprocessors__typescript-webpack/dist
# a couple of problematic JSON files
examples/logging-in__jwt/server/config.json
examples/logging-in__using-app-code/server/config.json
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ screenshots
videos
out.js
examples/*/cypress/logs
snapshots.js
7 changes: 7 additions & 0 deletions Development.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ $ npx eslint examples/blogs__vue-vuex-rest/cypress
$ npx eslint examples/blogs__vue-vuex-rest/cypress --fix
```

There are NPM scripts for linting code and JSON files

```shell
npm run lint
npm run lint:json
```

### Testing in specific browser

You can test some examples using a specific browser. For example, to run just some folders using Brave browser, call
Expand Down
16 changes: 2 additions & 14 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,8 @@ jobs:
steps:
- attach_workspace:
at: ~/
- run: |
npx eslint examples/blogs__a11y \
examples/blogs__application-actions \
examples/blogs__codepen-demo \
examples/blogs__direct-control-angular \
examples/blogs__e2e-api-testing \
examples/blogs__e2e-snapshots \
examples/blogs__element-coverage \
examples/blogs__testing-redux-store/cypress \
examples/blogs__vue-vuex-rest/cypress \
examples/preprocessors__grep \
examples/preprocessors__typescript-browserify \
examples/preprocessors__typescript-webpack \
examples/unit-testing__react
- run: npm run lint:json
- run: npm run lint

# dummy job running after all end-to-end tests
after-tests:
Expand Down
2 changes: 1 addition & 1 deletion examples/blogs__a11y/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"version": "1.0.0",
"description": "Testing accessibility of a page",
"scripts": {
"cypress:run": "../../node_modules/.bin/cypress run",
"cypress:open": "../../node_modules/.bin/cypress open",
"cypress:run": "../../node_modules/.bin/cypress run",
"test:ci": "../../node_modules/.bin/cypress run"
}
}
14 changes: 7 additions & 7 deletions examples/blogs__application-actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
"description": "Testing Redux store using Cypress",
"private": true,
"scripts": {
"start": "../../node_modules/.bin/http-server -p 8888 --silent -c-1",
"start:win": "bin-up serve -l 8888 --no-clipboard",
"dev": "../../node_modules/.bin/start-test 8888 cypress:open",
"cypress:open": "../../node_modules/.bin/cypress open",
"cypress:run": "../../node_modules/.bin/cypress run",
"cypress:run:win": "bin-up cypress run",
"cypress:run:chrome": "../../node_modules/.bin/cypress run --browser chrome",
"cypress:run:firefox": "../../node_modules/.bin/cypress run --browser firefox",
"cypress:open": "../../node_modules/.bin/cypress open",
"cypress:run:win": "bin-up cypress run",
"dev": "../../node_modules/.bin/start-test 8888 cypress:open",
"start": "../../node_modules/.bin/http-server -p 8888 --silent -c-1",
"start:win": "bin-up serve -l 8888 --no-clipboard",
"test:ci": "../../node_modules/.bin/start-test 8888 cypress:run",
"test:ci:windows": "bin-up start-test start:win http://localhost:8888 cypress:run:win",
"test:ci:chrome": "../../node_modules/.bin/start-test 8888 cypress:run:chrome",
"test:ci:firefox": "../../node_modules/.bin/start-test 8888 cypress:run:firefox"
"test:ci:firefox": "../../node_modules/.bin/start-test 8888 cypress:run:firefox",
"test:ci:windows": "bin-up start-test start:win http://localhost:8888 cypress:run:win"
}
}
4 changes: 2 additions & 2 deletions examples/blogs__codepen-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version": "1.0.0",
"description": "Demo of E2E testing HyperApp.js counter app running on Codepen.io",
"scripts": {
"start": "echo",
"cypress:run": "../../node_modules/.bin/cypress run",
"cypress:open": "../../node_modules/.bin/cypress open",
"cypress:run": "../../node_modules/.bin/cypress run",
"start": "echo",
"test:ci": "npm run cypress:run",
"test:ci:chrome": "npm run cypress:run -- --browser chrome"
}
Expand Down
4 changes: 2 additions & 2 deletions examples/blogs__direct-control-angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version": "1.0.0",
"description": "Example showing direct control of Angular 1.x application from E2E tests",
"scripts": {
"start": "echo",
"cypress:run": "../../node_modules/.bin/cypress run",
"cypress:open": "../../node_modules/.bin/cypress open",
"cypress:run": "../../node_modules/.bin/cypress run",
"start": "echo",
"test:ci": "npm run cypress:run"
}
}
2 changes: 1 addition & 1 deletion examples/blogs__e2e-api-testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version": "1.0.0",
"description": "Cypress E2E runner can also test Rest and other APIs",
"scripts": {
"cypress:open": "../../node_modules/.bin/cypress open",
"cypress:run": "../../node_modules/.bin/cypress run",
"cypress:run:windows": "bin-up cypress run",
"cypress:open": "../../node_modules/.bin/cypress open",
"start": "../../node_modules/.bin/json-server db.json --port 7081 --quiet",
"start:windows": "bin-up json-server db.json --port 7081 --quiet",
"test:ci": "../../node_modules/.bin/start-test 7081 cypress:run",
Expand Down
39 changes: 22 additions & 17 deletions examples/blogs__e2e-snapshots/cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
[{
"id": "1",
"title": "do first thing",
"completed": false
}, {
"id": "2",
"title": "do second thing",
"completed": true
}, {
"id": "3",
"title": "one more thing",
"completed": false
}, {
"id": "4",
"title": "last item on the agenda",
"completed": false
}]
[
{
"id": "1",
"title": "do first thing",
"completed": false
},
{
"id": "2",
"title": "do second thing",
"completed": true
},
{
"id": "3",
"title": "one more thing",
"completed": false
},
{
"id": "4",
"title": "last item on the agenda",
"completed": false
}
]
10 changes: 5 additions & 5 deletions examples/blogs__e2e-snapshots/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"version": "1.0.0",
"description": "End-to-end snapshots for Cypress",
"scripts": {
"start": "../../node_modules/.bin/json-server -p 3700 --static . data.json --middlewares ../../node_modules/json-server-reset",
"cypress:run": "../../node_modules/.bin/cypress run",
"cypress:open": "../../node_modules/.bin/cypress open",
"reset:db": "node reset-db.js",
"cypress:run": "../../node_modules/.bin/cypress run",
"dev": "../../node_modules/.bin/start-test 3700 cypress:open",
"reset": "node reset-db.js",
"test:ci": "../../node_modules/.bin/start-test 3700 cypress:run",
"dev": "../../node_modules/.bin/start-test 3700 cypress:open"
"reset:db": "node reset-db.js",
"start": "../../node_modules/.bin/json-server -p 3700 --static . data.json --middlewares ../../node_modules/json-server-reset",
"test:ci": "../../node_modules/.bin/start-test 3700 cypress:run"
}
}
8 changes: 4 additions & 4 deletions examples/blogs__element-coverage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"description": "Showing elements the test has interacted with",
"private": true,
"scripts": {
"start": "../../node_modules/.bin/react-scripts start",
"wait-on": "../../node_modules/.bin/wait-on http://localhost:3000",
"cypress:run": "npm run wait-on && ../../node_modules/.bin/cypress run",
"cypress:open": "../../node_modules/.bin/cypress open",
"test:ci": "../../node_modules/.bin/start-test 3000 cypress:run"
"cypress:run": "npm run wait-on && ../../node_modules/.bin/cypress run",
"start": "../../node_modules/.bin/react-scripts start",
"test:ci": "../../node_modules/.bin/start-test 3000 cypress:run",
"wait-on": "../../node_modules/.bin/wait-on http://localhost:3000"
},
"browserslist": [
">0.2%",
Expand Down
12 changes: 6 additions & 6 deletions examples/blogs__testing-redux-store/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
"description": "Testing Redux store using Cypress",
"private": true,
"scripts": {
"start": "../../node_modules/.bin/react-scripts start",
"cypress:run": "../../node_modules/.bin/cypress run",
"cypress:open": "../../node_modules/.bin/cypress open",
"cypress:run": "../../node_modules/.bin/cypress run",
"start": "../../node_modules/.bin/react-scripts start",
"test:ci": "../../node_modules/.bin/start-test 3000 cypress:run"
},
"devDependencies": {
"cypress-plugin-snapshots": "1.0.6"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
],
"devDependencies": {
"cypress-plugin-snapshots": "1.0.6"
}
]
}
9 changes: 8 additions & 1 deletion examples/blogs__vue-vuex-rest/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global Vue, Vuex, axios, FileReader, window, Promise */
/* global Vue, Vuex, axios, FileReader, window */
/* eslint-disable no-console */
(function () {
Vue.use(Vuex)
Expand Down Expand Up @@ -36,6 +36,7 @@
},
REMOVE_TODO (state, todo) {
let todos = state.todos

todos.splice(todos.indexOf(todo), 1)
},
CLEAR_NEW_TODO (state) {
Expand Down Expand Up @@ -68,11 +69,13 @@
// do not add empty todos
return
}

const todo = {
title: state.newTodo,
completed: false,
id: randomId(),
}

axios.post('/todos', todo).then(() => {
commit('ADD_TODO', todo)
})
Expand All @@ -95,6 +98,7 @@
completed: false,
id: randomId(),
}

commit('ADD_TODO', todo)
resolve()
}, milliseconds)
Expand Down Expand Up @@ -161,12 +165,15 @@
// or read it off the native event
const f = this.file || e.target.files[0]
const reader = new FileReader()

reader.onload = (e) => {
const list = JSON.parse(e.target.result)

list.forEach((todo) => {
this.$store.commit('ADD_TODO', todo)
})
}

reader.readAsText(f)
},
},
Expand Down
39 changes: 22 additions & 17 deletions examples/blogs__vue-vuex-rest/cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
[{
"id": "1",
"title": "do first thing",
"completed": false
}, {
"id": "2",
"title": "do second thing",
"completed": true
}, {
"id": "3",
"title": "one more thing",
"completed": false
}, {
"id": "4",
"title": "last item on the agenda",
"completed": false
}]
[
{
"id": "1",
"title": "do first thing",
"completed": false
},
{
"id": "2",
"title": "do second thing",
"completed": true
},
{
"id": "3",
"title": "one more thing",
"completed": false
},
{
"id": "4",
"title": "last item on the agenda",
"completed": false
}
]
22 changes: 11 additions & 11 deletions examples/blogs__vue-vuex-rest/cypress/fixtures/todos.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[
{
"title": "mock first",
"completed": false,
"id": "1"
},
{
"title": "mock second",
"completed": true,
"id": "2"
}
]
{
"title": "mock first",
"completed": false,
"id": "1"
},
{
"title": "mock second",
"completed": true,
"id": "2"
}
]
8 changes: 4 additions & 4 deletions examples/blogs__vue-vuex-rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"version": "1.0.0",
"description": "Testing Vue + Vuex + REST TodoMVC using Cypress",
"scripts": {
"start": "../../node_modules/.bin/json-server --static . data.json --middlewares ../../node_modules/json-server-reset",
"cypress:run": "../../node_modules/.bin/cypress run",
"cypress:open": "../../node_modules/.bin/cypress open",
"reset:db": "node reset-db.js",
"reset": "node reset-db.js",
"cypress:run": "../../node_modules/.bin/cypress run",
"dev": "../../node_modules/.bin/start-test 3000 cypress:open",
"reset": "node reset-db.js",
"reset:db": "node reset-db.js",
"start": "../../node_modules/.bin/json-server --static . data.json --middlewares ../../node_modules/json-server-reset",
"test:ci": "../../node_modules/.bin/start-test 3000 cypress:run"
}
}
5 changes: 3 additions & 2 deletions examples/blogs__vue-vuex-rest/reset-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ const resetDatabase = () => {

// for simple cases, can just overwrite the data file
const data = {
todos: []
todos: [],
}
const str = JSON.stringify(data, null, 2) + '\n'
const str = `${JSON.stringify(data, null, 2)}\n`

write('./data.json', str)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global chai */
/// <reference types="Cypress" />
/// <reference path="../support/index.d.ts" />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global chai */
// because this file is imported from cypress/support/index.js
// that means all other spec files will have this assertion plugin
// available to them because the supportFile is bundled and served
Expand Down Expand Up @@ -32,5 +33,6 @@ const isFoo = (_chai, utils) => {

_chai.Assertion.addMethod('foo', assertIsFoo)
}

// registers our assertion function "isFoo" with Chai
chai.use(isFoo)
Loading

0 comments on commit b305396

Please sign in to comment.