forcedotcom / LightningTestingService

Apache License 2.0
122 stars 35 forks source link

New jasmine suite not recognised #51

Closed pgonzaleznetwork closed 6 years ago

pgonzaleznetwork commented 6 years ago

Hi there,

I'm having trouble getting a new suite to be recognised. Steps

  1. Downloaded the "Lightning Testing Service with Examples" package.
  2. Created the following javascript file

describe("Lightning Component Testing Examples", function(){ afterEach(function() { // Each spec (test) renders its components into the same div, // so we need to clear that div out at the end of each spec. $T.clearRenderedTestComponents(); });

    describe('c:ContactCreatorL', function(){
    // We encourage you to have the code for c:egRenderElement side by side
    // when reading through this spec.
    it('creates a contact successfuly', function(done) {
        //instantiate the component using its name
        $T.createComponent("c:egComponentMethod", null)
        // The 'component' here is the instance of c:egRenderElement
        .then(function(component) {

            var fakeResponse = {
                getState : function(){
                    return "SUCCESS";
                }
            };

            //call the apexMethod function, which contains a reference to the apex controller
            spyOn($A, "enqueueAction").and.callFake(function(action) {
                var cb = action.getCallback("SUCCESS")
                cb.fn.apply(cb.s, [fakeResponse]);
            });

            expect(component.get("v.creationSucceded")).toBe(true);

            done();
        }).catch(function(e) {
            // end this spec as a failure
            done.fail(e);
        });
    });
});

});

  1. Went to the file > right click > compress > uploaded it as a static resource as application/zip
  2. Go to https://[myDomain]/c/jasmineTests.app and the test is not there.

The documentation doesn't say anything more than "uploaded the suite as a static resource", which I've done as per the above steps. The syntax appears to be correct and I'm not getting any errors or warnings.

Is there anything I need to do for this suite to be tested?

esalman-sfdc commented 6 years ago

If I understand correctly you installed the LTS package into an org and then also created an additional static resource that contains your test. Are you using sfdx or working in an org directly? In either case you don’t really have to zip the resource so not sure about that. As you are using LTS with examples, once you have an additional test spec file, edit jasmineTests.app to pull in your additional test spec file (at that point you can stop the samples to be pulled in also if you want).

pgonzaleznetwork commented 6 years ago

Thank you. Yes, that's exactly it.

I got this to work by:

1- uploading the suite as a js file 2- Adding the suite name under jasmineTests.app as follows

So, is this the flow that one is expected to follow? From the documentation, it's not clear to me how you can easily upload new tests and run them. It would be counter productive if I need to be editing this file all the time, or creating my own. Can you point me in the right direction?

esalman-sfdc commented 6 years ago

SFDX workflow would be,

pgonzaleznetwork commented 6 years ago

Thank you very much. Just some feedback: The documentation is not clear on this flow, like I said, it only says that you should upload the suites as static resources and then run them, it doesn't say that you need to create your own wrapper application and somehow pass a list of test files to use at run time...if this is indeed documented please let me know.

Last question, as it's related to the same topic, do you have an example of the 4th step on your comment above?

_In your sfdx project, create one or more test wrapper applications that use ltsjasmineRunner and provide a list of test files to it.

Assuming I'm using the sample, out of the box application, jasmineTests.app which is a wrapper of lts_jasmineRunner , how would I specify a list of files to test using the SFDX CLI, or do I need to go in an manually edit the source code and specify the files?

Thanks again for your help, much appreciated.

esalman-sfdc commented 6 years ago

As you pointed out jasmineTests.app would be an example. If you add new resources you would need to update it. Alternatively you could use something like gulp or a wrapper build script to add more magic if you prefer.

This is similar to what you do when using jasmine/mocha to test standalone projects. For example look inside (SpecRunner.html) the bundle at https://github.com/jasmine/jasmine/releases/tag/v2.8.0

pgonzaleznetwork commented 6 years ago

Got it, thank you very much!

pgonzaleznetwork commented 6 years ago

@esalman-sfdc Updating this just in case anyone is reading this. I managed to do what you suggested with gulp, for example

  1. Add your spec js files in a src folder
  2. Create a gulp task to concatenate all the specs into a single file

gulp.task('Assemble-LTS-Specs',function(){ return gulp.src('src/*.js') .pipe(concat('LightningComponentsTest.js')) .pipe(gulp.dest('output')) });

  1. Upload the output file (LightningComponentsTest.js) as a static resource.

  2. This file would be the only one referenced in jasmineTests.app

<c:lts_jasmineRunner testFiles="{!join(',', $Resource.LightningComponentsTests )}" />

Thank you very much for your help on this.