Skip to content
This repository has been archived by the owner on May 24, 2021. It is now read-only.

Commit

Permalink
chore: setup CI, linting, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kuceb committed Sep 10, 2019
1 parent 50f3ac2 commit a520ead
Show file tree
Hide file tree
Showing 11 changed files with 5,978 additions and 59 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ cypress/videos
cypress/screenshots
*.xml
*.iml
yarn.lock
27 changes: 27 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"eslint.alwaysShowStatus": true,
"eslint.autoFixOnSave": true,
"eslint.validate": [
{
"language": "javascript",
"autoFix": true
},
{
"language": "javascriptreact",
"autoFix": true
},
{
"language": "typescript",
"autoFix": true
},
{
"language": "typescriptreact",
"autoFix": true
},
{
"language": "json",
"autoFix": true
},
],
}

32 changes: 32 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: 2.1
jobs:
test:
docker:
- image: cypress/base:10
steps:
- checkout
- restore_cache:
keys:
- cache-{{ arch }}-{{ .Branch }}-{{ checksum "package.json" }}
- run:
name: Yarn install
command: yarn install --frozen-lockfile
- save_cache:
key: cache-{{ arch }}-{{ .Branch }}-{{ checksum "package.json" }}
paths:
- ~/.cache
- run:
command: yarn lint
- run:
command: yarn test
- run:
command: yarn run semantic-release
workflows:
build:
jobs:
- test
version: 2

# Semantic-release bot needs env vars:
# GH_TOKEN: read:org, repo, user:email, write:repo_hook
# NPM_TOKEN: read/release
2 changes: 1 addition & 1 deletion cypress.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"projectId": "3e57fb"
"projectId": "3e57fb"
}
71 changes: 48 additions & 23 deletions cypress/integration/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,54 @@
Cypress.config('defaultCommandTimeout', 100)
Cypress.env('RETRIES', 0)

const _ = Cypress._

