Skip to content

Commit

Permalink
Merge 873fd6f into d19ec8e
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnytest1 committed Aug 24, 2022
2 parents d19ec8e + 873fd6f commit 980a070
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 8 deletions.
22 changes: 18 additions & 4 deletions src/JestExt/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import { startWizard, WizardTaskId } from '../setup-wizard';
import { JestExtExplorerContext } from '../test-provider/types';
import { JestTestProvider } from '../test-provider';
import { JestProcessInfo } from '../JestProcessManagement';
import { addFolderToDisabledWorkspaceFolders } from '../extensionManager';
import { MessageAction } from '../messaging';

interface RunTestPickItem extends vscode.QuickPickItem {
id: DebugTestIdentifier;
Expand Down Expand Up @@ -144,6 +146,14 @@ export class JestExt {
};
}

private setupIgnoreAction(): messaging.MessageAction {
return {
title: 'Ignore Folder',
action: (): void => {
addFolderToDisabledWorkspaceFolders(this.extContext.workspace.name);
},
};
}
private setupRunEvents(events: JestSessionEvents): void {
events.onRunEvent.event((event: JestRunEvent) => {
switch (event.type) {
Expand Down Expand Up @@ -173,11 +183,15 @@ export class JestExt {
const msg = `${event.error}\n see troubleshooting: ${messaging.TROUBLESHOOTING_URL}`;
this.channel.appendLine(msg);
this.channel.show();
messaging.systemErrorMessage(
event.error,

const messageActions: Array<MessageAction> = [
messaging.showTroubleshootingAction,
this.setupWizardAction('cmdLine')
);
this.setupWizardAction('cmdLine'),
];
if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 1) {
messageActions.push(this.setupIgnoreAction());
}
messaging.systemErrorMessage(event.error, ...messageActions);
} else {
this.updateStatusBar({ state: 'done' });
}
Expand Down
7 changes: 7 additions & 0 deletions src/extensionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ export function getExtensionWindowSettings(): PluginWindowSettings {
};
}

export function addFolderToDisabledWorkspaceFolders(folder: string): void {
const config = vscode.workspace.getConfiguration('jest');
const disabledWorkspaceFolders = new Set(config.get<string[]>('disabledWorkspaceFolders') ?? []);
disabledWorkspaceFolders.add(folder);
config.update('disabledWorkspaceFolders', [...disabledWorkspaceFolders]);
}

export type RegisterCommand =
| {
type: 'all-workspaces';
Expand Down
32 changes: 30 additions & 2 deletions tests/JestExt/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ jest.unmock('../test-helper');
jest.mock('../../src/DebugCodeLens', () => ({
DebugCodeLensProvider: class MockCodeLensProvider {},
}));
jest.mock('os');
const mockPlatform = jest.fn();
const mockRelease = jest.fn();
mockRelease.mockReturnValue('');
jest.mock('os', () => ({ platform: mockPlatform, release: mockRelease }));
jest.mock('../../src/decorations/test-status', () => ({
TestStatus: jest.fn(),
}));
Expand Down Expand Up @@ -36,6 +39,8 @@ import { workspaceLogging } from '../../src/logging';
import { ProjectWorkspace } from 'jest-editor-support';
import { mockProjectWorkspace, mockWworkspaceLogging } from '../test-helper';
import { JestTestProvider } from '../../src/test-provider';
import { MessageAction } from '../../src/messaging';
import { addFolderToDisabledWorkspaceFolders } from '../../src/extensionManager';

/* eslint jest/expect-expect: ["error", { "assertFunctionNames": ["expect", "expectItTakesNoAction"] }] */
const mockHelpers = helper as jest.Mocked<any>;
Expand Down Expand Up @@ -1158,7 +1163,30 @@ describe('JestExt', () => {
it('if error: status bar stopped and show error', () => {
onRunEvent({ type: 'exit', error: 'something is wrong', process });
expect(sbUpdateMock).toBeCalledWith({ state: 'stopped' });
expect(messaging.systemErrorMessage).toHaveBeenCalled();
expect(messaging.systemErrorMessage).toHaveBeenCalledWith(
'something is wrong',
{ action: expect.any(Function), title: 'Help' },
{ action: expect.any(Function), title: 'Run Setup Wizard' }
);
});
it('if error: status bar stopped and show error with ignore folder button', () => {
(vscode.workspace.workspaceFolders as any) = ['testfolder1', 'testfolder2'];

onRunEvent({ type: 'exit', error: 'something is wrong', process });
expect(sbUpdateMock).toBeCalledWith({ state: 'stopped' });
expect(messaging.systemErrorMessage).toHaveBeenCalledWith(
'something is wrong',
{ action: expect.any(Function), title: 'Help' },
{ action: expect.any(Function), title: 'Run Setup Wizard' },
{ action: expect.any(Function), title: 'Ignore Folder' }
);

const ignoreAction: MessageAction = (messaging.systemErrorMessage as jest.Mocked<any>)
.mock.calls[0][3];

ignoreAction.action();

expect(addFolderToDisabledWorkspaceFolders).toHaveBeenCalledWith('test-folder');
});
});
});
Expand Down
4 changes: 3 additions & 1 deletion tests/JestProcessManagement/JestProcess.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ jest.unmock('../../src/JestProcessManagement/helper');
jest.unmock('../../src/helpers');

const mockPlatform = jest.fn();
jest.mock('os', () => ({ platform: mockPlatform }));
const mockRelease = jest.fn();
mockRelease.mockReturnValue('');
jest.mock('os', () => ({ platform: mockPlatform, release: mockRelease }));

import { Runner } from 'jest-editor-support';
import { JestProcess, RunnerEvents } from '../../src/JestProcessManagement/JestProcess';
Expand Down
19 changes: 18 additions & 1 deletion tests/extensionManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ jest.unmock('../src/extensionManager');
jest.unmock('../src/appGlobals');

import * as vscode from 'vscode';
import { ExtensionManager, getExtensionWindowSettings } from '../src/extensionManager';
import {
addFolderToDisabledWorkspaceFolders,
ExtensionManager,
getExtensionWindowSettings,
} from '../src/extensionManager';
import { DebugCodeLensProvider, TestState } from '../src/DebugCodeLens';
import { readFileSync } from 'fs';
import { PluginWindowSettings } from '../src/Settings';
Expand All @@ -11,6 +15,8 @@ import { JestExt } from '../src/JestExt';
import { DebugConfigurationProvider } from '../src/DebugConfigurationProvider';
import { CoverageCodeLensProvider } from '../src/Coverage';

const updateConfigurationMock = jest.fn();

vscode.workspace.getConfiguration = jest.fn().mockImplementation((section) => {
const data = readFileSync('./package.json');
const config = JSON.parse(data.toString()).contributes.configuration.properties;
Expand All @@ -24,6 +30,7 @@ vscode.workspace.getConfiguration = jest.fn().mockImplementation((section) => {

return {
get: jest.fn().mockImplementation((key) => defaults[`${section}.${key}`]),
update: updateConfigurationMock,
};
});

Expand Down Expand Up @@ -520,6 +527,16 @@ describe('ExtensionManager', () => {
});
});
});

describe('addFolderToDisabledWorkspaceFolders()', () => {
it('should add the folder to the disabledWorkspaceFolders in the configuration', async () => {
addFolderToDisabledWorkspaceFolders('some-workspace-folder');
expect(updateConfigurationMock).toHaveBeenCalledWith('disabledWorkspaceFolders', [
'some-workspace-folder',
]);
});
});

describe.each`
files | ext1Call | ext2Call
${['ws-3']} | ${0} | ${0}
Expand Down

0 comments on commit 980a070

Please sign in to comment.