UNPKG

skutter

Version:

Skutter: Opinionated BDD Browser based test framework

66 lines (65 loc) 2.75 kB
"use strict"; const library_load_error_1 = require("../errors/library-load-error"); class RequiredLibraryProvider { constructor(libraryPaths) { this.standardLibraries = []; this.libraries = []; this.libraryPaths = libraryPaths; this.standardLibraries.push("../../steps/html-steps.js"); this.standardLibraries.push("../../steps/inspection-steps.js"); this.standardLibraries.push("../../steps/list-steps.js"); this.standardLibraries.push("../../steps/screenshot-steps.js"); this.standardLibraries.push("../../steps/delay-steps.js"); } get() { if (this.libraries && this.libraries.length > 0) { return this.libraries; } let loadErrors = []; for (let libraryPath of this.standardLibraries) { let libraryFactory = null; let library = null; try { let libraryFactoryType = require(libraryPath); libraryFactory = new libraryFactoryType.default(); if (libraryFactory.createLibrary) { library = libraryFactory.createLibrary(); } else { loadErrors.push({ filePath: libraryPath, error: new Error("Library does not have createLibrary method available.") }); } } catch (loadException) { loadErrors.push({ filePath: libraryPath, error: loadException }); } if (library) { this.libraries.push((library.getYaddaLibrary())); } } if (this.libraryPaths) { for (let libraryPath of this.libraryPaths) { try { let libraryFactory = null; let customLibraryType = require(libraryPath); let library = null; libraryFactory = new customLibraryType.default(); if (libraryFactory.createLibrary) { library = libraryFactory.createLibrary(); } else { loadErrors.push({ filePath: libraryPath, error: new Error("Custom Library does not have createLibrary method available.") }); } this.libraries.push((library.getYaddaLibrary())); } catch (loadException) { loadErrors.push({ filePath: libraryPath, error: loadException }); } } } if (loadErrors.length > 0) { throw new library_load_error_1.LibraryLoadError(loadErrors); } return this.libraries; } } exports.RequiredLibraryProvider = RequiredLibraryProvider;