vaadin / vaadin-connect

A Vaadin Labs experiment with a secure stateless communication framework
https://vaadin.com/labs/vaadin-connect
Apache License 2.0
18 stars 5 forks source link

Avoid accessing browser APIs in the frontend client constructor #106

Open platosha opened 5 years ago

platosha commented 5 years ago

Suppose I have a module that depends on a method from an annotated service:

import {method} from './generated/MyService.js';

export class MyController {
  async myAction() {
    return await method();
  }
}

When doing frontend unit tests for that module, I want to be able to import it a Node.js environment and stub the dependencies. Currently, this is blocked because:

Suggested solution: postpone restoring the refresh token to the first call instead of doing that right in the client constructor. That should enable stubbing the method before it calls browser APIs.

manolo commented 5 years ago

perhaps vaadin-connect could check whether window.locaStorage is available in the runtime before trying to use it.