|  | 
| 9 | 9 | import assert from 'assert'; | 
| 10 | 10 | import { PathLike, constants, promises as fs } from 'fs'; | 
| 11 | 11 | import glob, { hasMagic } from 'glob'; | 
|  | 12 | +import { pluginName } from 'mini-css-extract-plugin'; | 
| 12 | 13 | import { basename, dirname, extname, join, relative } from 'path'; | 
| 13 | 14 | import { promisify } from 'util'; | 
| 14 | 15 | import type { Compilation, Compiler } from 'webpack'; | 
| 15 |  | -import { addError } from '../../utils/webpack-diagnostics'; | 
| 16 | 16 | 
 | 
| 17 | 17 | const globPromise = promisify(glob); | 
| 18 | 18 | 
 | 
| @@ -49,23 +49,21 @@ export class FindTestsPlugin { | 
| 49 | 49 |     // Add tests files are part of the entry-point. | 
| 50 | 50 |     webpackOptions.entry = async () => { | 
| 51 | 51 |       const specFiles = await findTests(include, exclude, workspaceRoot, projectSourceRoot); | 
| 52 |  | - | 
| 53 |  | -      if (!specFiles.length) { | 
| 54 |  | -        assert(this.compilation, 'Compilation cannot be undefined.'); | 
| 55 |  | -        addError( | 
| 56 |  | -          this.compilation, | 
| 57 |  | -          `Specified patterns: "${include.join(', ')}" did not match any spec files.`, | 
| 58 |  | -        ); | 
| 59 |  | -      } | 
| 60 |  | - | 
| 61 | 52 |       const entrypoints = await entry; | 
| 62 | 53 |       const entrypoint = entrypoints['main']; | 
| 63 | 54 |       if (!entrypoint.import) { | 
| 64 | 55 |         throw new Error(`Cannot find 'main' entrypoint.`); | 
| 65 | 56 |       } | 
| 66 | 57 | 
 | 
| 67 |  | -      originalImport ??= entrypoint.import; | 
| 68 |  | -      entrypoint.import = [...originalImport, ...specFiles]; | 
|  | 58 | +      if (specFiles.length) { | 
|  | 59 | +        originalImport ??= entrypoint.import; | 
|  | 60 | +        entrypoint.import = [...originalImport, ...specFiles]; | 
|  | 61 | +      } else { | 
|  | 62 | +        assert(this.compilation, 'Compilation cannot be undefined.'); | 
|  | 63 | +        this.compilation | 
|  | 64 | +          .getLogger(pluginName) | 
|  | 65 | +          .error(`Specified patterns: "${include.join(', ')}" did not match any spec files.`); | 
|  | 66 | +      } | 
| 69 | 67 | 
 | 
| 70 | 68 |       return entrypoints; | 
| 71 | 69 |     }; | 
|  | 
0 commit comments