Angular + Cypress 코드 검사보고가 작동하지 않음

Monkeeman69

Angular 프로덕션 프로젝트에서 Cypress 코드 커버리지를 사용하지 않으려 고 노력했습니다.

이를 진단하기 위해 최소한의 구현 프로젝트를 만들어 프로덕션 버전에서 이상한 것을 도입하지 않았는지 확인했습니다. 동일한 문제가 여전히 발생하고 있다고 생각하지 않습니다. 그것은 나를 미치게 만들기 시작했다!

나는 몇 가지 참고 문헌을 사용했으며 내가 볼 수있는 한 다음과 같은 작업을 수행해야합니다.

내가 알 수있는 한 Angular와 Cypress 측은 모두 연결되어 있고 .nyc_output 폴더와 커버리지 보고서에 출력을 얻고 있습니다. 그러나 보고서는 타이프 스크립트 줄 범위를 나타내거나 이러한 통계를 포함하지 않습니다.

여기에 이미지 설명 입력 여기에 이미지 설명 입력

나는 이것을 보았지만 도움이되지 않는 것 같습니다.

코드 계측 (웹팩 확장 + angular.json) :

module.exports = {
  module: {
    rules: [
      {
        test: /\.(js|ts)$/,
        loader: "istanbul-instrumenter-loader",
        options: { esModules: true },
        enforce: "post",
        include: require("path").join(__dirname, "..", "src"),
        exclude: [
          /\.(e2e|spec)\.ts$/,
          /node_modules/,
          /(ngfactory|ngstyle)\.js/,
        ],
      },
    ],
  },
};
"serve": {
          "builder": "ngx-build-plus:dev-server",
          "options": {
            "browserTarget": "architecture-testing:build",
            "extraWebpackConfig": "./cypress/coverage.webpack.js",
            "sourceMap": true
          },
          "configurations": {
            "production": {
              "browserTarget": "architecture-testing:build:production"
            }
          }
        }

Cypress가 적용 범위를 기록하고 저장하는 것으로 보입니다.

const registerCodeCoverageTasks = require("@cypress/code-coverage/task");

module.exports = (on, config) => {
  registerCodeCoverageTasks(on, config);

  return config;
};

여기에 이미지 설명 입력 여기에 이미지 설명 입력

out.json이 올바른 파일 및 코드 매핑을 가지고있는 것 같습니다.

여기에 이미지 설명 입력 여기에 이미지 설명 입력 여기에 이미지 설명 입력:

package.json (nyc 구성 + deps) :

{
  "name": "architecture-testing",
  "version": "0.0.0",
  "scripts": {
    "postinstall": "ngcc",
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "precypress": "rimraf .nyc_output coverage",
    "cypress": "ng run architecture-testing:cypress-run",
    "cypress:open": "cypress open",
    "cypress:run": "cypress run"
  },
  "nyc": {
    "extends": "@istanbuljs/nyc-config-typescript",
    "all": true,
    "exclude": [
      "coverage/**",
      "cypress/**",
      "**/*.spec.ts"
    ]
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~9.1.9",
    "@angular/common": "~9.1.9",
    "@angular/compiler": "~9.1.9",
    "@angular/core": "~9.1.9",
    "@angular/forms": "~9.1.9",
    "@angular/platform-browser": "~9.1.9",
    "@angular/platform-browser-dynamic": "~9.1.9",
    "@angular/router": "~9.1.9",
    "rxjs": "~6.5.4",
    "tslib": "^1.10.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.901.7",
    "@angular/cli": "~9.1.7",
    "@angular/compiler-cli": "~9.1.9",
    "@briebug/cypress-schematic": "^3.3.0",
    "@cypress/code-coverage": "^3.8.1",
    "@cypress/webpack-preprocessor": "5.4.1",
    "@istanbuljs/nyc-config-typescript": "^1.0.1",
    "@types/node": "^12.11.1",
    "codelyzer": "^5.1.2",
    "cypress": "^4.8.0",
    "istanbul-instrumenter-loader": "^3.0.1",
    "istanbul-lib-coverage": "^3.0.0",
    "ngx-build-plus": "^9.0.6",
    "nyc": "^15.1.0",
    "rimraf": "^3.0.2",
    "source-map-support": "^0.5.19",
    "ts-loader": "7.0.5",
    "ts-node": "^8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~3.8.3"
  }
}

사양 파일 :

it('does something', () => {
  cy.visit('http://localhost:4200');
  cy.get('[data-cy=button-one]').click();
  cy.get('[data-cy=button-output]').should('have.text', 'you clicked button 1');
});

