Skip to content

Commit

Permalink
show release message once per workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
connectdotz committed Aug 23, 2021
1 parent 4b88a2d commit 44d42bf
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 23 deletions.
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'
)
);
}
});
this.context.workspaceState.update(key, true);
}
}
}
35 changes: 31 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 @@ -581,8 +587,14 @@ describe('ExtensionManager', () => {
});
describe('activate', () => {
let ext1, ext2;
let workspaceState;
beforeEach(() => {
extensionManager = createExtensionManager(['ws-1', 'ws-2']);
workspaceState = {
get: jest.fn(),
update: jest.fn(),
};

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,9 +621,10 @@ 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;
workspaceState.get.mockReturnValue(false);
});
it('can reveal test explore view', async () => {
(vscode.window.showInformationMessage as jest.Mocked<any>).mockReturnValue(
Expand All @@ -633,6 +646,20 @@ 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();
expect(workspaceState.get).toBeCalled();
expect(workspaceState.update).toBeCalledWith(expect.anything(), true);
(vscode.window.showInformationMessage as jest.Mocked<any>).mockClear();

workspaceState.get.mockReturnValue(true);
await extensionManager.activate();
expect(vscode.window.showInformationMessage).not.toBeCalled();
});
});
});
});

0 comments on commit 44d42bf

Please sign in to comment.