describe('Cypress.currentTest', () => {
let error
let curtest
try{
curtest = Cypress.currentTest
} catch(e) {

try {
Cypress.currentTest
} catch (e) {
error = e
}

let lastId

it('throws error outside spec', function() {
it('throws error outside spec', function () {
expect(error).ok.property('message').contains('currentTest')
expect(this._runnable).eq(Cypress.currentTest)
curtest = Cypress.currentTest
Cypress.currentTest
expect(lastId).eq(this._runnable.id)
})

beforeEach(() => {
lastId = Cypress.currentTest.id
})

// Cypress.log({message:'set'})
it('gets correct runnable', () => {
expect(lastId).eq(Cypress.currentTest.id)
})
})

describe('deeply nested', () => {
const pushHook = name => {
const pushHook = (name) => {
// console.log(`%c${name}`, 'color:blue')
expect(name).ok
hooks.push(name)
}
let hooks = []
let foo = 0

const failUntil = num => {
const failUntil = (num) => {
if (num === true) {
expect(false).ok
}

if (foo <= num) {
cy.get('failOn' + foo)
cy.get(`failOn${foo}`)
}
}

cy.on('fail', err => {
cy.on('fail', (err) => {
hooks.push('FAIL')
throw err
})
Expand All @@ -59,10 +60,12 @@ describe('deeply nested', () => {
pushHook('BE 0')
foo++
})

describe('1', () => {
before(() => {
pushHook('B 1')
})

beforeEach(() => {
pushHook('BE 1')
failUntil(1)
Expand All @@ -73,12 +76,15 @@ describe('deeply nested', () => {
pushHook('BE 2')
failUntil(2)
})

beforeEach(() => {
pushHook('BE 2 B')
})

beforeEach(() => {
pushHook('BE 2 C')
})

it('T 2', () => {
pushHook('T 2')
failUntil(3)
Expand All @@ -104,29 +110,35 @@ describe('deeply nested', () => {
'BE 2',
'BE 2 B',
'BE 2 C',
'T 2'
'T 2',
])

hooks = []
})

it('T 2 B', () => {
pushHook('T 2 B')
failUntil(4)
})
afterEach(function() {

afterEach(function () {
pushHook('AE 2')
})
})
afterEach(function() {

afterEach(function () {
pushHook('AE 1')
})
afterEach(function() {

afterEach(function () {
pushHook('AE 1 B')
})
})

afterEach(() => {
pushHook('AE 0')
})

after(() => {
pushHook('AA 0')
expect(hooks).deep.eq([
Expand All @@ -144,29 +156,32 @@ describe('deeply nested', () => {
'AE 1',
'AE 1 B',
'AE 0',
'AA 0'
'AA 0',
])
})
})

describe('async', () => {
it('pass using done', function(done) {
cy.on('fail', err => {
it('pass using done', function (done) {
cy.on('fail', (err) => {
done()
})

expect(false).ok
})
})

describe('fail 10 times', function() {
describe('fail 10 times', function () {
this.retries(10)

let foo = 0

beforeEach(() => {
foo++
expect(foo).gt(2)
})
it('test', function() {

it('test', function () {
expect(foo).gt(10)
expect(this._runnable.currentRetry()).eq(10)
})
Expand All @@ -180,9 +195,11 @@ describe('retries set via Cypress.currentTest.retries', () => {
if (!Cypress.currentTest._currentRetry) {
logs = []
}

cy.on('log:added', (attr, log) => {
logs.push(attr)
})

Cypress.currentTest.retries(1)
})

Expand All @@ -206,38 +223,46 @@ describe('after all hook', () => {
it('fails but caught', () => {
expect(true).ok
})

after(() => {
cy.on('fail', err => {
cy.on('fail', (err) => {
didFail = true
// Cypress.log({message: didFail})
// throw err
})

expect(false).ok
})
})

describe('verify prev fail', () => {
it('did fail', () => {
expect(didFail).ok
})
})
})

describe('after hook lets test fail', () => {
let didFail = false
let didRunAfterHook = false

describe('should fail in after hook', () => {
it('fails but caught', () => {
cy.on('fail', err => {
cy.on('fail', (err) => {
didFail = true
// Cypress.log({message: didFail})
// throw err
})

expect(false).ok
})

after(() => {
didRunAfterHook = true
expect(true).ok
})
})

describe('verify prev fail', () => {
it('did fail', () => {
expect(didFail).ok
Expand Down
2 changes: 1 addition & 1 deletion cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ import './commands'
// Alternatively you can use CommonJS syntax:
// require('./commands')

require('../../')
require('../../')
28 changes: 23 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,27 @@
"description": "Cypress plugin allowing tests to retry a configurable amount of times",
"main": "src",
"scripts": {
"test": "node test.js"
"lint": "eslint --ext json,js,ts .",
"test": "cypress run"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"devDependencies": {
"@cypress/eslint-plugin-dev": "^3.7.1",
"@cypress/eslint-plugin-json": "^3.2.1",
"@cypress/eslint-plugin-dev": "^4.0.0",
"@typescript-eslint/eslint-plugin": "^2.2.0",
"@typescript-eslint/parser": "^2.2.0",
"cypress": "^3.1.5",
"eslint": "^5.16.0",
"eslint-plugin-cypress": "^2.6.0",
"eslint-plugin-mocha": "^6.0.0"
"eslint-plugin-json-format": "^2.0.1",
"eslint-plugin-mocha": "^6.0.0",
"husky": "^3.0.5",
"lint-staged": "^9.2.5",
"semantic-release": "^15.13.24",
"typescript": "^3.6.2"
},
"license": "MIT",
"repository": {
Expand All @@ -24,5 +36,11 @@
"cypress",
"plugin",
"retry"
]
],
"lint-staged": {
"*.{js,jsx,ts,tsx,json,eslintrc}": [
"eslint --fix",
"git add"
]
}
}
1 change: 0 additions & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@
currentTest: Mocha.ISuiteCallbackContext
}
}

Loading

0 comments on commit a520ead

Please sign in to comment.