Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5f102ed

Browse files
committedMay 15, 2019
initial
0 parents  commit 5f102ed

File tree

18 files changed

+9382
-0
lines changed

18 files changed

+9382
-0
lines changed
 

‎.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"plugins": ["istanbul"]
3+
}

‎.circleci/config.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: 2.1
2+
orbs:
3+
cypress: cypress-io/cypress@1.7.0
4+
jobs:
5+
release:
6+
executor: cypress/base-10
7+
steps:
8+
- attach_workspace:
9+
at: ~/
10+
- run: npm run semantic-release
11+
workflows:
12+
build:
13+
jobs:
14+
- cypress/run
15+
- release:
16+
requires:
17+
- cypress/run

‎.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules/
2+
cypress/videos
3+
cypress/screenshots
4+
coverage/
5+
.nyc_output/
6+
dist/

‎LICENSE.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## MIT License
2+
3+
Copyright (c) 2019 Cypress.io https://www.cypress.io
4+
5+
Permission is hereby granted, free of charge, to any person
6+
obtaining a copy of this software and associated documentation
7+
files (the "Software"), to deal in the Software without
8+
restriction, including without limitation the rights to use,
9+
copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the
11+
Software is furnished to do so, subject to the following
12+
conditions:
13+
14+
The above copyright notice and this permission notice shall be
15+
included in all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24+
OTHER DEALINGS IN THE SOFTWARE.

‎README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# cypress-istanbul [![renovate-app badge][renovate-badge]][renovate-app]
2+
3+
> Saves the code coverage collected from instrumented code
4+
5+
## Install
6+
7+
```shell
8+
npm install -D cypress-istanbul
9+
```
10+
11+
and its peer dependencies
12+
13+
```shell
14+
npm install -D nyc istanbul-lib-coverage cypress
15+
```
16+
17+
## License
18+
19+
This project is licensed under the terms of the [MIT license](/LICENSE.md).
20+
21+
[renovate-badge]: https://img.shields.io/badge/renovate-app-blue.svg
22+
[renovate-app]: https://renovateapp.com/

‎cypress.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"baseUrl": "http://localhost:1234",
3+
"viewportHeight": 200,
4+
"viewportWidth": 200
5+
}

