runner.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.Runner = void 0;
  6. var _utils = require("playwright-core/lib/utils");
  7. var _webServerPlugin = require("../plugins/webServerPlugin");
  8. var _projectUtils = require("./projectUtils");
  9. var _reporters = require("./reporters");
  10. var _tasks = require("./tasks");
  11. var _utilsBundle = require("playwright-core/lib/utilsBundle");
  12. var _watchMode = require("./watchMode");
  13. var _uiMode = require("./uiMode");
  14. var _internalReporter = require("../reporters/internalReporter");
  15. var _multiplexer = require("../reporters/multiplexer");
  16. /**
  17. * Copyright 2019 Google Inc. All rights reserved.
  18. * Modifications copyright (c) Microsoft Corporation.
  19. *
  20. * Licensed under the Apache License, Version 2.0 (the "License");
  21. * you may not use this file except in compliance with the License.
  22. * You may obtain a copy of the License at
  23. *
  24. * http://www.apache.org/licenses/LICENSE-2.0
  25. *
  26. * Unless required by applicable law or agreed to in writing, software
  27. * distributed under the License is distributed on an "AS IS" BASIS,
  28. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  29. * See the License for the specific language governing permissions and
  30. * limitations under the License.
  31. */
  32. class Runner {
  33. constructor(config) {
  34. this._config = void 0;
  35. this._config = config;
  36. }
  37. async listTestFiles(projectNames) {
  38. const projects = (0, _projectUtils.filterProjects)(this._config.projects, projectNames);
  39. const report = {
  40. projects: []
  41. };
  42. for (const project of projects) {
  43. report.projects.push({
  44. name: project.project.name,
  45. testDir: project.project.testDir,
  46. use: {
  47. testIdAttribute: project.project.use.testIdAttribute
  48. },
  49. files: await (0, _projectUtils.collectFilesForProject)(project)
  50. });
  51. }
  52. return report;
  53. }
  54. async runAllTests() {
  55. const config = this._config;
  56. const listOnly = config.cliListOnly;
  57. const deadline = config.config.globalTimeout ? (0, _utils.monotonicTime)() + config.config.globalTimeout : 0;
  58. // Legacy webServer support.
  59. (0, _webServerPlugin.webServerPluginsForConfig)(config).forEach(p => config.plugins.push({
  60. factory: p
  61. }));
  62. const reporter = new _internalReporter.InternalReporter(new _multiplexer.Multiplexer(await (0, _reporters.createReporters)(config, listOnly ? 'list' : 'run')));
  63. const taskRunner = listOnly ? (0, _tasks.createTaskRunnerForList)(config, reporter, 'in-process', {
  64. failOnLoadErrors: true
  65. }) : (0, _tasks.createTaskRunner)(config, reporter);
  66. const testRun = new _tasks.TestRun(config, reporter);
  67. reporter.onConfigure(config.config);
  68. if (!listOnly && config.ignoreSnapshots) {
  69. reporter.onStdOut(_utilsBundle.colors.dim(['NOTE: running with "ignoreSnapshots" option. All of the following asserts are silently ignored:', '- expect().toMatchSnapshot()', '- expect().toHaveScreenshot()', ''].join('\n')));
  70. }
  71. const taskStatus = await taskRunner.run(testRun, deadline);
  72. let status = testRun.failureTracker.result();
  73. if (status === 'passed' && taskStatus !== 'passed') status = taskStatus;
  74. const modifiedResult = await reporter.onEnd({
  75. status
  76. });
  77. if (modifiedResult && modifiedResult.status) status = modifiedResult.status;
  78. await reporter.onExit();
  79. // Calling process.exit() might truncate large stdout/stderr output.
  80. // See https://github.com/nodejs/node/issues/6456.
  81. // See https://github.com/nodejs/node/issues/12921
  82. await new Promise(resolve => process.stdout.write('', () => resolve()));
  83. await new Promise(resolve => process.stderr.write('', () => resolve()));
  84. return status;
  85. }
  86. async watchAllTests() {
  87. const config = this._config;
  88. (0, _webServerPlugin.webServerPluginsForConfig)(config).forEach(p => config.plugins.push({
  89. factory: p
  90. }));
  91. return await (0, _watchMode.runWatchModeLoop)(config);
  92. }
  93. async uiAllTests(options) {
  94. const config = this._config;
  95. (0, _webServerPlugin.webServerPluginsForConfig)(config).forEach(p => config.plugins.push({
  96. factory: p
  97. }));
  98. return await (0, _uiMode.runUIMode)(config, options);
  99. }
  100. }
  101. exports.Runner = Runner;