|
1 | 1 | import { expect } from "chai"; |
2 | 2 | import { exec } from "child_process"; |
3 | 3 | import sinon from "sinon"; |
4 | | -import { after } from "mocha"; |
| 4 | +import { after, afterEach } from "mocha"; |
5 | 5 | import * as vscode from "vscode"; |
6 | 6 | import { ICoverageLines, Renderer } from "../src/coverage-system/renderer"; |
7 | 7 | import { StatusBarToggler } from "../src/extension/statusbartoggler"; |
| 8 | +import { Gutters, PREVIEW_COMMAND } from "../src/extension/gutters"; |
8 | 9 |
|
9 | 10 | suite("Extension Tests", function () { |
| 11 | + const disposables: vscode.Disposable[] = []; |
| 12 | + |
| 13 | + afterEach(() => { |
| 14 | + // Clear mocks after each test to avoid cascading failures due to one test failing |
| 15 | + sinon.restore(); |
| 16 | + |
| 17 | + // Also clear any disposables |
| 18 | + disposables.forEach(d => d.dispose()); |
| 19 | + disposables.length = 0; |
| 20 | + }); |
| 21 | + |
10 | 22 | after(() => { |
11 | 23 | vscode.window.showInformationMessage('All tests done!'); |
12 | 24 | }); |
13 | 25 |
|
14 | | - test("Preview the coverage report in a new webview tab @integration", async () => { |
| 26 | + test("Preview the coverage report without live server extension @integration", async function() { |
| 27 | + const getLiveServerStub = sinon.stub(Gutters.prototype, "getLiveServerExtension"); |
| 28 | + getLiveServerStub.returns(undefined); |
| 29 | + |
| 30 | + const toastStub = sinon.stub(vscode.window, "showErrorMessage"); |
| 31 | + |
| 32 | + await vscode.commands.executeCommand("coverage-gutters.previewCoverageReport"); |
| 33 | + |
| 34 | + expect(toastStub.callCount).to.equal(1); |
| 35 | + const call = toastStub.getCall(0); |
| 36 | + expect(call.args[0]).to.equal("Live Preview extension not installed"); |
| 37 | + }); |
| 38 | + |
| 39 | + test("Preview the coverage report with live server installed but inactive @integration", async function() { |
| 40 | + const getLiveServerStub = sinon.stub(Gutters.prototype, "getLiveServerExtension"); |
| 41 | + const liveServer = { isActive: false, activate: () => { liveServer.isActive = true; } }; |
| 42 | + getLiveServerStub.returns(liveServer as never); |
| 43 | + |
| 44 | + const doPreviewStub = sinon.stub(); |
| 45 | + disposables.push(vscode.commands.registerCommand(PREVIEW_COMMAND, doPreviewStub)); |
| 46 | + |
| 47 | + // Note: depends on "coverage-gutters.coverageReportFileName": "index.html", |
| 48 | + // being set in the example.code-workspace setting file as the coverage report |
| 49 | + // is in the root of the node folder and not inside the default /coverage |
| 50 | + await vscode.commands.executeCommand("coverage-gutters.previewCoverageReport"); |
| 51 | + expect(liveServer.isActive).to.equal(true); |
| 52 | + expect(doPreviewStub.callCount).to.equal(1); |
| 53 | + }); |
| 54 | + |
| 55 | + test("Preview the coverage report with live server @integration", async function() { |
| 56 | + const getLiveServerStub = sinon.stub(Gutters.prototype, "getLiveServerExtension"); |
| 57 | + getLiveServerStub.returns({ isActive: true } as never); |
| 58 | + |
| 59 | + const doPreviewStub = sinon.stub(); |
| 60 | + disposables.push(vscode.commands.registerCommand(PREVIEW_COMMAND, doPreviewStub)); |
| 61 | + |
15 | 62 | // Note: depends on "coverage-gutters.coverageReportFileName": "index.html", |
16 | 63 | // being set in the example.code-workspace setting file as the coverage report |
17 | 64 | // is in the root of the node folder and not inside the default /coverage |
18 | 65 | await vscode.commands.executeCommand("coverage-gutters.previewCoverageReport"); |
19 | | - // Look to see if the webview is open and showing preview coverage |
20 | | - await checkCoverage(() => { |
21 | | - const livePreview = vscode.extensions.getExtension("ms-vscode.live-server"); |
22 | | - expect(livePreview?.isActive).to.equal(true); |
23 | | - }); |
| 66 | + expect(doPreviewStub.callCount).to.equal(1); |
24 | 67 | }); |
25 | 68 |
|
26 | 69 | test("Run display coverage on a test file that has coverages generated remotely @integration", async () => { |
|
0 commit comments