Innovenergy_trunk/frontend/node_modules/testcafe/lib/live/bootstrapper.js

47 lines
5.8 KiB
JavaScript
Raw Permalink Normal View History

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const module_1 = __importDefault(require("module"));
const bootstrapper_1 = __importDefault(require("../runner/bootstrapper"));
const compiler_1 = __importDefault(require("../compiler"));
const cache_proxy_1 = __importDefault(require("./../compiler/test-file/cache-proxy"));
const originalRequire = module_1.default.prototype.require;
class LiveModeBootstrapper extends bootstrapper_1.default {
constructor(runner, browserConnectionGateway, compilerService, messageBus) {
super({ browserConnectionGateway, compilerService, messageBus });
this.runner = runner;
cache_proxy_1.default.preventCaching();
}
_getTests(id) {
this._mockRequire();
return super._getTests(id)
.then(result => {
this._restoreRequire();
return result;
})
.catch(err => {
this._restoreRequire();
compiler_1.default.cleanUp();
this.runner.setBootstrappingError(err);
});
}
_mockRequire() {
const controller = this.runner.controller;
// NODE: we replace the `require` method to add required files to watcher
module_1.default.prototype.require = function (filePath) {
const filename = module_1.default._resolveFilename(filePath, this, false);
if (path_1.default.isAbsolute(filename) || /^\.\.?[/\\]/.test(filename))
controller.addFileToWatches(filename);
return originalRequire.apply(this, arguments);
};
}
_restoreRequire() {
module_1.default.prototype.require = originalRequire;
}
}
exports.default = LiveModeBootstrapper;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYm9vdHN0cmFwcGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL2xpdmUvYm9vdHN0cmFwcGVyLmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUEsZ0RBQXdCO0FBQ3hCLG9EQUE0QjtBQUM1QiwwRUFBa0Q7QUFDbEQsMkRBQW1DO0FBQ25DLHNGQUE2RDtBQUU3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