Skip to content

Commit

Permalink
show release message once per workspace (#756)
Browse files Browse the repository at this point in the history
  • Loading branch information
connectdotz authored Aug 24, 2021
1 parent 4b88a2d commit deac4f4
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 24 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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 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);
}
}
}
39 changes: 35 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,25 @@ describe('ExtensionManager', () => {
)
);
});
it('if close without selecting any action, should exit with no-op', async () => {
(vscode.window.showInformationMessage as jest.Mocked<any>).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<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();
});
});
});
});

0 comments on commit deac4f4

Please sign in to comment.