너무 길어서 미안하지만 다음에 어디로 가야할지 고민 중입니다. 어떤 방향 으로든 나를 가리킬 수 있다면 많은 감사합니다.

답변 조사에 따른 업데이트 :

Looking at the past versions of the @cypress/code-coverage it appears the issue for me was introduced in v3.3.0 of the plugin. All the versions for v3.2.* were working for me when downgrading my minimal project. After looking at the documentation changes for v3.3.0 the key bit of information in the readme was:

**Note:** if you have `all: true` NYC option set, this plugin will check the produced `.nyc_output/out.json` before generating the final report. If the `out.json` file does not have information for some files that should be there according to `include` list, then an empty placeholder will be included, see [PR 208](https://github.com/cypress-io/code-coverage/pull/208).

My original nyc config was:

  "nyc": {
    "extends": "@istanbuljs/nyc-config-typescript",
    "all": true,
    "exclude": [
      "coverage/**",
      "cypress/**",
      "**/*.spec.ts"
    ]
  }

So for some reason even though I have metrics for the files that were being tested in out.json a second "empty placeholder" node was being created and overiding the subsequent report generation. I am guessing that this is potentially a bug or a problem with my setup again so will ask the creators.

I can now see coverage if I change my nyc config to:

  "nyc": {
    "extends": "@istanbuljs/nyc-config-typescript",
    "all": true,
    "include": [
      "src/**/*.ts"
    ],
    "exclude": [
      "coverage/**",
      "cypress/**",
      "**/*.spec.ts"
    ]
  }

This does mean that if I don't hit a file with testing it won't be included as an empty placeholder as "all": true is no longer present.

Looking at @briebug/[email protected] this doesn't appear to be causing any issues (same happens without using their builder) but has been raised as one here and here.

Richard Matsen

Comparing ang-cy-cov-example to your package.json, a major difference is that he uses @cypress/[email protected] where-as you have the latest v3.8.1.

Changing back to this v1.14.0 works ok with your setup. Since your info indicates data is appearing in .nyc_output/out.json, I tested with the command line ./node_modules/.bin/nyc report which gives a quick view in the console.

Comparing .nyc_output/out.json between the two versions, the individual nodes are structurally the same, i.e have the correct sections (path, statementMap, inputSourceMap etc).

There are two types of additional nodes

  • additional files such as karma.conf.js, coverage.webpack.js, cy-ts-preprocessor.js, integration/spec.ts, support/commands.ts - which we are not interested in.

  • the files we are interested in are duplicated at the end of the file but the duplicates have no coverage metrics.

e.g

First copy of main.ts with metrics

  "path-to\\src\\main.ts": {
    "path": "path-to\\src\\main.ts",
    "statementMap": {
         ...
      },
      "1": {
         ...
      },
      "2": {
         ...
      }
    },
    "fnMap": {},
    "branchMap": {
         ...
    },
    "s": {
      "0": 1,   // indicates one visit to this statement
      "1": 0,
      "2": 1
    },
    "f": {},
    "b": {
      "0": [
        0,
        1
      ]
    },
    "inputSourceMap": {
         ...
    },
    "_coverageSchema": "332fd63041d2c1bcb487cc26dd0d5f7d97098a6c",
    "hash": "5959c383a9744c99a600a28ff82b12f0a540c5e6"
  },

Second copy of main.ts with no metrics

  "path-to/src/main.ts": {
    "path": "path-to/src/main.ts",
    "statementMap": {},
    "fnMap": {},
    "branchMap": {},
    "s": {},          // no metrics recorded here
    "f": {},
    "b": {}
  },

So, conclusion is the NYC report is replacing the first nodes metrics with the empty metrics of the second node.

I skipped back through the versions, v3.2.0 was the latest I found working.

Also note this warning when adding node modules, but can't say if it is a contributing factor.

warning " > @briebug/[email protected]" has incorrect peer dependency "cypress@^3.6.1"


Point of failure

The basic problem is in task-utils.js.

모든 파일을 가져 오는 ref

const allFiles = globby.sync(patterns, { absolute: true })

경우 globby에도 Windows에서 슬래시와 반환 경로

및 ref getting coveredPaths

const coveredPaths = coverageKeys.map(key => nycCoverage[key].path)

out.jsonWindows에서 백 슬래시로 키가 저장되는 위치 .

빠른 해결 방법은이 시점에서 경로를 정규화하는 것입니다.

const coveredPaths = coverageKeys.map(key => nycCoverage[key].path)
  .map(path => path.replace(/\\/g, '/'))  // Compare "normalized" paths 

