I used @joshbaeha's suggestion to ng new a new Angular 5 project and copied the test.ts file, which appears to be completely generic and not reliant on project structure or anything else. Everything is now working. Here it is:

test.ts

// 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);
Answer from Chris Halcrow on Stack Overflow
🌐
MDBootstrap
mdbootstrap.com › standard › material design for bootstrap 5 & vanilla javascript
Unit tests not working after upgrade to angular 5 and mdb pr - Material Design for Bootstrap
The missing file seems to be part of a third party library. TS files in published libraries are often a sign of a badly packaged library. Please open an issue in the library repository to alert its author and ask them to package the library ...
Discussions

Build issue during Karma Test execution => index.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property
The ng test command fails with Build issue saying the index.ts is missing from the TypeScript compilation. I have a App Module and Common Module for some common functions created with Angular 7. More on github.com
🌐 github.com
4
April 16, 2019
angular - How to resolve test.ts when running ng test? - Stack Overflow
I'm using Angular CLI and when I run ng test, it starts launching the browser, then I suddenly get an error: userName@UserName:~/devApp/profiles$ng test 10% building modules 1/1 modules 0 active18... More on stackoverflow.com
🌐 stackoverflow.com
September 18, 2017
npm test fails after upgrade from angular4 to angular 5 "test.ts is missing from the TypeScript compilation" - Stack Overflow
10 Module build failed: Error: index.ts is missing from the TypeScript compilation · 0 Angular 5 Getting Error when trying to run "ng test" More on stackoverflow.com
🌐 stackoverflow.com
src/test.ts not found
FAIL src/app/file.spec.ts ● Test suite failed to run TypeScript diagnostics (customize using `[jest-config].globals.ts-jest.diagnostics` option): error TS6053: File 'C:/Users/.../projectHome/src/test.ts' not found. I just upgraded from jest-preset-angular 6 to 7 and I get this error. More on github.com
🌐 github.com
5
March 29, 2019
🌐
GitHub
github.com › angular › angular-cli › issues › 26379
File 'src\main.ts' is missing from the TypeScript compilation. · Issue #26379 · angular/angular-cli
November 16, 2023 - - Building...X [ERROR] File 'src\main.ts' is missing from the TypeScript compilation. [plugin angular-compiler] Ensure the file is part of the TypeScript program via the 'files' or 'include' property.
Author   toddhd
🌐
GitHub
github.com › angular › angular-cli › issues › 14179
Build issue during Karma Test execution => index.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property · Issue #14179 · angular/angular-cli
April 16, 2019 - Added the same index.ts from common components into the tsConfig.spec.json as well, but the ng test command fails in this scenario with "index.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property" error message for the Component where I have imported some of the files Common Module.
Author   arun-mano
Find elsewhere
🌐
GitHub
github.com › thymikee › jest-preset-angular › issues › 249
src/test.ts not found · Issue #249 · thymikee/jest-preset-angular
March 29, 2019 - FAIL src/app/file.spec.ts ● Test suite failed to run TypeScript diagnostics (customize using `[jest-config].globals.ts-jest.diagnostics` option): error TS6053: File 'C:/Users/.../projectHome/src/test.ts' not found. I just upgraded from jest-preset-angular 6 to 7 and I get this error.
Author   gagle
Top answer
1 of 4
9

Simple solution: just remove the call to require.context

I just faced the same problem, converting an app from Angular 14 to 15, and it turns out the solution is even simpler: just delete the two lines at the bottom of src/test.ts. The call to require.context() is no longer needed.

I used to have

const context = require.context("./", true, /\.spec\.ts$/);
context.keys().forEach(context);

at the end of src/test.ts, but now I have deleted those two lines and all my tests run just like they used to with Angular 14.

