From 030143f3480e54b3ea4e18ec667af75d06bb743b Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Fri, 30 Oct 2020 23:30:22 +0200 Subject: [PATCH] Flow: remove support for measuring Flow coverage (#2837) --- .github/workflows/ci.yml | 2 +- .nycflowrc.yml | 10 ----- .nycrc.yml | 5 +-- package.json | 1 - resources/check-cover.js | 87 ---------------------------------------- 5 files changed, 3 insertions(+), 102 deletions(-) delete mode 100644 .nycflowrc.yml delete mode 100644 resources/check-cover.js diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 342732d1d5e..9a6a36b4837 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -137,7 +137,7 @@ jobs: if: ${{ always() }} uses: codecov/codecov-action@v1 with: - file: ./coverage/tests/coverage-final.json + file: ./coverage/coverage-final.json fail_ci_if_error: true test: diff --git a/.nycflowrc.yml b/.nycflowrc.yml deleted file mode 100644 index 4032fdd014a..00000000000 --- a/.nycflowrc.yml +++ /dev/null @@ -1,10 +0,0 @@ -include: - - 'src/' -exclude: - - 'src/polyfills' -clean: true -temp-directory: 'coverage/flow' -report-dir: 'coverage/flow' -skip-full: true -skip-empty: true -reporter: [json, html, text] diff --git a/.nycrc.yml b/.nycrc.yml index 765e27b0c20..91de70cb7bb 100644 --- a/.nycrc.yml +++ b/.nycrc.yml @@ -4,11 +4,10 @@ include: exclude: - 'src/polyfills' - '**/*-fuzz.js' - - '**/*-benchmark.js' - '**/*.d.ts' clean: true -temp-directory: 'coverage/tests' -report-dir: 'coverage/tests' +temp-directory: 'coverage' +report-dir: 'coverage' skip-full: true reporter: [json, html, text] check-coverage: true diff --git a/package.json b/package.json index 36c5f3f399d..6c8409a2f61 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,6 @@ "test": "npm run lint && npm run check && npm run testonly && npm run prettier:check && npm run check:spelling && npm run build:npm && npm run build:deno && npm run check:integrations", "lint": "eslint --cache .", "check": "flow check", - "check:cover": "node resources/check-cover.js && nyc report --nycrc-path .nycflowrc.yml", "testonly": "mocha --full-trace src/**/__tests__/**/*-test.js", "testonly:cover": "nyc npm run testonly", "prettier": "prettier --write --list-different .", diff --git a/resources/check-cover.js b/resources/check-cover.js deleted file mode 100644 index 3935ef9b215..00000000000 --- a/resources/check-cover.js +++ /dev/null @@ -1,87 +0,0 @@ -'use strict'; - -const fs = require('fs'); -const path = require('path'); - -const { - exec, - execAsync, - rmdirRecursive, - readdirRecursive, -} = require('./utils'); - -rmdirRecursive('./coverage/flow'); -getFullCoverage() - .then((fullCoverage) => { - fs.mkdirSync('./coverage/flow', { recursive: true }); - fs.writeFileSync( - './coverage/flow/full-coverage.json', - JSON.stringify(fullCoverage), - ); - }) - .catch((error) => { - console.error(error.stack); - process.exit(1); - }); - -async function getFullCoverage() { - const fullCoverage = {}; - - exec('flow start --quiet'); - try { - exec('flow check', { stdio: 'inherit' }); - - // TODO: measure coverage for all files. ATM missing types for chai & mocha - const files = readdirRecursive('./src', { ignoreDir: /^__.*__$/ }) - .filter((filepath) => filepath.endsWith('.js')) - .map((filepath) => path.join('src/', filepath)); - - await Promise.all(files.map(getCoverage)).then((coverages) => { - for (const coverage of coverages) { - fullCoverage[coverage.path] = coverage; - } - }); - } finally { - exec('flow stop --quiet'); - } - return fullCoverage; -} - -async function getCoverage(filepath) { - const json = await execAsync(`flow coverage --json ${filepath}`); - const flowExpressions = JSON.parse(json).expressions; - - const s = {}; - const statementMap = {}; - let id = 0; - for (const coveredExp of flowExpressions.covered_locs) { - s[id] = 1; - statementMap[id] = covertLocation(coveredExp); - ++id; - } - - for (const uncoveredExp of flowExpressions.uncovered_locs) { - s[id] = 0; - statementMap[id] = covertLocation(uncoveredExp); - ++id; - } - - // istanbul format, see: - // https://github.com/gotwarlost/istanbul/blob/master/coverage.json.md - return { - path: filepath, - b: {}, - branchMap: {}, - f: {}, - fnMap: {}, - s, - statementMap, - }; -} - -function covertLocation(flow) { - return { - start: { line: flow.start.line, column: flow.start.column - 1 }, - end: { line: flow.end.line, column: flow.end.column - 1 }, - }; -}