Skip to content

Commit

Permalink
The change in the measurement of CVAT-UI code coverage. (#2295)
Browse files Browse the repository at this point in the history
* The change in the measurement of CVAT-UI code coverage.

* Firefox to cron without coverage.

PR, push coverage via Chrome.

* Refactoring .travis.yml.

Added a wait of 10 seconds in the first test to prevent a login error in CVAT after rebuilding containers after code instrumentation.

Co-authored-by: Kruchinin <[email protected]>
  • Loading branch information
dvkruchinin and Kruchinin authored Oct 16, 2020
1 parent c50e3ef commit 70e89d6
Show file tree
Hide file tree
Showing 8 changed files with 5,206 additions and 504 deletions.
2 changes: 0 additions & 2 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{
"all": true,
"recursive": true,
"compact": false,
"useInlineSourceMaps": false,
"extension": [
".js",
".jsx",
Expand Down
25 changes: 10 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ cache:

addons:
firefox: "latest"
chrome: stable
apt:
packages:
- libgconf-2-4
Expand All @@ -34,27 +35,21 @@ before_script:

script:
- docker-compose -f docker-compose.yml -f docker-compose.ci.yml run cvat_ci /bin/bash -c 'coverage run -a manage.py test cvat/apps utils/cli && mv .coverage ${CONTAINER_COVERAGE_DATA_DIR}'
- docker-compose -f docker-compose.yml -f docker-compose.ci.yml run cvat_ci /bin/bash -c 'cd cvat-data && npm install && cd ../cvat-core && npm install && npm run test && coveralls-lcov -v -n ./reports/coverage/lcov.info > ${CONTAINER_COVERAGE_DATA_DIR}/coverage.json'
- docker-compose -f docker-compose.yml -f docker-compose.ci.yml run cvat_ci /bin/bash -c 'cd cvat-data && npm install && cd ../cvat-core && npm install && npm run test && mv ./reports/coverage/lcov.info ${CONTAINER_COVERAGE_DATA_DIR} && chmod a+rwx ${CONTAINER_COVERAGE_DATA_DIR}/lcov.info'
- docker-compose up -d
# Create superuser
- docker exec -it cvat bash -ic "echo \"from django.contrib.auth.models import User; User.objects.create_superuser('${DJANGO_SU_NAME}', '${DJANGO_SU_EMAIL}', '${DJANGO_SU_PASSWORD}')\" | python3 ~/manage.py shell"
# End-to-end testing
- cd ./tests && npm install && cd ..
- if [[ $TRAVIS_EVENT_TYPE == "cron" && $TRAVIS_BRANCH == "develop" ]];
then
cd ./tests && npm install &&
npm run cypress:run:firefox && cd .. &&
npm install &&
npm run coverage &&
docker-compose up -d --build &&
cd ./tests &&
npm run cypress:run:chrome && cd .. &&
npm run report:coverage:text &&
npm run report:coverage:lcov;
else
cd ./tests && npm install &&
npm run cypress:run:chrome && cd ..;
cd ./tests && npm run cypress:run:firefox && exit $?;
fi;

- npm install && npm run coverage
- docker-compose up -d --build
- cd ./tests && npx cypress run --headless --browser chrome
- mv ./.nyc_output ../ && cd ..
- npx nyc report --reporter=text-lcov >> ${HOST_COVERAGE_DATA_DIR}/lcov.info
- docker-compose -f docker-compose.yml -f docker-compose.ci.yml run cvat_ci /bin/bash -c 'cd ${CONTAINER_COVERAGE_DATA_DIR} && coveralls-lcov -v -n lcov.info > ${CONTAINER_COVERAGE_DATA_DIR}/coverage.json'

after_success:
# https://coveralls-python.readthedocs.io/en/latest/usage/multilang.html
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@
"coverage": "npm run instrument && npm run cp && npm run rm",
"instrument": "nyc instrument cvat-ui cvat-ui_cov && nyc instrument cvat-canvas cvat-canvas_cov && nyc instrument cvat-data cvat-data_cov && nyc instrument cvat-core cvat-core_cov",
"cp": "cp -r cvat-ui_cov/* cvat-ui && cp -r cvat-canvas_cov/* cvat-canvas && cp -r cvat-data_cov/* cvat-data && cp -r cvat-core_cov/* cvat-core",
"rm": "rm -rf cvat-ui_cov && rm -rf cvat-canvas_cov && rm -rf cvat-data_cov && rm -r cvat-core_cov",
"report:coverage:text": "nyc report --reporter=text",
"report:coverage:lcov": "nyc report --reporter=text-lcov | coveralls"
"rm": "rm -rf cvat-ui_cov cvat-canvas_cov cvat-data_cov cvat-core_cov"
},
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions tests/cypress/integration/auth_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ describe('Check server availability', () => {

it('Click to "Sign in" button', () => {
cy.get('[type="submit"]').click()
cy.wait(10000)
})
})
36 changes: 3 additions & 33 deletions tests/cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,8 @@

const {imageGenerator} = require('../plugins/imageGenerator/addPlugin')
const {createZipArchive} = require('../plugins/createZipArchive/addPlugin')
const istanbul = require('istanbul-lib-coverage')
const { join } = require('path')
const { existsSync, mkdirSync, writeFileSync } = require('fs')
const execa = require('execa')

module.exports = (on) => {
let coverageMap = istanbul.createCoverageMap({})
const outputFolder = '../.nyc_output'
const nycFilename = join(outputFolder, 'out.json')

if (!existsSync(outputFolder)) {
mkdirSync(outputFolder)
console.log('created folder %s for output coverage', outputFolder)
}

module.exports = (on, config) => {
require('@cypress/code-coverage/task')(on, config)
on('task', {imageGenerator})
on('task', {createZipArchive})
on('task', {
Expand All @@ -31,22 +18,5 @@ module.exports = (on) => {
return null
}
})
on('task', {
/**
* Combines coverage information from single test
* with previously collected coverage.
*/
combineCoverage (coverage) {
coverageMap.merge(coverage)
return null
},

/**
* Saves coverage information as a JSON file and calls
*/
coverageReportPrepare () {
writeFileSync(nycFilename, JSON.stringify(coverageMap, null, 2))
return null
}
})
return config
}
17 changes: 1 addition & 16 deletions tests/cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import './commands'
import '@cypress/code-coverage/support'

before(() => {
if (Cypress.browser.name === 'firefox') {
Expand All @@ -18,19 +19,3 @@ before(() => {
})
}
})

afterEach(() => {
if (Cypress.browser.name === 'chrome') {
cy.window().then(win => {
if (win.__coverage__) {
cy.task('combineCoverage', win.__coverage__)
}
})
}
})

after(() => {
if (Cypress.browser.name === 'chrome') {
cy.task('coverageReportPrepare')
}
})
Loading

0 comments on commit 70e89d6

Please sign in to comment.