‎cypress/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Cypress.io end-to-end tests
2+
3+
[Cypress.io](https://www.cypress.io) is an open source, MIT licensed end-to-end test runner
4+
5+
## Folder structure
6+
7+
These folders hold end-to-end tests and supporting files for the Cypress Test Runner.
8+
9+
- [fixtures](fixtures) holds optional JSON data for mocking, [read more](https://on.cypress.io/fixture)
10+
- [integration](integration) holds the actual test files, [read more](https://on.cypress.io/writing-and-organizing-tests)
11+
- [plugins](plugins) allow you to customize how tests are loaded, [read more](https://on.cypress.io/plugins)
12+
- [support](support) file runs before all tests and is a great place to write or load additional custom commands, [read more](https://on.cypress.io/writing-and-organizing-tests#Support-file)
13+
14+
## `cypress.json` file
15+
16+
You can configure project options in the [../cypress.json](../cypress.json) file, see [Cypress configuration doc](https://on.cypress.io/configuration).
17+
18+
## More information
19+
20+
- [https://github.com/cypress.io/cypress](https://github.com/cypress.io/cypress)
21+
- [https://docs.cypress.io/](https://docs.cypress.io/)
22+
- [Writing your first Cypress test](http://on.cypress.io/intro)

‎cypress/app.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { map } from 'lodash'
2+
3+
const list = [{ name: 'joe' }, { name: 'mary' }]
4+
const names = map(list, 'name')
5+
if (true) {
6+
console.log('just names', names)
7+
} else {
8+
console.error('never reached')
9+
}

‎cypress/fixtures/example.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "hello@cypress.io",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}

‎cypress/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<body>
2+
<h2>Test page</h2>
3+
<p>Open the DevTools to see console messages</p>
4+
<script src="app.js"></script>
5+
</body>

‎cypress/integration/spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// enables intelligent code completion for Cypress commands
2+
// https://on.cypress.io/intelligent-code-completion
3+
/// <reference types="Cypress" />
4+
5+
context('Page test', () => {
6+
beforeEach(() => {
7+
cy.visit('/', {
8+
onBeforeLoad (win) {
9+
cy.spy(win.console, 'log').as('log')
10+
}
11+
})
12+
})
13+
14+
it('logs names', function () {
15+
cy.get('@log')
16+
.should('have.been.calledOnce')
17+
.should('have.been.calledWith', 'just names', ['joe', 'mary'])
18+
})
19+
})

‎cypress/plugins/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = (on, config) => {
2+
on('task', require('../../task'))
3+
}

‎cypress/support/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '../../support'

‎package-lock.json

Lines changed: 9079 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"name": "cypress-istanbul",
3+
"version": "1.0.0",
4+
"description": "Saves the code coverage collected from instrumented code",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "cypress run",
8+
"start": "parcel serve cypress/index.html",
9+
"cy:open": "cypress open",
10+
"dev": "start-test 1234 cy:open"
11+
},
12+
"peerDependencies": {
13+
"cypress": "*",
14+
"nyc": "*",
15+
"istanbul-lib-coverage": "*"
16+
},
17+
"repository": {
18+
"type": "git",
19+
"url": "git+https://github.com/cypress-io/cypress-istanbul.git"
20+
},
21+
"keywords": [
22+
"cypress",
23+
"istanbul",
24+
"cypress-plugin",
25+
"code",
26+
"coverage"
27+
],
28+
"author": "Gleb Bahmutov <gleb.bahmutov@gmail.com>",
29+
"license": "MIT",
30+
"bugs": {
31+
"url": "https://github.com/cypress-io/cypress-istanbul/issues"
32+
},
33+
"homepage": "https://github.com/cypress-io/cypress-istanbul#readme",
34+
"files": [
35+
"*.js"
36+
],
37+
"devDependencies": {
38+
"@babel/core": "7.4.4",
39+
"babel-plugin-istanbul": "5.1.4",
40+
"cypress": "3.2.0",
41+
"istanbul-lib-coverage": "2.0.5",
42+
"lodash": "4.17.11",
43+
"nyc": "14.1.1",
44+
"parcel-bundler": "1.12.3",
45+
"start-server-and-test": "1.9.0"
46+
}
47+
}

‎renovate.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"extends": [
3+
"config:base"
4+
],
5+
"automerge": true,
6+
"major": {
7+
"automerge": false
8+
},
9+
"prHourlyLimit": 2,
10+
"updateNotScheduled": false,
11+
"timezone": "America/New_York",
12+
"schedule": [
13+
"every weekend"
14+
],
15+
"masterIssue": true
16+
}

‎support.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/// <reference types="cypress" />
2+
before(() => {
3+
// we need to reset the coverage when running
4+
// in the interactive mode, otherwise the counters will
5+
// keep increasing every time we rerun the tests
6+
cy.task('resetCoverage', { isInteractive: Cypress.config('isInteractive') })
7+
})
8+
9+
afterEach(() => {
10+
// save coverage after each test
11+
// because the entire "window" object is about
12+
// to be recycled by Cypress before next test
13+
cy.window().then(win => {
14+
if (win.__coverage__) {
15+
cy.task('combineCoverage', win.__coverage__)
16+
}
17+
})
18+
})
19+
20+
after(() => {
21+
// when all tests finish, lets generate the coverage report
22+
cy.task('coverageReport')
23+
})

‎task.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
const istanbul = require('istanbul-lib-coverage')
2+
const { join } = require('path')
3+
const { existsSync, mkdirSync, readFileSync, writeFileSync } = require('fs')
4+
const execa = require('execa')
5+
6+
// these are standard folder and file names used by NYC tools
7+
const outputFolder = '.nyc_output'
8+
const coverageFolder = join(process.cwd(), outputFolder)
9+
const nycFilename = join(coverageFolder, 'out.json')
10+
11+
function saveCoverage (coverage) {
12+
if (!existsSync(coverageFolder)) {
13+
mkdirSync(coverageFolder)
14+
console.log('created folder %s for output coverage', coverageFolder)
15+
}
16+
17+
writeFileSync(nycFilename, JSON.stringify(coverage, null, 2))
18+
}
19+
20+
module.exports = {
21+
/**
22+
* Clears accumulated code coverage information.
23+
*
24+
* Interactive mode with "cypress open"
25+
* - running a single spec or "Run all specs" needs to reset coverage
26+
* Headless mode with "cypress run"
27+
* - runs EACH spec separately, so we cannot reset the coverage
28+
* or we will lose the coverage from previous specs.
29+
*/
30+
resetCoverage ({ isInteractive }) {
31+
if (isInteractive) {
32+
console.log('reset code coverage in interactive mode')
33+
const coverageMap = istanbul.createCoverageMap({})
34+
saveCoverage(coverageMap)
35+
}
36+
/*
37+
Else:
38+
in headless mode, assume the coverage file was deleted
39+
before the `cypress run` command was called
40+
example: rm -rf .nyc_output || true
41+
*/
42+
43+
return null
44+
},
45+
46+
/**
47+
* Combines coverage information from single test
48+
* with previously collected coverage.
49+
*/
50+
combineCoverage (coverage) {
51+
const previous = existsSync(nycFilename)
52+
? JSON.parse(readFileSync(nycFilename))
53+
: istanbul.createCoverageMap({})
54+
const coverageMap = istanbul.createCoverageMap(previous)
55+
coverageMap.merge(coverage)
56+
saveCoverage(coverageMap)
57+
console.log('wrote coverage file %s', nycFilename)
58+
59+
return null
60+
},
61+
62+
/**
63+
* Saves coverage information as a JSON file and calls
64+
* NPM script to generate HTML report
65+
*/
66+
coverageReport () {
67+
if (!existsSync(nycFilename)) {
68+
console.warn('Cannot find coverage file %s', nycFilename)
69+
console.warn('Skipping coverage report')
70+
return null
71+
}
72+
console.log('saving coverage report')
73+
// should we generate report via NYC module API?
74+
return execa('nyc', ['report', '--reporter=html'], { stdio: 'inherit' })
75+
}
76+
}

0 commit comments

Comments
 (0)
Please sign in to comment.