Z
Z
zorro32022-03-01 22:32:07
JavaScript
zorro3, 2022-03-01 22:32:07

Why doesn't code coverage change when I test a function?

I want to cover the file with unit tests, I noticed that the coverage does not work, I wrote a test function to make sure and here is the result:

export function test(input) {
    return input.policy.ingest.type
}

import { test } from "./policyTester"

describe("policyTester.js", () => {
    it("returns valid datapoint for policy tester",() => {
        const input = {
            policy: {
                ingest: {
                    type: "ingest",
                    name: "zorro"
                }
            }
        }
        const resp = test(input)
        expect(resp).to.eq("ingest")
    })
})


621e7403e48ac874481117.jpeg

package.json

{
  "name": "zing-graphql",
  "version": "1.0.0",
  "scripts": {
    "build": "webpack --config build/webpack.prod.conf.js --progress",
    "dev": "webpack --config build/webpack.dev.conf.js",
    "dev:mock": "MOCK=ALL webpack --config build/webpack.dev.conf.js",
    "start": "npm run dev",
    "clean": "rm -rf dist/ node_modules/",
    "lint": "./lint.sh",
    "test": "nyc test/test.sh",
    "testspec": "test/test.sh",
    "tdd": "mochapack --webpack-config build/webpack.prod.conf.js --require test/setup.js --watch 'server/v2/**/*.spec.js'",
    "graphql:codegen": "graphql-codegen"
  },
  "engines": {
    "node": ">= 10.0.0"
  },
  "description": "ZING GraphQL service",
  "main": "server/index.js",
  "repository": "[email protected]:zenoss/graphql.git",
  "author": "Zenoss <[email protected]>",
  "private": true,
  "resolutions": {
    "**/@opencensus/core": "^0.0.22",
    "**/@types/continuation-local-storage": "3.2.1",
    "**/grpc": "^1.24.4",
    "**/grpc-create-metadata": "3.0.0"
  },
  "dependencies": {
    "@axelspringer/graphql-google-pubsub": "^2.1.0",
    "@elastic/elasticsearch": "7",
    "@google-cloud/opentelemetry-cloud-trace-exporter": "^1.0.0",
    "@google-cloud/pubsub": "^2.11.0",
    "@graphql-codegen/cli": "^1.20.1",
    "@graphql-codegen/typescript": "^1.21.0",
    "@graphql-codegen/typescript-resolvers": "^1.18.2",
    "@opencensus/core": "^0.0.22",
    "@opencensus/nodejs": "^0.0.22",
    "@opentelemetry/api": "^1.0.4",
    "@opentelemetry/auto-instrumentations-node": "^0.27.2",
    "@opentelemetry/core": "^1.0.1",
    "@opentelemetry/exporter-jaeger": "^1.0.1",
    "@opentelemetry/exporter-trace-otlp-http": "^0.27.0",
    "@opentelemetry/propagator-grpc-census-binary": "^0.25.1",
    "@opentelemetry/propagator-jaeger": "^1.0.1",
    "@opentelemetry/resources": "^1.0.1",
    "@opentelemetry/sdk-node": "^0.27.0",
    "@opentelemetry/sdk-trace-base": "^1.0.1",
    "@opentelemetry/sdk-trace-node": "^1.0.1",
    "@opentelemetry/semantic-conventions": "^1.0.1",
    "@stackpath/node-grpc-error-details": "^1.0.0",
    "@types/continuation-local-storage": "3.2.1",
    "@zenoss/opencensus-node-exporter": "^0.0.4",
    "apollo-datasource": "^0.9.0",
    "apollo-server": "^2.25.3",
    "apollo-server-express": "^2.18.2",
    "apollo-server-plugin-response-cache": "^0.5.2",
    "bunyan": "~1.8.12",
    "bunyan-gke-stackdriver": "^0.1.2",
    "clone": "^2.1.2",
    "cookie-parser": "^1.4.4",
    "cors": "^2.8.4",
    "crypto": "^1.0.1",
    "dataloader": "^2.0.0",
    "dompurify": "2.0.17",
    "express": "^4.16.2",
    "google-auth-library": "^7.11.0",
    "google-protobuf": "^4.0.0-rc.2",
    "graphql": "^14.0.2",
    "graphql-iso-date": "^3.5.0",
    "graphql-middleware": "^3.0.2",
    "graphql-schema-modules": "^0.0.4",
    "graphql-subscriptions": "^1.2.0",
    "graphql-tools": "^4.0.5",
    "graphql-type-json": "^0.2.0",
    "grpc": "^1.24.4",
    "http": "^0.0.1-security",
    "jsdom": "15.2.1",
    "json-stable-stringify": "^1.0.1",
    "lodash": "^4.17.21",
    "nanoid": "^3.1.31",
    "opencensus-exporter-stackdriver": "zenoss/opencensus-exporter-stackdriver#v0.1.0",
    "pb-util": "^0.1.2",
    "phonetic": "^0.1.1",
    "protobufjs": "^6.8.8",
    "prufer": "^0.0.1",
    "subscriptions-transport-ws": "^0.9.18",
    "url-parse": "1.5.7",
    "workerpool": "^6.1.4",
    "yamr-js": "zenoss/yamr-js#4.6.4",
    "zing-grpc-clients": "zenoss/zing-proto#v11.16.2"
  },
  "devDependencies": {
    "apollo-server-testing": "^2.9.13",
    "babel-eslint": "^9.0.0",
    "chai": "^4.2.0",
    "clean-webpack-plugin": "^0.1.19",
    "eslint": "^7.19.0",
    "eslint-config-airbnb-base": "^14.2.1",
    "eslint-friendly-formatter": "^3.0.0",
    "eslint-import-resolver-webpack": "^0.8.3",
    "eslint-loader": "^2.0.0",
    "eslint-plugin-import": "^2.22.1",
    "eslint-plugin-mocha": "^9.0.0",
    "jsonwebtoken": "^8.5.1",
    "mocha": ">=6 <9",
    "mochapack": "^2.0.6",
    "nyc": "^15.1.0",
    "sinon": "^7.5.0",
    "sinon-chai": "^3.3.0",
    "start-server-webpack-plugin": "^2.2.5",
    "ts-loader": "^8.0.17",
    "typescript": "^4.1.5",
    "webpack": "^4.0.0",
    "webpack-cli": "^4.5.0",
    "webpack-merge": "^5.7.3",
    "webpack-node-externals": "^2.5.2"
  }
}


nyc config

{
    "all": true,
    "extension": [
        ".js"
    ],
    "exclude": [
        "**/dist/**",
        "**/build/**",
        "**/test/**",
        "**/*.spec.js",
        "**/*.eslintrc.js"
    ],
    "reporter": ["lcov", "text"],
    "sourceMap": true,
    "instrument": true,
    "report-dir": "./test/coverage"
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question