cralfaro
cralfaro

Reputation: 5948

RequireJS and shim libraries not AMD compatible with selenium

Hi I recently changed my App to requireJS structure, and i modified all 3rd party libraries to the shim configuration. But when i run the integration tests i have in my App i got some failures like.

requirejs.config({
baseUrl: 'resources/js/lib/',
shim : {
    'bootstrap' : {deps: ['jquery']},
    'bootstrap-datepicker': { deps: ['jquery', 'bootstrap']},
    ...
},
paths: {
    'app': '../app',
    'jquery': 'jquery-1.11.1',
    'bootstrap' : 'bootstrap',
    'bootstrap-datepicker': 'bootstrap-datepicker',
    ...
}

});

but i got this failures

$(...).collapse() its not a function.
$(...).datepicker() its not a function.

I figure out the problem its with the libraries that are not AMD compatible as (bootstrap.js, bootstrap-datepicker.js, chosen.js,...)

There are some way to solve this problem with requireJS and non AMD libraries?

Thanks

Upvotes: 1

Views: 232

Answers (1)

cralfaro
cralfaro

Reputation: 5948

I found a solution and i hope this can help everybody with the same problem.

  1. You need to use properly the requirejs.config and add all related dependencies of yours shim libraries. No need to use exports functionallity.

  2. IMPORTANT be sure to use all 3rd party libraries with AMD compatible

  3. If you have some third party library which is not AMD compatible, you can follow this page https://github.com/umdjs/umd to easily convert to AMD. Best the best option would be use third party libraries AMD compatible.

Upvotes: 1

Related Questions