public icon indicating copy to clipboard operation
public copied to clipboard

Sharing Jasmine suites

Open ssarj opened this issue 10 years ago • 4 comments

Issue description or question

We're having a few issues relating to how we've structured our shared Jasmine tests. Essentially (outlined in the code below), we've got helper functions that are called within the context of a suite to generate extra tests. When we've got instrument set to false on the shared library test code it appears Wallaby has difficulty in identifying to which test the failure belongs.

Error message (Wallaby.js - Console)

wallaby.js started
core v1.0.317
Finished executing 2 affected test(s)
Test without test file id, most likely the test did not run, OR the test/test body is in the file that is not in the `tests` list in the configuration file { testFileIdCanNotBeDetermined: 'Generated test spec',
  id: 100002,
  log: [ { message: 'Expected false to be truthy.', stack: [Object] } ],
  filesInvolved: [] }

While the Failing Tests tab reports ​​​​​Some of the failing tests can not be reported, check the wallaby console for more details.

Wallaby.js configuration file

module.exports = function (w) {

    return {
        files: [
            { pattern: "lib/Lib.ts", instrument: false },
            { pattern: "lib/jasmine.js" }
        ],

        tests: [
            { pattern: "Tests/Test.ts" }
        ],

        testFramework: "jasmine"
    };
};

Code editor or IDE name and version

Visual Studio 2015

OS name and version

Windows

lib/lib.ts file

module Lib {
    export function GenerateTestCases(value: boolean = true): void {
        describe(`Generated test suite`, () => {
            it(`Generated test spec`, () => {
                expect(value).toBeTruthy();
            });
        });
    }
}

tests/Test.ts

module Test {
    describe(`My complete test suite`, () => {
        describe(`Manual test suite`, () => {
            it(`Manual test spec`, () => {
                expect(true).toBeTruthy();
            });
        });

        Lib.GenerateTestCases(false);
    });
}

If we adjust instrument to true, we no longer receive the above error / warning message, but things are still a little weird. If for example, we had another test suite that is executed before the above failing test, the failing tests appear allocated to the test suite that ran first. This is illustrated in the following screenshot:

image

I can attach the code for this if desired; it's just an extension of the above that includes the module under test in the suite / spec names.

Thanks.

ssarj avatar Nov 07 '16 23:11 ssarj

Hello,

First, you need to set instrument: true in this case, otherwise wallaby will not be able to detect the shared tests. If you've been setting instrument: false in order to exclude the file from the code coverage metric calculation displayed in wallaby app, then you may use the filesWithNoCoverageCalculated setting for it.

Next, what you're observing is a known restriction. Wallaby.js requires all files with tests to be entry points. As you can see in the referenced feature request, we have recently added some support for this scenario, and wallaby tries to guess the original test file for the tests in the shared file. The weird thing with the wrong parent for the shared test you've been observing was a bug in the new algorithm. We have fixed it and published the new version of wallaby core 1.0.319. Please try to update to the new version and see if it fixes the issue.

If you find more oddities with the support of your setup, please feel free to report those in this issue's thread.

ArtemGovorov avatar Nov 08 '16 06:11 ArtemGovorov

Thanks, will look into that now!

ssarj avatar Nov 08 '16 22:11 ssarj

1.0.319 works well, thanks @ArtemGovorov.

ssarj avatar Nov 09 '16 06:11 ssarj

Awesome, thanks for the update!

ArtemGovorov avatar Nov 09 '16 06:11 ArtemGovorov