Jenkins Test Failures -- beforeAll()


#1

Be aware that the beforeAll() method in the jasmine framework is not considered a ‘test’ in and of itself, like each of the test’s it() blocks are (see sample test file below). This is a feature of the jasmine framework and is unrelated to the C3 AI Suite.

Developers should care about this because it means that if a line of code throws an error in the beforeAll() method, the test runner will not throw an error to the console for the developer to view. Instead, this beforeAll() will fail silently, and what is most likely is the developer will see a downstream error in the actual it() blocks because the failure in the beforeAll() normally means that the pre-requisite data needed for the test was not properly created.

If this happens… developers can investigate which piece(s) of the beforeAll() are failing by putting a debugger; line in the code (see example below in sample file).

How can this be avoid?
This can be avoided in a couple ways:

  1. create checks or try/catch blocks in the beforeAll() method that will throw the beforeAll() error to the developer.
  2. instead of the beforeAll() method, use an it() block. Note, while this will bring errors in the method to the attention of the developer sooner, it will also “count” as a test in your CI/CD build and package test count.

For general information on the jasmine framework, please refer to their resources: https://jasmine.github.io/

var filename = 'test_TestName';

describe(filename, function() {
  // this is a beforeAll() method
  beforeAll(function () {
        debugger; // this is the DEBUGGER example line!
        this.start = new DateTime("2016-01-01T00:00:00.000");
        this.end = new DateTime("2016-01-01T01:00:00.000");
        this.cut = this.end, // before the cutoff time, it is coldTag, after this time, it will be hotTag
        this.context = TestApi.createContext(filename);

        // set up other useful variables here for use later in the test file. 

        TestApi.waitForSetup(this.context, [], 1, 120);

    });

    afterAll(function() {
        TestApi.teardown(this.context);
    });
    
    // this is an *it() block*. This is one example, and a single test file can have several it() blocks.
    it("describe what the test is doing here.", function () { 
    	
        var metricResult = MyType.evalMetric({
            id: some.id,
            expression: 'SomeMetricName',
            start: this.start,
            end: this.end,
            interval: this.interval,
        });
       
        // should return [1,1,0,0,0,1]
       var expected=[1,1,0,0,0,1]

        expect(expected).toEqual(metricResult.data());    
    });
});