nightwatch.conf.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import path from 'path';
  2. import glob from 'glob';
  3. // Find directories which have Nightwatch tests in them.
  4. const regex = /(.*\/?tests\/?.*\/Nightwatch)\/.*/g;
  5. const collectedFolders = {
  6. Tests: [],
  7. Commands: [],
  8. Assertions: [],
  9. Pages: [],
  10. };
  11. const searchDirectory = process.env.DRUPAL_NIGHTWATCH_SEARCH_DIRECTORY || '';
  12. const defaultIgnore = ['vendor/**'];
  13. glob
  14. .sync('**/tests/**/Nightwatch/**/*.js', {
  15. cwd: path.resolve(process.cwd(), `../${searchDirectory}`),
  16. ignore: process.env.DRUPAL_NIGHTWATCH_IGNORE_DIRECTORIES
  17. ? process.env.DRUPAL_NIGHTWATCH_IGNORE_DIRECTORIES.split(',').concat(
  18. defaultIgnore,
  19. )
  20. : defaultIgnore,
  21. })
  22. .forEach(file => {
  23. let m = regex.exec(file);
  24. while (m !== null) {
  25. // This is necessary to avoid infinite loops with zero-width matches.
  26. if (m.index === regex.lastIndex) {
  27. regex.lastIndex += 1;
  28. }
  29. const key = `../${m[1]}`;
  30. Object.keys(collectedFolders).forEach(folder => {
  31. if (file.includes(`Nightwatch/${folder}`)) {
  32. collectedFolders[folder].push(`${searchDirectory}${key}/${folder}`);
  33. }
  34. });
  35. m = regex.exec(file);
  36. }
  37. });
  38. // Remove duplicate folders.
  39. Object.keys(collectedFolders).forEach(folder => {
  40. collectedFolders[folder] = Array.from(new Set(collectedFolders[folder]));
  41. });
  42. module.exports = {
  43. src_folders: collectedFolders.Tests,
  44. output_folder: process.env.DRUPAL_NIGHTWATCH_OUTPUT,
  45. custom_commands_path: collectedFolders.Commands,
  46. custom_assertions_path: collectedFolders.Assertions,
  47. page_objects_path: collectedFolders.Pages,
  48. globals_path: 'globals.js',
  49. selenium: {
  50. start_process: false,
  51. },
  52. test_settings: {
  53. default: {
  54. selenium_port: process.env.DRUPAL_TEST_WEBDRIVER_PORT,
  55. selenium_host: process.env.DRUPAL_TEST_WEBDRIVER_HOSTNAME,
  56. default_path_prefix: process.env.DRUPAL_TEST_WEBDRIVER_PATH_PREFIX || '',
  57. desiredCapabilities: {
  58. browserName: 'chrome',
  59. acceptSslCerts: true,
  60. chromeOptions: {
  61. w3c: false,
  62. args: process.env.DRUPAL_TEST_WEBDRIVER_CHROME_ARGS
  63. ? process.env.DRUPAL_TEST_WEBDRIVER_CHROME_ARGS.split(' ')
  64. : [],
  65. },
  66. },
  67. screenshots: {
  68. enabled: true,
  69. on_failure: true,
  70. on_error: true,
  71. path: `${process.env.DRUPAL_NIGHTWATCH_OUTPUT}/screenshots`,
  72. },
  73. end_session_on_fail: false,
  74. },
  75. local: {
  76. webdriver: {
  77. start_process: process.env.DRUPAL_TEST_CHROMEDRIVER_AUTOSTART,
  78. port: process.env.DRUPAL_TEST_WEBDRIVER_PORT,
  79. server_path: 'node_modules/.bin/chromedriver',
  80. },
  81. desiredCapabilities: {
  82. browserName: 'chrome',
  83. acceptSslCerts: true,
  84. chromeOptions: {
  85. w3c: false,
  86. args: process.env.DRUPAL_TEST_WEBDRIVER_CHROME_ARGS
  87. ? process.env.DRUPAL_TEST_WEBDRIVER_CHROME_ARGS.split(' ')
  88. : [],
  89. },
  90. },
  91. screenshots: {
  92. enabled: true,
  93. on_failure: true,
  94. on_error: true,
  95. path: `${process.env.DRUPAL_NIGHTWATCH_OUTPUT}/screenshots`,
  96. },
  97. end_session_on_fail: false,
  98. },
  99. },
  100. };