ryanluker / vscode-coverage-gutters

Display test coverage generated by lcov and xml - works with many languages
https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters
MIT License
460 stars 88 forks source link

Add Ruby example project #335

Closed aussiDavid closed 3 years ago

aussiDavid commented 3 years ago

I've added a Ruby example project with RSpec and Simplecov to generate lcov code coverage reports that are suitable for vscode-coverage-gutters.

aussiDavid commented 3 years ago

@ryanluker Thanks. I've added a lcov.info file and updated the README.md with additional information.

I tried to write the integration test myself but I could not get the test suite to run.

ryanluker commented 3 years ago

@aussiDavid no problem, I checked out your branch and added an test just below the java one in extension.test.ts on line 182. If you could add it to this PR then we are I think it is pretty ready to go once the build passes 😁.

    test("Run display coverage on ruby test file @integration", async () => {
        const decorationSpy = sinon.spy(Renderer.prototype, "setDecorationsForEditor");
        const extension = await vscode.extensions.getExtension("ryanluker.vscode-coverage-gutters");
        if (!extension) {
            throw new Error("Could not load extension");
        }

        const testCoverage = await vscode.workspace.findFiles("**/ruby/lib/app/math.rb", "**/node_modules/**");
        const testDocument = await vscode.workspace.openTextDocument(testCoverage[0]);
        await vscode.window.showTextDocument(testDocument);
        await vscode.commands.executeCommand("coverage-gutters.displayCoverage");

        await checkCoverage(() => {
            // Look for exact coverage on the ruby file
            const cachedLines: ICoverageLines = decorationSpy.getCall(0).args[1];
            expect(cachedLines.full).to.have.lengthOf(5);
            expect(cachedLines.none).to.have.lengthOf(0);
        });

        decorationSpy.restore();
    });
aussiDavid commented 3 years ago

Out of curiosity, how do you run the tests? Is there something special that needs to be installed/configured?

On Mon, 26 Jul 2021 at 14:22, Ryan Luker @.***> wrote:

@aussiDavid https://github.com/aussiDavid no problem, I checked out your branch and added an test just below the java one in extension.test.ts on line 182.

test("Run display coverage on ruby test file @integration", async () => {
    const decorationSpy = sinon.spy(Renderer.prototype, "setDecorationsForEditor");
    const extension = await vscode.extensions.getExtension("ryanluker.vscode-coverage-gutters");
    if (!extension) {
        throw new Error("Could not load extension");
    }

    const testCoverage = await vscode.workspace.findFiles("**/ruby/lib/app/math.rb", "**/node_modules/**");
    const testDocument = await vscode.workspace.openTextDocument(testCoverage[0]);
    await vscode.window.showTextDocument(testDocument);
    await vscode.commands.executeCommand("coverage-gutters.displayCoverage");

    await checkCoverage(() => {
        // Look for exact coverage on the ruby file
        const cachedLines: ICoverageLines = decorationSpy.getCall(0).args[1];
        expect(cachedLines.full).to.have.lengthOf(5);
        expect(cachedLines.none).to.have.lengthOf(0);
    });

    decorationSpy.restore();
});

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ryanluker/vscode-coverage-gutters/pull/335#issuecomment-886372628, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABMVYGGFTOYERE4NHHSZPRTTZTSXDANCNFSM5A5OV2DQ .

-- David Milanese

ryanluker commented 3 years ago

@aussiDavid there is a couple different ways to run the tests, the easiest is to use the headless mode in a command line (imo). You could also use the built in tooling vscode gives extensions (and what we have defined in the config for debugging / running tests). These commands depend on which operating system you are using though (windows and macos will open a vscode window to run the extension tests in, while linux will need to use the headless test scripts).

RE: Special setup Only special setup needed is to have run npm install in the root of the project before trying to use the test scripts.

Options for testing

Command line

image

Running the debugger

Screenshot 2021-07-25 215925

Using the vscode npm scripts viewer

Screenshot 2021-07-25 220114

ryanluker commented 3 years ago

@aussiDavid Oh I forgot to mention but the github action workflow doesn't automatically run on your PRs until you have one successfully merged to master in this repository. In the meantime I just push a button so the tests can run on your code 😁.

aussiDavid commented 3 years ago

Done. @ryanluker please run the test, I occasionally get a failed test when checking the contents of the code average preview file (index.html).

ryanluker commented 3 years ago

@aussiDavid Looks great, thanks for adding a variety of test coverage into the lcov.info so that way the extension test can assert more types of coverage 👍🏻. I noticed with the first test I wrote I only could assert coverage and no coverage so this is much better.