Skip to content

Commit

Permalink
fix(plugin loader): no warn when not using plugins (#3498)
Browse files Browse the repository at this point in the history
Don't warn the user when it is running StrykerJS without plugins:

```
WARN PluginLoader Expression "@stryker-mutator/*" not resulted in plugins to load.
```
  • Loading branch information
nicojs authored May 4, 2022
1 parent 8ca7c65 commit 54aa298
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/core/src/di/plugin-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { tokens, commonTokens, Plugin, PluginKind } from '@stryker-mutator/api/p
import { notEmpty, propertyPath } from '@stryker-mutator/util';

import { fileUtils } from '../utils/file-utils.js';
import { defaultOptions } from '../config/options-validator.js';

const IGNORED_PACKAGES = ['core', 'api', 'util', 'instrumenter'];

Expand Down Expand Up @@ -115,7 +116,7 @@ export class PluginLoader {
const plugins = (await fs.promises.readdir(pluginDirectory))
.filter((pluginName) => !IGNORED_PACKAGES.includes(pluginName) && regexp.test(pluginName))
.map((pluginName) => `${org.length ? `${org}/` : ''}${pluginName}`);
if (plugins.length === 0) {
if (plugins.length === 0 && !defaultOptions.plugins.includes(pluginExpression)) {
this.log.warn('Expression "%s" not resulted in plugins to load.', pluginExpression);
}
plugins.forEach((plugin) => this.log.debug('Loading plugin "%s" (matched with expression %s)', plugin, pluginExpression));
Expand Down
7 changes: 7 additions & 0 deletions packages/core/test/unit/di/plugin-loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { factory, testInjector } from '@stryker-mutator/test-helpers';
import { PluginLoader } from '../../../src/di/index.js';
import { fileUtils } from '../../../src/utils/file-utils.js';
import { resolveFromRoot } from '../../helpers/test-utils.js';
import { defaultOptions } from '../../../src/config/index.js';

describe(PluginLoader.name, () => {
let sut: PluginLoader;
Expand Down Expand Up @@ -79,6 +80,12 @@ describe(PluginLoader.name, () => {
expect(testInjector.logger.warn).calledWithExactly('Expression "%s" not resulted in plugins to load.', 'my-prefix-*');
});

it('should not log a warning when the default glob expression does not yield modules', async () => {
readdirStub.resolves([]);
await sut.load(defaultOptions.plugins);
expect(testInjector.logger.warn).not.called;
});

it('should log debug information when for glob expression', async () => {
const fooPlugin: SchemaValidationContribution = { strykerValidationSchema: { foo: 'plugin' } };
importModuleStub.resolves(fooPlugin);
Expand Down

0 comments on commit 54aa298

Please sign in to comment.