runner.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /**
  2. * Run integration tests
  3. *
  4. * Uses the `waterline-adapter-tests` module to
  5. * run mocha tests against the appropriate version
  6. * of Waterline. Only the interfaces explicitly
  7. * declared in this adapter's `package.json` file
  8. * are tested. (e.g. `queryable`, `semantic`, etc.)
  9. */
  10. /**
  11. * Module dependencies
  12. */
  13. var util = require('util');
  14. var TestRunner = require('waterline-adapter-tests');
  15. var Adapter = require('../../../lib/adapter');
  16. // Grab targeted interfaces from this adapter's `package.json` file:
  17. var package = {};
  18. var interfaces = [];
  19. var features = [];
  20. try {
  21. package = require('../../../package.json');
  22. interfaces = package.waterlineAdapter.interfaces;
  23. features = package.waterlineAdapter.features;
  24. } catch (e) {
  25. throw new Error(
  26. '\n' +
  27. 'Could not read supported interfaces from `waterlineAdapter.interfaces`' + '\n' +
  28. 'in this adapter\'s `package.json` file ::' + '\n' +
  29. util.inspect(e)
  30. );
  31. }
  32. console.log('Testing `' + package.name + '`, a Sails/Waterline adapter.');
  33. console.log('Running `waterline-adapter-tests` against ' + interfaces.length + ' interfaces...');
  34. console.log('( ' + interfaces.join(', ') + ' )');
  35. console.log();
  36. console.log('Latest draft of Waterline adapter interface spec:');
  37. console.log('http://links.sailsjs.org/docs/plugins/adapters/interfaces');
  38. console.log();
  39. // //////////////////////////////////////////////////////////////////////
  40. // Integration Test Runner
  41. //
  42. // Uses the `waterline-adapter-tests` module to
  43. // run mocha tests against the specified interfaces
  44. // of the currently-implemented Waterline adapter API.
  45. // //////////////////////////////////////////////////////////////////////
  46. new TestRunner({
  47. // Mocha opts
  48. mocha: {
  49. bail: false,
  50. timeout: 20000
  51. },
  52. // Load the adapter module.
  53. adapter: Adapter,
  54. // Default connection config to use.
  55. config: (function(){
  56. var config = {
  57. schema: true,
  58. };
  59. // Try and build up a Waterline Adapter Tests URL if one isn't set.
  60. // (Not all automated test runners can be configured to automatically set these).
  61. // Docker sets various URL's that can be used to build up a URL for instance.
  62. if (process.env.WATERLINE_ADAPTER_TESTS_URL) {
  63. config.url = process.env.WATERLINE_ADAPTER_TESTS_URL;
  64. return config;
  65. }
  66. else {
  67. var host = process.env.MYSQL_PORT_3306_TCP_ADDR || process.env.WATERLINE_ADAPTER_TESTS_HOST || 'localhost';
  68. var port = process.env.WATERLINE_ADAPTER_TESTS_PORT || 3306;
  69. var user = process.env.MYSQL_ENV_MYSQL_USER || process.env.WATERLINE_ADAPTER_TESTS_USER || 'root';
  70. var password = process.env.MYSQL_ENV_MYSQL_PASSWORD || process.env.WATERLINE_ADAPTER_TESTS_PASSWORD || process.env.MYSQL_PWD || '';
  71. var database = process.env.MYSQL_ENV_MYSQL_DATABASE || process.env.WATERLINE_ADAPTER_TESTS_DATABASE || 'adapter_tests';
  72. config.url = 'mysql://' + user + ':' + password + '@' + host + ':' + port + '/' + database;
  73. return config;
  74. }
  75. })(),
  76. failOnError: true,
  77. // The set of adapter interfaces to test against.
  78. // (grabbed these from this adapter's package.json file above)
  79. interfaces: interfaces,
  80. // The set of adapter features to test against.
  81. // (grabbed these from this adapter's package.json file above)
  82. features: features,
  83. // Most databases implement 'semantic' and 'queryable'.
  84. //
  85. // As of Sails/Waterline v0.10, the 'associations' interface
  86. // is also available. If you don't implement 'associations',
  87. // it will be polyfilled for you by Waterline core. The core
  88. // implementation will always be used for cross-adapter / cross-connection
  89. // joins.
  90. //
  91. // In future versions of Sails/Waterline, 'queryable' may be also
  92. // be polyfilled by core.
  93. //
  94. // These polyfilled implementations can usually be further optimized at the
  95. // adapter level, since most databases provide optimizations for internal
  96. // operations.
  97. //
  98. // Full interface reference:
  99. // https://github.com/balderdashy/sails-docs/blob/master/adapter-specification.md
  100. });