简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM