Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Unit Testing Problem - Illustrator Extension in Angular 4

New Here ,
Nov 16, 2017 Nov 16, 2017

Hi guys,

I'm building an extension for Illustrator using Angular 4. My extension works ok but the I can't unit test it because the calls to CSInterface explode when the code isn't running inside Illustrator.

By default, the Angular CLI creates the project with Karma and Jasmine and I've created a basic test. Essentially the test spec.ts file blows up when trying to create the component because of the errors in CSInterface. This is understandable since it isn't running inside Illustrator but I can't figure out how to mock out the calls to CS interface.

An abbreviated version of the code looks like:

component file:

// Some imports here

declare var CSInterface: any;

@Component({

    selector: 'app-notes',

    templateUrl: './notes.component.html',

    styleUrls: ['./notes.component.scss']

})

export class NotesComponent implements OnInit {

    const csInterface = new CSInterface();

    ngOnInit() {

        // do some other stuff, then

        this.csInterface.evalScript("myScript()");

    }

}

export class NotesComponent implements OnInit {

test file:

  beforeEach(async(() => {

   TestBed.configureTestingModule({

   imports: [

   FormsModule

  ],

   providers: [

   NotesComponent,

  {

   provide: SocketService, useClass: MockSocketService

  },

  {

   provide: ExtensionStateService, useClass: MockExtensionStateService

  }

  ],

  });

  }));


  beforeEach(

   inject([NotesComponent], (_notesComponent: NotesComponent) => {

   component = _notesComponent;

  })

  );


  it('basic test 2', () => {

   expect(2 + 2).toBe(4);

  });

Anyway, that is the basics. Essentially, I need to find a way to mock out the CSInterface so that it will allow the tests to run.

If it matters, the failure is on CSInterface line 480, where it does:

CSInterface.prototype.hostEnvironment = JSON.parse(window.__adobe_cep__.getHostEnvironment());   

It fails because __adobe_cep__ is undefined when running outside the CC environment.

Anyone else doing an angular project and have the included test suite working?

Thanks!

Marshall

643
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 17, 2017 Nov 17, 2017
LATEST

I haven't been able to integrate my ExtendScript test with my other tests, but I have created separate sets of tests using Karma and Istanbul for the AngularJS unit testing, Protractor for the e2e testing, and this:

GitHub - tmaslen/jasminejsx: A port of Jasmine 2.2.0 that is compatible with Adobe ExtendScript

for the  Extendscript testing. Not  really an answer but maybe you can find a way to get jasminejsx to play along with your other tests.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines