Skip to content

Commit

Permalink
fix: improve Webstorm integration (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
noomorph authored Oct 12, 2023
1 parent 1282b3e commit 926077a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/environment-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { EnvironmentContext, JestEnvironment, JestEnvironmentConfig } from
import type { Circus } from '@jest/types';
import { JestMetadataError } from './errors';
import { realm, injectRealmIntoSandbox } from './realms';
import { SemiAsyncEmitter } from './utils';
import { jestUtils, SemiAsyncEmitter } from './utils';

const emitterMap: WeakMap<object, SemiAsyncEmitter<ForwardedCircusEvent>> = new WeakMap();

Expand Down Expand Up @@ -35,7 +35,10 @@ export function onTestEnvironmentCreate(
`Please check that at least one of the reporters in your Jest config inherits from "jest-metadata/reporter".\n` +
hint;

if (globalConfig && (globalConfig.runInBand || globalConfig.maxWorkers === 1)) {
if (
globalConfig &&
(jestUtils.isSingleWorker(globalConfig) || jestUtils.isInsideIDE(globalConfig))
) {
console.warn('[jest-metadata] ' + message);
} else {
throw new JestMetadataError(message);
Expand Down
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './emitters';
export * as jestUtils from './jestUtils';
export { getVersion } from './getVersion';
export { aggregateLogs, logger, optimizeForLogger } from './logger';
export { makeDeferred, Deferred } from './makeDeferred';
Expand Down
11 changes: 11 additions & 0 deletions src/utils/jestUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { Config } from '@jest/reporters';

export function isSingleWorker(config: Config.GlobalConfig) {
return config.runInBand || config.maxWorkers === 1;
}

export function isInsideIDE(config: Config.GlobalConfig) {
const isSingleReporter = config.reporters && config.reporters.length === 1;
const singleReporter = isSingleReporter ? config.reporters?.[0]?.[0] ?? '' : '';
return /jest-intellij/i.test(singleReporter);
}

0 comments on commit 926077a

Please sign in to comment.