nightwatch.conf.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. };
  10. const searchDirectory = process.env.DRUPAL_NIGHTWATCH_SEARCH_DIRECTORY || '';
  11. glob
  12. .sync('**/tests/**/Nightwatch/**/*.js', {
  13. cwd: path.resolve(process.cwd(), `../${searchDirectory}`),
  14. ignore: process.env.DRUPAL_NIGHTWATCH_IGNORE_DIRECTORIES
  15. ? process.env.DRUPAL_NIGHTWATCH_IGNORE_DIRECTORIES.split(',')
  16. : [],
  17. })
  18. .forEach(file => {
  19. let m = regex.exec(file);
  20. while (m !== null) {
  21. // This is necessary to avoid infinite loops with zero-width matches.
  22. if (m.index === regex.lastIndex) {
  23. regex.lastIndex += 1;
  24. }
  25. const key = `../${m[1]}`;
  26. Object.keys(collectedFolders).forEach(folder => {
  27. if (file.includes(`Nightwatch/${folder}`)) {
  28. collectedFolders[folder].push(`${searchDirectory}${key}/${folder}`);
  29. }
  30. });
  31. m = regex.exec(file);
  32. }
  33. });
  34. // Remove duplicate folders.
  35. Object.keys(collectedFolders).forEach(folder => {
  36. collectedFolders[folder] = Array.from(new Set(collectedFolders[folder]));
  37. });
  38. module.exports = {
  39. src_folders: collectedFolders.Tests,
  40. output_folder: process.env.DRUPAL_NIGHTWATCH_OUTPUT,
  41. custom_commands_path: collectedFolders.Commands,
  42. custom_assertions_path: collectedFolders.Assertions,
  43. page_objects_path: '',
  44. globals_path: 'tests/Drupal/Nightwatch/globals.js',
  45. selenium: {
  46. start_process: false,
  47. },
  48. test_settings: {
  49. default: {
  50. selenium_port: process.env.DRUPAL_TEST_WEBDRIVER_PORT,
  51. selenium_host: process.env.DRUPAL_TEST_WEBDRIVER_HOSTNAME,
  52. default_path_prefix: process.env.DRUPAL_TEST_WEBDRIVER_PATH_PREFIX || '',
  53. desiredCapabilities: {
  54. browserName: 'chrome',
  55. acceptSslCerts: true,
  56. chromeOptions: {
  57. args: process.env.DRUPAL_TEST_WEBDRIVER_CHROME_ARGS
  58. ? process.env.DRUPAL_TEST_WEBDRIVER_CHROME_ARGS.split(' ')
  59. : [],
  60. },
  61. },
  62. screenshots: {
  63. enabled: true,
  64. on_failure: true,
  65. on_error: true,
  66. path: `${process.env.DRUPAL_NIGHTWATCH_OUTPUT}/screenshots`,
  67. },
  68. end_session_on_fail: false,
  69. },
  70. },
  71. };