loaderHost.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.OutOfProcessLoaderHost = exports.InProcessLoaderHost = void 0;
  6. var _ipc = require("../common/ipc");
  7. var _processHost = require("./processHost");
  8. var _test = require("../common/test");
  9. var _testLoader = require("../common/testLoader");
  10. var _poolBuilder = require("../common/poolBuilder");
  11. var _compilationCache = require("../transform/compilationCache");
  12. var _esmLoaderHost = require("../common/esmLoaderHost");
  13. /**
  14. * Copyright Microsoft Corporation. All rights reserved.
  15. *
  16. * Licensed under the Apache License, Version 2.0 (the "License");
  17. * you may not use this file except in compliance with the License.
  18. * You may obtain a copy of the License at
  19. *
  20. * http://www.apache.org/licenses/LICENSE-2.0
  21. *
  22. * Unless required by applicable law or agreed to in writing, software
  23. * distributed under the License is distributed on an "AS IS" BASIS,
  24. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. * See the License for the specific language governing permissions and
  26. * limitations under the License.
  27. */
  28. class InProcessLoaderHost {
  29. constructor(config) {
  30. this._config = void 0;
  31. this._poolBuilder = void 0;
  32. this._config = config;
  33. this._poolBuilder = _poolBuilder.PoolBuilder.createForLoader();
  34. }
  35. async start(errors) {
  36. await (0, _esmLoaderHost.initializeEsmLoader)();
  37. return true;
  38. }
  39. async loadTestFile(file, testErrors) {
  40. const result = await (0, _testLoader.loadTestFile)(file, this._config.config.rootDir, testErrors);
  41. this._poolBuilder.buildPools(result, testErrors);
  42. return result;
  43. }
  44. async stop() {
  45. await (0, _esmLoaderHost.incorporateCompilationCache)();
  46. }
  47. }
  48. exports.InProcessLoaderHost = InProcessLoaderHost;
  49. class OutOfProcessLoaderHost {
  50. constructor(config) {
  51. this._config = void 0;
  52. this._processHost = void 0;
  53. this._config = config;
  54. this._processHost = new _processHost.ProcessHost(require.resolve('../loader/loaderMain.js'), 'loader', {});
  55. }
  56. async start(errors) {
  57. const startError = await this._processHost.startRunner((0, _ipc.serializeConfig)(this._config));
  58. if (startError) {
  59. errors.push({
  60. message: `Test loader process failed to start with code "${startError.code}" and signal "${startError.signal}"`
  61. });
  62. return false;
  63. }
  64. return true;
  65. }
  66. async loadTestFile(file, testErrors) {
  67. const result = await this._processHost.sendMessage({
  68. method: 'loadTestFile',
  69. params: {
  70. file
  71. }
  72. });
  73. testErrors.push(...result.testErrors);
  74. return _test.Suite._deepParse(result.fileSuite);
  75. }
  76. async stop() {
  77. const result = await this._processHost.sendMessage({
  78. method: 'getCompilationCacheFromLoader'
  79. });
  80. (0, _compilationCache.addToCompilationCache)(result);
  81. await this._processHost.stop();
  82. }
  83. }
  84. exports.OutOfProcessLoaderHost = OutOfProcessLoaderHost;