'/node_modules/@cypress/code-coverage/task-utils.js'를 패치하면 문제가 해결됩니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Angular JS 코드가 작동하지 않음

분류에서Dev

cURL 코드가 작동하지 않음

분류에서Dev

CSRF 코드가 작동하지 않음

분류에서Dev

코드가 작동하지 않음 (JavaScript)

분류에서Dev

recursetree 코드가 작동하지 않음

분류에서Dev

WebGL 코드가 작동하지 않음

분류에서Dev

코드가 작동하지 않음

분류에서Dev

Ansible 코드가 작동하지 않음

분류에서Dev

정규식 검사 C # 코드가 작동하지 않음

분류에서Dev

Angular JS + CoffeeScript + JSFiddle : 코드가 작동하지 않습니다.

분류에서Dev

내 Angular 코드가 Plunker에서 작동하지 않습니다.

분류에서Dev

Angular JS 코드가 작동하지 않습니다.

분류에서Dev

동일한 코드가 동일하게 작동하지 않음

분류에서Dev

Angular 6.4.1 환경 빌드가 작동하지 않음

분류에서Dev

Angular2에서 POST 메서드가 작동하지 않음

분류에서Dev

Angular-cli 빌드 생성 CSS가 작동하지 않음

분류에서Dev

PHP 이미지 업로드 코드가 작동하지 않음

분류에서Dev

무작위 코드가 제대로 작동하지 않음

분류에서Dev

setTimeout을 사용할 때 코드가 작동하지 않음

분류에서Dev

Powershell CD 사이트 코드가 작동하지 않음

분류에서Dev

CakePHP 3.x 고유 유효성 검사가 여러 레코드 저장에 작동하지 않음

분류에서Dev

Angular Broadcast가 작동하지 않음

분류에서Dev

클라우드 코드가 작동하지 않음

분류에서Dev

노드 콜백-코드가 작동하지 않음

분류에서Dev

WPF 지역화가 코드 뒤에서 작동하지 않음

분류에서Dev

쿠키 감지 코드가 작동하지 않음

분류에서Dev

WebGL 코드가 작동하지 않음-빈 페이지

분류에서Dev

Angular ng-show가 초기 페이지로드에서 작동하지 않음

분류에서Dev

새 행 추가, jQuery 코드가 작동하지 않음

Related 관련 기사

  1. 1

    Angular JS 코드가 작동하지 않음

  2. 2

    cURL 코드가 작동하지 않음

  3. 3

    CSRF 코드가 작동하지 않음

  4. 4

    코드가 작동하지 않음 (JavaScript)

  5. 5

    recursetree 코드가 작동하지 않음

  6. 6

    WebGL 코드가 작동하지 않음

  7. 7

    코드가 작동하지 않음

  8. 8

    Ansible 코드가 작동하지 않음

  9. 9

    정규식 검사 C # 코드가 작동하지 않음

  10. 10

    Angular JS + CoffeeScript + JSFiddle : 코드가 작동하지 않습니다.

  11. 11

    내 Angular 코드가 Plunker에서 작동하지 않습니다.

  12. 12

    Angular JS 코드가 작동하지 않습니다.

  13. 13

    동일한 코드가 동일하게 작동하지 않음

  14. 14

    Angular 6.4.1 환경 빌드가 작동하지 않음

  15. 15

    Angular2에서 POST 메서드가 작동하지 않음

  16. 16

    Angular-cli 빌드 생성 CSS가 작동하지 않음

  17. 17

    PHP 이미지 업로드 코드가 작동하지 않음

  18. 18

    무작위 코드가 제대로 작동하지 않음

  19. 19

    setTimeout을 사용할 때 코드가 작동하지 않음

  20. 20

    Powershell CD 사이트 코드가 작동하지 않음

  21. 21

    CakePHP 3.x 고유 유효성 검사가 여러 레코드 저장에 작동하지 않음

  22. 22

    Angular Broadcast가 작동하지 않음

  23. 23

    클라우드 코드가 작동하지 않음

  24. 24

    노드 콜백-코드가 작동하지 않음

  25. 25

    WPF 지역화가 코드 뒤에서 작동하지 않음

  26. 26

    쿠키 감지 코드가 작동하지 않음

  27. 27

    WebGL 코드가 작동하지 않음-빈 페이지

  28. 28

    Angular ng-show가 초기 페이지로드에서 작동하지 않음

  29. 29

    새 행 추가, jQuery 코드가 작동하지 않음

뜨겁다태그

보관