@serenity-js/jasmine
Version:
Serenity/JS test runner adapter for Jasmine, enabling the use of the Screenplay Pattern in Jasmine-based test suites and leveraging Serenity/JS reporting capabilities
46 lines • 2.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.bootstrap = bootstrap;
const core_1 = require("@serenity-js/core");
const index_js_1 = require("@serenity-js/core/lib/io/index.js");
const monkeyPatched_js_1 = require("./monkeyPatched.js");
const SerenityReporterForJasmine_js_1 = require("./SerenityReporterForJasmine.js");
/**
* Monkey-patches Jasmine's Suite and Spec so that they provide more accurate information,
* and returns a bootstrapped instance of the [`SerenityReporterForJasmine`](https://serenity-js.org/api/jasmine/function/default/) to be registered with Jasmine.
*
* ## Registering the reporter from the command line
*
* ```terminal
* jasmine --reporter=@serenity-js/jasmine
* ```
*
* ## Registering the reporter programmatically
*
* ```ts
* import serenityReporterForJasmine = require('@serenity-js/jasmine');
*
* jasmine.getEnv().addReporter(serenityReporterForJasmine);
* ```
*
* @param config
* @param jasmine
* the global.jasmine instance
*/
function bootstrap(config = {}, jasmine = global.jasmine) {
const wrappers = {
expectationResultFactory: originalExpectationResultFactory => ((attributes) => {
const result = originalExpectationResultFactory(attributes);
if (!attributes.passed && attributes.error instanceof core_1.RuntimeError) {
result.stack = attributes.error.stack;
}
return result;
}),
};
jasmine.Suite = (0, monkeyPatched_js_1.monkeyPatched)(jasmine.Suite, wrappers);
jasmine.Spec = (0, monkeyPatched_js_1.monkeyPatched)(jasmine.Spec, wrappers);
const cwd = index_js_1.Path.from(process.cwd());
const requirementsHierarchy = new index_js_1.RequirementsHierarchy(new index_js_1.FileSystem(cwd), config?.specDirectory && cwd.resolve(index_js_1.Path.from(config?.specDirectory)));
return new SerenityReporterForJasmine_js_1.SerenityReporterForJasmine(core_1.serenity, requirementsHierarchy);
}
//# sourceMappingURL=bootstrap.js.map