title: How do you ensure code coverage for files with no matching spec files in an Angular 7 app?
body: <p>This question has been asked before but all answers appear to be out of date and do not result in full code coverage <strong>including coverage for files with no spec file</strong>.</p>
  
  <p>When I run the command <code>ng-test --code-coverage</code> my results show far fewer source code checked than reality, because it is skiping files with no matching spec file. I have tried to solve this in a few ways including creating an app.module.spec file and importing app.module into it and this increased the reported tested lines of code, but after adding a new component without tests to a deeply nested module the numbers did not change.</p>
  
  <p>Here is my karma config:</p>
  
  <pre><code>// Karma configuration file, see link for more information
  // https://karma-runner.github.io/1.0/config/configuration-file.html
  
  module.exports = function (config) {
    config.set({
      basePath: '',
      frameworks: ['jasmine', '@angular-devkit/build-angular'],
      plugins: [
        require('karma-jasmine'),
        require('karma-chrome-launcher'),
        require('karma-jasmine-html-reporter'),
        require('karma-mocha-reporter'),
        require('karma-coverage-istanbul-reporter'),
        require('@angular-devkit/build-angular/plugins/karma')
      ],
      client: {
        clearContext: false // leave Jasmine Spec Runner output visible in browser
      },
      coverageIstanbulReporter: {
        dir: require('path').join(__dirname, '../coverage'),
        reports: ['html', 'lcovonly', 'text-summary'],
        fixWebpackSourcePaths: true,
        thresholds: {
          statements: 80,
          lines: 80,
          branches: 80,
          functions: 80
        }
      },
      mochaReporter: {
        maxLogLines: 4
      },
      reporters: ['progress', 'mocha', 'kjhtml'],
      port: 9876,
      colors: true,
      logLevel: config.LOG_INFO,
      autoWatch: true,
      browsers: ['Chrome'],
      singleRun: false
    });
  };
  </code></pre>
  
  <p>here is my tests.ts file</p>
  
  <pre><code>// This file is required by karma.conf.js and loads recursively all the .spec and framework files
  
  import 'zone.js/dist/zone-testing';
  import { getTestBed } from '@angular/core/testing';
  import {
    BrowserDynamicTestingModule,
    platformBrowserDynamicTesting
  } from '@angular/platform-browser-dynamic/testing';
  
  declare const require: any;
  
  // First, initialize the Angular testing environment.
  getTestBed().initTestEnvironment(
    BrowserDynamicTestingModule,
    platformBrowserDynamicTesting()
  );
  // Then we find all the tests.
  const context = require.context('./', true, /\.spec\.ts$/);
  // And load the modules.
  context.keys().map(context);
  </code></pre>
  
  <p>Here is my tsconfig.spec.json file:</p>
  
  <pre><code>{
    "extends": "../tsconfig.json",
    "compilerOptions": {
      "outDir": "../out-tsc/spec",
      "types": [
        "jasmine",
        "node"
      ]
    },
    "files": [
      "test.ts",
      "polyfills.ts"
    ],
    "include": [
      "**/*.spec.ts",
      "**/*.d.ts"
    ]
  }
  </code></pre>