diff --git a/CHANGELOG.md b/CHANGELOG.md index 4491a963..a239a206 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,10 @@ Please add your own contribution below inside the Master section ## Master * brief change description - @author - --> +### 4.1.1 +* show release message once per workspace - @connetdotz (#756) ### 4.1.0 * fix type warning in settings.json when using the `{"autoRun": "off"}` option - @tommy * fix couple of test result matching issues - @connectdotz (#737) diff --git a/package.json b/package.json index 7f7c969b..783e0152 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-jest", "displayName": "Jest", "description": "Use Facebook's Jest With Pleasure.", - "version": "4.1.0", + "version": "4.1.1", "publisher": "Orta", "engines": { "vscode": "^1.59.0" diff --git a/src/extensionManager.ts b/src/extensionManager.ts index 293079d3..1aac53d7 100644 --- a/src/extensionManager.ts +++ b/src/extensionManager.ts @@ -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(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 if (value === 'See Details') { + 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); + } } } diff --git a/tests/extensionManager.test.ts b/tests/extensionManager.test.ts index b50534ef..74e00e5f 100644 --- a/tests/extensionManager.test.ts +++ b/tests/extensionManager.test.ts @@ -51,7 +51,7 @@ 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)) ?? []; @@ -59,7 +59,13 @@ const createExtensionManager = (workspaceFolders: string[]): ExtensionManager => 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; }; @@ -582,7 +588,13 @@ describe('ExtensionManager', () => { describe('activate', () => { let ext1, ext2; beforeEach(() => { - extensionManager = createExtensionManager(['ws-1', 'ws-2']); + const map = new Map(); + 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).mockReturnValue( @@ -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; }); @@ -633,6 +645,25 @@ describe('ExtensionManager', () => { ) ); }); + it('if close without selecting any action, should exit with no-op', async () => { + (vscode.window.showInformationMessage as jest.Mocked).mockReturnValue( + Promise.resolve(undefined) + ); + await extensionManager.activate(); + expect(vscode.commands.executeCommand).not.toBeCalled(); + }); + it('will not show again once it has been seen', async () => { + (vscode.window.showInformationMessage as jest.Mocked).mockReturnValue( + Promise.resolve('Show Test Explorer') + ); + await extensionManager.activate(); + expect(vscode.window.showInformationMessage).toBeCalled(); + + (vscode.window.showInformationMessage as jest.Mocked).mockClear(); + + await extensionManager.activate(); + expect(vscode.window.showInformationMessage).not.toBeCalled(); + }); }); }); });