I could not find proper documentation for this change (that's why I landed on this question in the first place) but my assumption is that Karma now automatically finds all the *.spec.ts files and we no longer need to direct it to do so.

Narrowing the test suites with "include"

The "include" property, added under "test":/"options":, can be used to restrict the list of spec files to run.

According to my tests, configuring angular.json like this:

   "test": {
     "options": {
        "include": ["**/*.spec.ts"],
        ...
     },
     ...

is the same as without "include": all spec files are exercised.

But configuring angular.json like this:

   "test": {
     "options": {
        "include": ["**/app.component.spec.ts"],
        ...
     },
     ...

would only run spec files called app.component.spec.ts.

2 of 4
8

test.ts file is no longer generated by angular, and the property main used to link the file is no longer allowed in angular.json, you can use the include property in angular.json to add patterns or file name

"test": {
  ...
  "options": {
    "include": [
      "**/app.component.spec.ts"
    ]
    ...
  }
}
🌐
Angular
angular.dev › guide › testing
Testing • Overview • Angular
HELPFUL: When creating new TypeScript files for test setup or providers, like src/test-providers.ts, ensure they are included in your project's test TypeScript configuration file (typically tsconfig.spec.json).
🌐
Angular
v2.angular.io › docs › ts › latest › guide › testing.html
Testing - ts - GUIDE
The component is probably too simple to be worth testing in real life but it's perfect for a first encounter with the Angular testing utilities. The corresponding src/app/banner-inline.component.spec.ts sits in the same folder as the component, for reasons explained in the FAQ answer to "Why put specs next to the things they test?".
🌐
GitHub
github.com › angular › angular-cli › issues › 12794
updating CLI from 6.1.5 -> 7.0.3 indicates missing tsconfig files for ng serve / test (Karma) · Issue #12794 · angular/angular-cli
October 29, 2018 - angular / angular-cli Public · Notifications · You must be signed in to change notification settings · Fork 11.9k · Star 27k · New issueCopy link · New issueCopy link · Closed · Closed · updating CLI from 6.1.5 -> 7.0.3 indicates missing tsconfig files for ng serve / test (Karma)#12794 ·
Author   michahell
🌐
Stack Overflow
stackoverflow.com › questions › 68744619 › angular-v12-unit-test-error-no-specs-found
karma jasmine - Angular v12 - Unit Test - [ERROR] No specs found - Stack Overflow
I noticed that no tests were found in my project after upgrading my Angular version from v11 to v12. In my tests.ts file I had this: const context = require.context('./', true, /\.spec\.ts$/); Works now after changing to this: const context = require.context('src/', true, /\.spec\.ts$/); Share ·
🌐
Medium
medium.com › @satawneh › ts-is-missing-from-the-typescript-compilation-63da4e0e8787
.ts is missing from the TypeScript compilation. - Shadi Atawneh - Medium
June 7, 2021 - ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the ‘files’ or ‘include’ property. in angular 9 model class is not recognized and ng build gives error
🌐
Angular
v17.angular.io › guide › testing
Angular
Angular is a platform for building mobile and desktop web applications. Join the community of millions of developers who build compelling user interfaces with Angular.
🌐
GitHub
github.com › angular › angular-cli › issues › 18509
Is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property....at AngularCompilerPlugin.getCompiledFile( · Issue #18509 · angular/angular-cli
August 12, 2020 - Is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property....at AngularCompilerPlugin.getCompiledFile(#18509
Author   CP-Ram
🌐
GitHub
github.com › angular › angular-cli › issues › 17235
ng test fails in angular 9 · Issue #17235 · angular/angular-cli
March 17, 2020 - Simple steps to reproduce this bug. below is the configuration , I am having after the the upgrade to angular 9. ... { "extends": "../tsconfig.json", "compilerOptions": { "outDir": "../out-tsc/app", "types": [] }, "files": [ "main.ts", "polyfills.ts" ], "include": [ "src/**/*.d.ts" ], "exclude": [ "src/test.ts", "**/*.spec.ts" ] }
Author   debender495
🌐
Reddit
reddit.com › r/angular2 › help! error: xxx.ts is missing from the typescript compilation....
r/Angular2 on Reddit: Help! Error: xxx.ts is missing from the TypeScript compilation....
January 4, 2023 -

I deal with this compilation problem for whole day already but no progress, I am at my wits end.

Error: C:\Users\Steve\Documents\lessonbite-web\src\app\theme\pages\webView\webViewMain.module.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
    at AngularCompilerPlugin.getCompiledFile (C:\Users\Steve\Documents\lessonbite-web\node_modules\@ngtools\webpack\src\angular_compiler_plugin.js:951:23)
    at C:\Users\Steve\Documents\lessonbite-web\node_modules\@ngtools\webpack\src\loader.js:43:31
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

What I am sure:

  1. The compilation problem has occured this morning, when I turn on my computer. I do not change anything

  2. There was no problem yesterday. The last thing I changed is some component.ts and html.

  3. This Angular project works for months for me already

  4. In above error, it mentioned "webViewMain.module", but I am sure it is not about this specific component, because all of the component have the same error mesage. (This makes that bug more difficult to solve)

What I think:

  1. It is likely caused by the changes I did yesterday, probably the last half hour of yesterday.

What I tried:

  1. Revert all the code changes, no use

  2. Go SO to search for solution, they say it may be because of import name typo, but don't work for me. My project has worked for months, and nothing is changed in tsconfig.json, tsconfig.app.json, package.json

  3. Delete node_moudles, and reinstall, don't work

Any idea? I am really at my wits end. I wonder how could his bug be so hard to solve.