[keycloak-dev] Javascript adapater tests
Stan Silvert
ssilvert at redhat.com
Wed Jan 16 14:22:38 EST 2019
On 1/16/2019 12:58 PM, Guillaume Vincent wrote:
> > Coverage is what matters.
>
> I like to tests features and add regression tests for each bugs.
> Coverage is not a good metric, you can call your function with no
> assertion, you will have 100% code coverage.
> But I think we are agree that every function in the adapter (init(),
> login() refreshToken(), etc) should be tested.
Yeah, I'm not talking about code coverage or path coverage. I'm talking
about coverage in a broader sense, as in, "the test suite covers
everything the system is designed to do".
>
> > should be written in TypeScript.
>
> Totally agree, as I said I created the experience in a couple of hours.
> But yes JS adapter should be written in typescript
>
> I see 2 strategies to implement tests and upgrade the JS adapter:
>
> 1/ write a new lib in Typescript near the old one, add some tests for
> every function and test new and old implementation together with
> automated tests.
> 2/ split actual code (each method in a file for example) set up a
> blunder to build the js adapter and then add unit and functional tests
> one by one for every function. Then migrate code to Typescript
>
> I can try a POC on the first one if you want
Somebody did a POC as part of this project:
https://github.com/ebondu/angular2-keycloak
The idea was that we would end up with both a javascript adapter and a
TypeScript adapter. I was opposed to that at the time. It's easy
enough to just wrap the javascript adapter and use the type definition
file for TypeScript.
But there would be advantages to */replacing /*the javascript adapter
with TypeScript. One is that we would no longer need a type def file
that gets out of sync with the javascript adapter. And you would get
all the usual TypeScript goodness as we further develop the adapter. It
would result in better, more maintainable code.
The main technical hurdle would be that the interface would need to be
backward compatible to support users who currently have code calling the
javascript adapter directly. We would need to continue supporting code
that calls the adapter with plain javascript.
Stian, can you think of technical reasons why we should not do this? I
know there are probably many non-technical reasons.
>
>
>
> On Wed, Jan 16, 2019 at 5:43 PM Stan Silvert <ssilvert at redhat.com
> <mailto:ssilvert at redhat.com>> wrote:
>
> On 1/16/2019 9:53 AM, Guillaume Vincent wrote:
> > Hello Keycloak dev list,
> >
> > in a previous post I raised the problem that the JavaScript
> adapter did not
> > have JavaScript tests.
> >
> > In a couple of hours I created a simple example for Keycloak
> with unit and
> > functional tests https://github.com/guillaumevincent/keycloak-lite
> >
> > You can see tests in this file
> >
> https://github.com/guillaumevincent/keycloak-lite/blob/master/test.js
> >
> > I also created a blog post on IMO How to test JavaScript code:
> > https://guillaumevincent.com/2019/01/15/test-in-javascript.html
> >
> > Maybe we can open the discussion on how keycloak.js should be
> tested.
> > Without any fast and automated tests, in JavaScript, the
> refactor of the
> > keycloak adapter will not be easy at all.
> >
> > wdyt?
> Several thoughts:
>
> * Basically, I agree. It makes sense to test javascript with
> javascript. I like where you are going with this.
> * An important point in any discussion of testing is that the only
> useful test is a test that uncovers a bug. We never write tests
> just to say we have lots of tests. Coverage is what matters. I'm
> not criticizing your blog. It's just something I like to keep
> in mind.
> * You mention TypeScript in your blog, but test.js appears to be
> written in plain javascript. IMO, any javascript we write
> (with the
> possible exception of keycloak.js) should be written in
> TypeScript.
> Both internally and externally, developers are moving more and
> more
> to TypeScript. Also, the Java developers on our team will be much
> more comfortable and confident with a strongly typed language that
> works well with an IDE.
> * We need to know a little more about the current test coverage
> of the
> javascript adapter. Much of it is tested through indirect means.
> * We need to understand how javascript tests will integrate into our
> builds.
> * We need to standardize on a javascript test package. I don't want
> the adapter to be tested with one library while the new account
> management console is tested with another.
>
>
>
> _______________________________________________
> keycloak-dev mailing list
> keycloak-dev at lists.jboss.org <mailto:keycloak-dev at lists.jboss.org>
> https://lists.jboss.org/mailman/listinfo/keycloak-dev
>
>
>
> --
> Guillaume Vincent
> Senior Software Engineer
More information about the keycloak-dev
mailing list