How to use pluginLoader method in stryker-parent

Best JavaScript code snippet using stryker-parent

PluginLoader.test.ts

Source:PluginLoader.test.ts Github

copy

Full Screen

1/*2 * Copyright The OpenTelemetry Authors3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * https://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16import { NoopTracerProvider, diag } from '@opentelemetry/api';17import * as assert from 'assert';18import * as path from 'path';19import sinon = require('sinon');20import {21 HookState,22 PluginLoader,23 Plugins,24 searchPathForTest,25 ENV_PLUGIN_DISABLED_LIST,26} from '../../src/platform/node/old/PluginLoader';27const INSTALLED_PLUGINS_PATH = path.join(__dirname, 'node_modules');28/* eslint-disable node/no-extraneous-require */29const simplePlugins: Plugins = {30 'simple-module': {31 enabled: true,32 path: '@opentelemetry/plugin-simple-module',33 ignoreMethods: [],34 ignoreUrls: [],35 },36};37const httpPlugins: Plugins = {38 http: {39 enabled: true,40 path: '@opentelemetry/plugin-http-module',41 ignoreMethods: [],42 ignoreUrls: [],43 },44};45const disablePlugins: Plugins = {46 'simple-module': {47 enabled: false,48 path: '@opentelemetry/plugin-simple-module',49 },50 nonexistent: {51 enabled: false,52 path: '@opentelemetry/plugin-nonexistent-module',53 },54};55const nonexistentPlugins: Plugins = {56 nonexistent: {57 enabled: true,58 path: '@opentelemetry/plugin-nonexistent-module',59 },60};61const missingPathPlugins: Plugins = {62 'simple-module': {63 enabled: true,64 },65 nonexistent: {66 enabled: true,67 },68};69const supportedVersionPlugins: Plugins = {70 'supported-module': {71 enabled: true,72 path: '@opentelemetry/plugin-supported-module',73 },74};75const notSupportedVersionPlugins: Plugins = {76 'notsupported-module': {77 enabled: true,78 path: 'notsupported-module',79 },80};81const alreadyRequiredPlugins: Plugins = {82 'already-require-module': {83 enabled: true,84 path: '@opentelemetry/plugin-supported-module',85 },86};87const differentNamePlugins: Plugins = {88 'random-module': {89 enabled: true,90 path: '@opentelemetry/plugin-http-module',91 },92};93describe('PluginLoader', () => {94 const provider = new NoopTracerProvider();95 before(() => {96 module.paths.push(INSTALLED_PLUGINS_PATH);97 searchPathForTest(INSTALLED_PLUGINS_PATH);98 });99 afterEach(() => {100 // clear require cache101 Object.keys(require.cache).forEach(key => delete require.cache[key]);102 sinon.restore();103 });104 describe('.state()', () => {105 it('returns UNINITIALIZED when first called', () => {106 const pluginLoader = new PluginLoader(provider);107 assert.strictEqual(pluginLoader['_hookState'], HookState.UNINITIALIZED);108 });109 it('transitions from UNINITIALIZED to ENABLED', () => {110 const pluginLoader = new PluginLoader(provider);111 pluginLoader.load(simplePlugins);112 assert.strictEqual(pluginLoader['_hookState'], HookState.ENABLED);113 pluginLoader.unload();114 });115 it('transitions from ENABLED to DISABLED', () => {116 const pluginLoader = new PluginLoader(provider);117 pluginLoader.load(simplePlugins).unload();118 assert.strictEqual(pluginLoader['_hookState'], HookState.DISABLED);119 });120 });121 describe('.load()', () => {122 afterEach(() => {123 delete process.env[ENV_PLUGIN_DISABLED_LIST];124 });125 it('sanity check', () => {126 // Ensure that module fixtures contain values that we expect.127 const simpleModule = require('simple-module');128 const simpleModule001 = require('supported-module');129 const simpleModule100 = require('notsupported-module');130 assert.strictEqual(simpleModule.name(), 'simple-module');131 assert.strictEqual(simpleModule001.name(), 'supported-module');132 assert.strictEqual(simpleModule100.name(), 'notsupported-module');133 assert.strictEqual(simpleModule.value(), 0);134 assert.strictEqual(simpleModule001.value(), 0);135 assert.strictEqual(simpleModule100.value(), 0);136 assert.throws(() => require('nonexistent-module'));137 });138 it('should not load a plugin on the ignore list environment variable', () => {139 // Set ignore list env var140 process.env[ENV_PLUGIN_DISABLED_LIST] = 'simple-module';141 const pluginLoader = new PluginLoader(provider);142 pluginLoader.load({ ...simplePlugins, ...supportedVersionPlugins });143 assert.strictEqual(pluginLoader['plugins'].length, 0);144 const simpleModule = require('simple-module');145 assert.strictEqual(pluginLoader['plugins'].length, 0);146 assert.strictEqual(simpleModule.value(), 0);147 assert.strictEqual(simpleModule.name(), 'simple-module');148 const supportedModule = require('supported-module');149 assert.strictEqual(pluginLoader['plugins'].length, 1);150 assert.strictEqual(supportedModule.value(), 1);151 assert.strictEqual(supportedModule.name(), 'patched-supported-module');152 pluginLoader.unload();153 });154 it('should not load plugins on the ignore list environment variable', () => {155 // Set ignore list env var156 process.env[ENV_PLUGIN_DISABLED_LIST] = 'simple-module,http';157 const pluginLoader = new PluginLoader(provider);158 pluginLoader.load({159 ...simplePlugins,160 ...supportedVersionPlugins,161 ...httpPlugins,162 });163 assert.strictEqual(pluginLoader['plugins'].length, 0);164 const simpleModule = require('simple-module');165 assert.strictEqual(pluginLoader['plugins'].length, 0);166 assert.strictEqual(simpleModule.value(), 0);167 assert.strictEqual(simpleModule.name(), 'simple-module');168 const httpModule = require('http');169 assert.ok(httpModule);170 assert.strictEqual(pluginLoader['plugins'].length, 0);171 const supportedModule = require('supported-module');172 assert.strictEqual(pluginLoader['plugins'].length, 1);173 assert.strictEqual(supportedModule.value(), 1);174 assert.strictEqual(supportedModule.name(), 'patched-supported-module');175 pluginLoader.unload();176 });177 it('should not load any plugins if ignore list environment variable is set to "*"', () => {178 // Set ignore list env var179 process.env[ENV_PLUGIN_DISABLED_LIST] = '*';180 const pluginLoader = new PluginLoader(provider);181 pluginLoader.load({182 ...simplePlugins,183 ...supportedVersionPlugins,184 ...httpPlugins,185 });186 assert.strictEqual(pluginLoader['plugins'].length, 0);187 const simpleModule = require('simple-module');188 const httpModule = require('http');189 const supportedModule = require('supported-module');190 assert.strictEqual(191 pluginLoader['plugins'].length,192 0,193 'No plugins were loaded'194 );195 assert.strictEqual(simpleModule.value(), 0);196 assert.strictEqual(simpleModule.name(), 'simple-module');197 assert.ok(httpModule);198 assert.strictEqual(supportedModule.value(), 0);199 assert.strictEqual(supportedModule.name(), 'supported-module');200 pluginLoader.unload();201 });202 it('should load a plugin and patch the target modules', () => {203 const pluginLoader = new PluginLoader(provider);204 assert.strictEqual(pluginLoader['plugins'].length, 0);205 pluginLoader.load(simplePlugins);206 // The hook is only called the first time the module is loaded.207 const simpleModule = require('simple-module');208 assert.strictEqual(pluginLoader['plugins'].length, 1);209 assert.strictEqual(simpleModule.value(), 1);210 assert.strictEqual(simpleModule.name(), 'patched-simple-module');211 pluginLoader.unload();212 });213 it('should load a plugin and patch the core module', () => {214 const pluginLoader = new PluginLoader(provider);215 assert.strictEqual(pluginLoader['plugins'].length, 0);216 pluginLoader.load(httpPlugins);217 // The hook is only called the first time the module is loaded.218 const httpModule = require('http');219 assert.strictEqual(pluginLoader['plugins'].length, 1);220 assert.strictEqual(httpModule.get(), 'patched');221 pluginLoader.unload();222 });223 // @TODO: simplify this test once we can load module with custom path224 it('should not load the plugin when supported versions does not match', () => {225 const pluginLoader = new PluginLoader(provider);226 assert.strictEqual(pluginLoader['plugins'].length, 0);227 pluginLoader.load(notSupportedVersionPlugins);228 // The hook is only called the first time the module is loaded.229 require('notsupported-module');230 assert.strictEqual(pluginLoader['plugins'].length, 0);231 pluginLoader.unload();232 });233 // @TODO: simplify this test once we can load module with custom path234 it('should load a plugin and patch the target modules when supported versions match', () => {235 const pluginLoader = new PluginLoader(provider);236 assert.strictEqual(pluginLoader['plugins'].length, 0);237 pluginLoader.load(supportedVersionPlugins);238 // The hook is only called the first time the module is loaded.239 const simpleModule = require('supported-module');240 assert.strictEqual(pluginLoader['plugins'].length, 1);241 assert.strictEqual(simpleModule.value(), 1);242 assert.strictEqual(simpleModule.name(), 'patched-supported-module');243 pluginLoader.unload();244 });245 it('should not load a plugin when value is false', () => {246 const pluginLoader = new PluginLoader(provider);247 assert.strictEqual(pluginLoader['plugins'].length, 0);248 pluginLoader.load(disablePlugins);249 const simpleModule = require('simple-module');250 assert.strictEqual(pluginLoader['plugins'].length, 0);251 assert.strictEqual(simpleModule.value(), 0);252 assert.strictEqual(simpleModule.name(), 'simple-module');253 pluginLoader.unload();254 });255 it('should not load a plugin when value is true but path is missing', () => {256 const pluginLoader = new PluginLoader(provider);257 assert.strictEqual(pluginLoader['plugins'].length, 0);258 pluginLoader.load(missingPathPlugins);259 const simpleModule = require('simple-module');260 assert.strictEqual(pluginLoader['plugins'].length, 0);261 assert.strictEqual(simpleModule.value(), 0);262 assert.strictEqual(simpleModule.name(), 'simple-module');263 pluginLoader.unload();264 });265 it('should not load a non existing plugin', () => {266 const pluginLoader = new PluginLoader(provider);267 assert.strictEqual(pluginLoader['plugins'].length, 0);268 pluginLoader.load(nonexistentPlugins);269 assert.strictEqual(pluginLoader['plugins'].length, 0);270 pluginLoader.unload();271 });272 it("doesn't patch modules for which plugins aren't specified", () => {273 const pluginLoader = new PluginLoader(provider);274 pluginLoader.load({});275 assert.strictEqual(require('simple-module').value(), 0);276 pluginLoader.unload();277 });278 it('should warn when module was already loaded', () => {279 const warnStub = sinon.stub(diag, 'warn');280 require('already-require-module');281 const pluginLoader = new PluginLoader(provider);282 pluginLoader.load(alreadyRequiredPlugins);283 pluginLoader.unload();284 sinon.assert.calledOnce(warnStub);285 const message = warnStub.firstCall.args[0];286 assert.ok(message.match(/were already required when/));287 assert.ok(message.match(/(already-require-module)/));288 });289 it('should not load a plugin that patches a different module that the one configured', () => {290 const pluginLoader = new PluginLoader(provider);291 assert.strictEqual(pluginLoader['plugins'].length, 0);292 pluginLoader.load(differentNamePlugins);293 require('random-module');294 assert.strictEqual(pluginLoader['plugins'].length, 0);295 pluginLoader.unload();296 });297 });298 describe('.unload()', () => {299 it('should unload the plugins and unpatch the target module when unloads', () => {300 const pluginLoader = new PluginLoader(provider);301 assert.strictEqual(pluginLoader['plugins'].length, 0);302 pluginLoader.load(simplePlugins);303 // The hook is only called the first time the module is loaded.304 const simpleModule = require('simple-module');305 assert.strictEqual(pluginLoader['plugins'].length, 1);306 assert.strictEqual(simpleModule.value(), 1);307 assert.strictEqual(simpleModule.name(), 'patched-simple-module');308 pluginLoader.unload();309 assert.strictEqual(pluginLoader['plugins'].length, 0);310 assert.strictEqual(simpleModule.name(), 'simple-module');311 assert.strictEqual(simpleModule.value(), 0);312 });313 });...

Full Screen

Full Screen

plugin.js

Source:plugin.js Github

copy

Full Screen

1const assert = require("assert");2const pluginLoader = require("../lib/plugin");3const TruffleError = require("truffle-error");4const originalRequire = require("original-require");5const path = require("path");6describe("plugin loader", () => {7 originalRequire("app-module-path").addPath(8 path.resolve(process.cwd(), "test/mockPlugins")9 );10 describe("checkPluginConfig", () => {11 it("throws when passed an options.plugins non-array or empty array value", () => {12 assert.throws(13 () => {14 pluginLoader.checkPluginConfig({ plugins: "string" });15 },16 TruffleError,17 "TruffleError not thrown!"18 );19 assert.throws(20 () => {21 pluginLoader.checkPluginConfig({ plugins: 1234 });22 },23 TruffleError,24 "TruffleError not thrown!"25 );26 assert.throws(27 () => {28 pluginLoader.checkPluginConfig({ plugins: { foo: "bar" } });29 },30 TruffleError,31 "TruffleError not thrown!"32 );33 assert.throws(34 () => {35 pluginLoader.checkPluginConfig({ plugins: [] });36 },37 TruffleError,38 "TruffleError not thrown!"39 );40 assert.throws(41 () => {42 pluginLoader.checkPluginConfig({ plugins: null });43 },44 TruffleError,45 "TruffleError not thrown!"46 );47 assert.throws(48 () => {49 pluginLoader.checkPluginConfig({ plugins: undefined });50 },51 TruffleError,52 "TruffleError not thrown!"53 );54 });55 it("returns options when passed a valid options.plugins array value", () => {56 assert(pluginLoader.checkPluginConfig({ plugins: ["truffle-test"] }));57 let pluginOptions = pluginLoader.checkPluginConfig({58 plugins: ["truffle-test"]59 });60 assert(pluginOptions);61 assert.deepEqual(pluginOptions, { plugins: ["truffle-test"] });62 assert(63 pluginLoader.checkPluginConfig({64 plugins: ["truffle-test", "truffle-analyze"]65 })66 );67 pluginOptions = pluginLoader.checkPluginConfig({68 plugins: ["truffle-test", "truffle-analyze"]69 });70 assert(pluginOptions);71 assert.deepEqual(pluginOptions, {72 plugins: ["truffle-test", "truffle-analyze"]73 });74 });75 });76 describe("checkPluginModules", () => {77 it("throws when options.plugins are specified but not locally or globally installed", () => {78 assert.throws(79 () => {80 pluginLoader.checkPluginModules({81 plugins: ["truffle-analyze"],82 working_directory: process.cwd()83 });84 },85 TruffleError,86 "TruffleError not thrown!"87 );88 assert.throws(89 () => {90 pluginLoader.checkPluginModules({91 plugins: ["truffle-analyze", "truffle-test"],92 working_directory: process.cwd()93 });94 },95 TruffleError,96 "TruffleError not thrown!"97 );98 });99 it("returns array of locally or globally installed options.plugins", () => {100 assert(101 pluginLoader.checkPluginModules({102 plugins: ["truffle-box"],103 working_directory: process.cwd()104 })105 );106 let pluginArray = pluginLoader.checkPluginModules({107 plugins: ["truffle-box"],108 working_directory: process.cwd()109 });110 assert(pluginArray);111 assert(Array.isArray(pluginArray) && pluginArray.length === 1);112 assert(113 pluginLoader.checkPluginModules({114 plugins: ["truffle-box", "truffle-config"],115 working_directory: process.cwd()116 })117 );118 pluginArray = pluginLoader.checkPluginModules({119 plugins: ["truffle-box", "truffle-config"],120 working_directory: process.cwd()121 });122 assert(pluginArray);123 assert(Array.isArray(pluginArray) && pluginArray.length === 2);124 });125 });126 describe("loadPluginModules", () => {127 it("throws when plugins are installed without a truffle-plugin.json configuration file", () => {128 assert.throws(129 () => {130 pluginLoader.loadPluginModules(["truffle-box"]);131 },132 TruffleError,133 "TruffleError not thrown!"134 );135 assert.throws(136 () => {137 pluginLoader.loadPluginModules(["truffle-box", "truffle-config"]);138 },139 TruffleError,140 "TruffleError not thrown!"141 );142 });143 it("returns object of plugins installed with the truffle-plugin.json file loaded", () => {144 assert(pluginLoader.loadPluginModules(["truffle-mock"]));145 let pluginObj = pluginLoader.loadPluginModules(["truffle-mock"]);146 assert(pluginObj);147 assert(typeof pluginObj === "object");148 let pluginConfig = originalRequire("truffle-mock/truffle-plugin.json");149 assert(pluginConfig === pluginObj["truffle-mock"]);150 assert(151 pluginLoader.loadPluginModules(["truffle-mock", "truffle-other-mock"])152 );153 pluginObj = pluginLoader.loadPluginModules([154 "truffle-mock",155 "truffle-other-mock"156 ]);157 assert(pluginObj);158 assert(typeof pluginObj === "object");159 pluginConfig = originalRequire("truffle-other-mock/truffle-plugin.json");160 assert(pluginConfig === pluginObj["truffle-other-mock"]);161 });162 });163 describe("load", () => {164 describe("TruffleError handling", () => {165 it("throws when passed an options.plugins non-array or empty array value", () => {166 assert.throws(167 () => {168 pluginLoader.checkPluginConfig({ plugins: "string" });169 },170 TruffleError,171 "TruffleError not thrown!"172 );173 assert.throws(174 () => {175 pluginLoader.checkPluginConfig({ plugins: 1234 });176 },177 TruffleError,178 "TruffleError not thrown!"179 );180 assert.throws(181 () => {182 pluginLoader.checkPluginConfig({ plugins: { foo: "bar" } });183 },184 TruffleError,185 "TruffleError not thrown!"186 );187 assert.throws(188 () => {189 pluginLoader.checkPluginConfig({ plugins: [] });190 },191 TruffleError,192 "TruffleError not thrown!"193 );194 assert.throws(195 () => {196 pluginLoader.checkPluginConfig({ plugins: null });197 },198 TruffleError,199 "TruffleError not thrown!"200 );201 assert.throws(202 () => {203 pluginLoader.checkPluginConfig({ plugins: undefined });204 },205 TruffleError,206 "TruffleError not thrown!"207 );208 });209 it("throws when options.plugins are specified but not locally or globally installed", () => {210 assert.throws(211 () => {212 pluginLoader.checkPluginModules({213 plugins: ["truffle-analyze"],214 working_directory: process.cwd()215 });216 },217 TruffleError,218 "TruffleError not thrown!"219 );220 assert.throws(221 () => {222 pluginLoader.checkPluginModules({223 plugins: ["truffle-analyze", "truffle-test"],224 working_directory: process.cwd()225 });226 },227 TruffleError,228 "TruffleError not thrown!"229 );230 });231 it("throws when plugins are installed without a truffle-plugin.json configuration file", () => {232 assert.throws(233 () => {234 pluginLoader.loadPluginModules(["truffle-box"]);235 },236 TruffleError,237 "TruffleError not thrown!"238 );239 assert.throws(240 () => {241 pluginLoader.loadPluginModules(["truffle-box", "truffle-config"]);242 },243 TruffleError,244 "TruffleError not thrown!"245 );246 });247 });248 it("returns object of plugins installed & truffle-plugin.json data when passed a valid options.plugins array", () => {249 assert(250 pluginLoader.load({251 plugins: ["truffle-mock"],252 working_directory: process.cwd()253 })254 );255 let pluginObj = pluginLoader.load({256 plugins: ["truffle-mock"],257 working_directory: process.cwd()258 });259 assert(pluginObj);260 assert(typeof pluginObj === "object");261 let pluginConfig = originalRequire("truffle-mock/truffle-plugin.json");262 assert(pluginConfig === pluginObj["truffle-mock"]);263 assert(264 pluginLoader.load({265 plugins: ["truffle-mock", "truffle-other-mock"],266 working_directory: process.cwd()267 })268 );269 pluginObj = pluginLoader.load({270 plugins: ["truffle-mock", "truffle-other-mock"],271 working_directory: process.cwd()272 });273 assert(pluginObj);274 assert(typeof pluginObj === "object");275 pluginConfig = originalRequire("truffle-other-mock/truffle-plugin.json");276 assert(pluginConfig === pluginObj["truffle-other-mock"]);277 });278 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const pluginLoader = require('stryker-parent').pluginLoader;2const pluginLoader = require('stryker-api').pluginLoader;3const pluginLoader = require('stryker').pluginLoader;4const pluginLoader = require('stryker-parent').pluginLoader;5const pluginLoader = require('stryker-api').pluginLoader;6const pluginLoader = require('stryker').pluginLoader;7const pluginLoader = require('stryker-parent').pluginLoader;8const pluginLoader = require('stryker-api').pluginLoader;9const pluginLoader = require('stryker').pluginLoader;10const pluginLoader = require('stryker-parent').pluginLoader;11const pluginLoader = require('stryker-api').pluginLoader;12const pluginLoader = require('stryker').pluginLoader;13const pluginLoader = require('stryker-parent').pluginLoader;14const pluginLoader = require('stryker-api').pluginLoader;15const pluginLoader = require('stryker').pluginLoader;16const pluginLoader = require('stryker-parent').pluginLoader;17const pluginLoader = require('stryker-api').pluginLoader;18const pluginLoader = require('stryker').pluginLoader;19const pluginLoader = require('stryker-parent').pluginLoader;20const pluginLoader = require('stryker-api').pluginLoader;

Full Screen

Using AI Code Generation

copy

Full Screen

1var pluginLoader = require('stryker-parent').pluginLoader;2var config = require('./stryker.conf.js');3pluginLoader.load(config);4pluginLoader.load(config).init();5var loadedPlugins = pluginLoader.load(config).init();6var loadedPlugins = pluginLoader.load(config).init().config();7var loadedPlugins = pluginLoader.load(config).init().config().log();8var loadedPlugins = pluginLoader.load(config).init().config().log().exec(function(loadedPlugins){9});10var loadedPlugins = pluginLoader.load(config).init().config().log().exec(function(loadedPlugins){11}).config();12var loadedPlugins = pluginLoader.load(config).init().config().log().exec(function(loadedPlugins){13}).config().log();14var loadedPlugins = pluginLoader.load(config).init().config().log().exec(function(loadedPlugins){15}).config().log().exec(function(loadedPlugins){16});

Full Screen

Using AI Code Generation

copy

Full Screen

1const pluginLoader = require('stryker-parent').pluginLoader;2const plugin = pluginLoader.load('stryker-mocha-runner');3plugin.run();4module.exports = {5 run: function () {6 console.log('running plugin');7 }8};9You can find the code of the pluginLoader.load() method in the Stryker project here:

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run stryker-parent automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful