Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show release message once per workspace #756

Merged
merged 3 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Please add your own contribution below inside the Master section

## Master
* brief change description - @author

* show release message once per workspace - @connetdotz
-->

### 4.1.0
Expand Down
41 changes: 23 additions & 18 deletions src/extensionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,23 +277,28 @@ export class ExtensionManager {
this.showReleaseMessage();
}
private showReleaseMessage(): void {
vscode.window
.showInformationMessage(
`vscode-jest now supports the official vscode test explorer!!`,
'Show Test Explorer',
'See Details'
)
.then((value) => {
if (value === 'Show Test Explorer') {
vscode.commands.executeCommand('workbench.view.testing.focus');
} else {
vscode.commands.executeCommand(
'vscode.open',
vscode.Uri.parse(
'https://github.com/jest-community/vscode-jest/blob/master/README.md#how-to-use-the-test-explorer'
)
);
}
});
const key = 'didShowMessage-4.1';
const didShow = this.context.workspaceState.get<boolean>(key, false);
if (!didShow) {
vscode.window
.showInformationMessage(
`vscode-jest now supports the official vscode test explorer!!`,
'Show Test Explorer',
'See Details'
)
.then((value) => {
if (value === 'Show Test Explorer') {
vscode.commands.executeCommand('workbench.view.testing.focus');
} else {
vscode.commands.executeCommand(
'vscode.open',
vscode.Uri.parse(
'https://github.com/jest-community/vscode-jest/blob/master/README.md#how-to-use-the-test-explorer'
)
);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in #755 this should exit out early if the value returned is undefined so that when the user dismisses the prompt it doesn't open the readme

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed!

});
this.context.workspaceState.update(key, true);
}
}
}
32 changes: 28 additions & 4 deletions tests/extensionManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,21 @@ const mockJestExt = () => {
return makeJestExt(args[1]);
});
};
const createExtensionManager = (workspaceFolders: string[]): ExtensionManager => {
const createExtensionManager = (workspaceFolders: string[], context?: any): ExtensionManager => {
(vscode.workspace as any).workspaceFolders =
workspaceFolders?.map((f) => makeWorkspaceFolder(f)) ?? [];

(vscode.workspace.getWorkspaceFolder as jest.Mocked<any>).mockImplementation((uri) => {
return vscode.workspace.workspaceFolders.find((ws) => ws.name === uri);
});
mockJestExt();
const em = new ExtensionManager({} as any);
const extensionContext = context ?? {
workspaceState: {
get: jest.fn(),
update: jest.fn(),
},
};
const em = new ExtensionManager(extensionContext);
vscode.workspace.workspaceFolders.forEach((ws) => em.register(ws));
return em;
};
Expand Down Expand Up @@ -582,7 +588,13 @@ describe('ExtensionManager', () => {
describe('activate', () => {
let ext1, ext2;
beforeEach(() => {
extensionManager = createExtensionManager(['ws-1', 'ws-2']);
const map = new Map<string, boolean>();
const workspaceState = {
get: jest.fn((key) => map.get(key)),
update: jest.fn((key: string, value: boolean) => map.set(key, value)),
};

extensionManager = createExtensionManager(['ws-1', 'ws-2'], { workspaceState });
ext1 = extensionManager.getByName('ws-1');
ext2 = extensionManager.getByName('ws-2');
(vscode.window.showInformationMessage as jest.Mocked<any>).mockReturnValue(
Expand All @@ -609,7 +621,7 @@ describe('ExtensionManager', () => {
expect(ext1.onDidChangeActiveTextEditor).not.toBeCalled();
expect(ext2.onDidChangeActiveTextEditor).not.toBeCalled();
});
describe('can show test explore information', () => {
describe('can show test explore information once per workspace', () => {
beforeEach(() => {
(vscode.window.activeTextEditor as any) = undefined;
});
Expand All @@ -633,6 +645,18 @@ describe('ExtensionManager', () => {
)
);
});
it('will not show again once it has been seen', async () => {
(vscode.window.showInformationMessage as jest.Mocked<any>).mockReturnValue(
Promise.resolve('Show Test Explorer')
);
await extensionManager.activate();
expect(vscode.window.showInformationMessage).toBeCalled();

(vscode.window.showInformationMessage as jest.Mocked<any>).mockClear();

await extensionManager.activate();
expect(vscode.window.showInformationMessage).not.toBeCalled();
});
});
});
});