How to use pluginsForKind method in stryker-parent

Best JavaScript code snippet using stryker-parent

plugin-loader.ts

Source:plugin-loader.ts Github

copy

Full Screen

1import path from 'path';2import fs from 'fs';3import { fileURLToPath, pathToFileURL, URL } from 'url';4import { Logger } from '@stryker-mutator/api/logging';5import { tokens, commonTokens, Plugin, PluginKind } from '@stryker-mutator/api/plugin';6import { notEmpty, propertyPath } from '@stryker-mutator/util';7import { fileUtils } from '../utils/file-utils.js';8import { defaultOptions } from '../config/options-validator.js';9const IGNORED_PACKAGES = ['core', 'api', 'util', 'instrumenter'];10interface PluginModule {11 strykerPlugins: Array<Plugin<PluginKind>>;12}13interface SchemaValidationContribution {14 strykerValidationSchema: Record<string, unknown>;15}16/**17 * Represents a collection of loaded plugins and metadata18 */19export interface LoadedPlugins {20 /**21 * The JSON schema contributions loaded22 */23 schemaContributions: Array<Record<string, unknown>>;24 /**25 * The actual Stryker plugins loaded, sorted by type26 */27 pluginsByKind: Map<PluginKind, Array<Plugin<PluginKind>>>;28 /**29 * The import specifiers or full URL paths to the actual plugins30 */31 pluginModulePaths: string[];32}33/**34 * Can resolve modules and pull them into memory35 */36export class PluginLoader {37 public static inject = tokens(commonTokens.logger);38 constructor(private readonly log: Logger) {}39 /**40 * Loads plugins based on configured plugin descriptors.41 * A plugin descriptor can be:42 * * A full url: "file:///home/nicojs/github/my-plugin.js"43 * * An absolute file path: "/home/nicojs/github/my-plugin.js"44 * * A relative path: "./my-plugin.js"45 * * A bare import expression: "@stryker-mutator/karma-runner"46 * * A simple glob expression (only wild cards are supported): "@stryker-mutator/*"47 */48 public async load(pluginDescriptors: readonly string[]): Promise<LoadedPlugins> {49 const pluginModules = await this.resolvePluginModules(pluginDescriptors);50 const loadedPluginModules = (51 await Promise.all(52 pluginModules.map(async (moduleName) => {53 const plugin = await this.loadPlugin(moduleName);54 return {55 ...plugin,56 moduleName,57 };58 })59 )60 ).filter(notEmpty);61 const result: LoadedPlugins = { schemaContributions: [], pluginsByKind: new Map<PluginKind, Array<Plugin<PluginKind>>>(), pluginModulePaths: [] };62 loadedPluginModules.forEach(({ plugins, schemaContribution, moduleName }) => {63 if (plugins) {64 result.pluginModulePaths.push(moduleName);65 plugins.forEach((plugin) => {66 const pluginsForKind = result.pluginsByKind.get(plugin.kind);67 if (pluginsForKind) {68 pluginsForKind.push(plugin);69 } else {70 result.pluginsByKind.set(plugin.kind, [plugin]);71 }72 });73 }74 if (schemaContribution) {75 result.schemaContributions.push(schemaContribution);76 }77 });78 return result;79 }80 private async resolvePluginModules(pluginDescriptors: readonly string[]): Promise<string[]> {81 return (82 await Promise.all(83 pluginDescriptors.map(async (pluginExpression) => {84 if (pluginExpression.includes('*')) {85 return await this.globPluginModules(pluginExpression);86 } else if (path.isAbsolute(pluginExpression) || pluginExpression.startsWith('.')) {87 return pathToFileURL(path.resolve(pluginExpression)).toString();88 } else {89 // Bare plugin expression like "@stryker-mutator/mocha-runner" (or file URL)90 return pluginExpression;91 }92 })93 )94 )95 .filter(notEmpty)96 .flat();97 }98 private async globPluginModules(pluginExpression: string) {99 const { org, pkg } = parsePluginExpression(pluginExpression);100 const pluginDirectory = path.resolve(fileURLToPath(new URL('../../../../../', import.meta.url)), org);101 const regexp = new RegExp('^' + pkg.replace('*', '.*'));102 this.log.debug('Loading %s from %s', pluginExpression, pluginDirectory);103 const plugins = (await fs.promises.readdir(pluginDirectory))104 .filter((pluginName) => !IGNORED_PACKAGES.includes(pluginName) && regexp.test(pluginName))105 .map((pluginName) => `${org.length ? `${org}/` : ''}${pluginName}`);106 if (plugins.length === 0 && !defaultOptions.plugins.includes(pluginExpression)) {107 this.log.warn('Expression "%s" not resulted in plugins to load.', pluginExpression);108 }109 plugins.forEach((plugin) => this.log.debug('Loading plugin "%s" (matched with expression %s)', plugin, pluginExpression));110 return plugins;111 }112 private async loadPlugin(113 descriptor: string114 ): Promise<{ plugins: Array<Plugin<PluginKind>> | undefined; schemaContribution: Record<string, unknown> | undefined } | undefined> {115 this.log.debug('Loading plugin %s', descriptor);116 try {117 const module = await fileUtils.importModule(descriptor);118 const plugins = isPluginModule(module) ? module.strykerPlugins : undefined;119 const schemaContribution = hasValidationSchemaContribution(module) ? module.strykerValidationSchema : undefined;120 if (plugins || schemaContribution) {121 return {122 plugins,123 schemaContribution,124 };125 } else {126 this.log.warn(127 'Module "%s" did not contribute a StrykerJS plugin. It didn\'t export a "%s" or "%s".',128 descriptor,129 propertyPath<PluginModule>()('strykerPlugins'),130 propertyPath<SchemaValidationContribution>()('strykerValidationSchema')131 );132 }133 } catch (e: any) {134 if (e.code === 'ERR_MODULE_NOT_FOUND' && e.message.indexOf(descriptor) !== -1) {135 this.log.warn('Cannot find plugin "%s".\n Did you forget to install it ?', descriptor);136 } else {137 this.log.warn('Error during loading "%s" plugin:\n %s', descriptor, e.message);138 }139 }140 return;141 }142}143/**144 * Distills organization name from a package expression.145 * @example146 * '@stryker-mutator/core' => { org: '@stryker-mutator', 'core' }147 * 'glob' => { org: '', 'glob' }148 */149function parsePluginExpression(pluginExpression: string) {150 const parts = pluginExpression.split('/');151 if (parts.length > 1) {152 return {153 org: parts.slice(0, parts.length - 1).join('/'),154 pkg: parts[parts.length - 1],155 };156 } else {157 return {158 org: '',159 pkg: parts[0],160 };161 }162}163function isPluginModule(module: unknown): module is PluginModule {164 const pluginModule = module as Partial<PluginModule>;165 return Array.isArray(pluginModule.strykerPlugins);166}167function hasValidationSchemaContribution(module: unknown): module is SchemaValidationContribution {168 const pluginModule = module as Partial<SchemaValidationContribution>;169 return typeof pluginModule.strykerValidationSchema === 'object';...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const pluginsForKind = require('stryker-parent').pluginsForKind;2console.log(pluginsForKind('reporter'));3const pluginsForKind = require('stryker-api').pluginsForKind;4console.log(pluginsForKind('reporter'));5const pluginsForKind = require('stryker').pluginsForKind;6console.log(pluginsForKind('reporter'));7const pluginsForKind = require('stryker').pluginsForKind;8console.log(pluginsForKind('reporter'));9const pluginsForKind = require('stryker').pluginsForKind;10console.log(pluginsForKind('reporter'));11const pluginsForKind = require('stryker').pluginsForKind;12console.log(pluginsForKind('reporter'));13const pluginsForKind = require('stryker').pluginsForKind;14console.log(pluginsForKind('reporter'));15const pluginsForKind = require('stryker').pluginsForKind;16console.log(pluginsForKind('reporter'));17const pluginsForKind = require('stryker').pluginsForKind;18console.log(pluginsForKind('reporter'));19const pluginsForKind = require('stryker').pluginsForKind;20console.log(pluginsForKind('reporter'));21const pluginsForKind = require('stryker').pluginsForKind;22console.log(pluginsForKind('reporter'));23const pluginsForKind = require('stryker').pluginsForKind;24console.log(pluginsForKind('reporter

Full Screen

Using AI Code Generation

copy

Full Screen

1const pluginsForKind = require('stryker-parent').pluginsForKind;2const plugins = pluginsForKind('reporter');3console.log(plugins);4const plugins = require('stryker').pluginsForKind('reporter');5console.log(plugins);6module.exports = function(config) {7 config.set({8 });9};

Full Screen

Using AI Code Generation

copy

Full Screen

1const plugins_1 = require("stryker-parent/plugins");2const plugins = plugins_1.pluginsForKind('test-runner');3console.log(plugins);4import { pluginsForKind } from 'stryker-parent/plugins';5const plugins = pluginsForKind('test-runner');6console.log(plugins);7import { pluginsForKind } from 'stryker-parent/plugins';8const plugins = pluginsForKind('test-runner');9console.log(plugins);10import { pluginsForKind } from 'stryker-parent/plugins';11const plugins = pluginsForKind('test-runner');12console.log(plugins);13import { pluginsForKind } from 'stryker-parent/plugins';14const plugins = pluginsForKind('test-runner');15console.log(plugins);16import { pluginsForKind } from 'stryker-parent/plugins';17const plugins = pluginsForKind('test-runner');18console.log(plugins);19import { pluginsForKind } from 'stryker-parent/plugins';20const plugins = pluginsForKind('test-runner');21console.log(plugins);22import { pluginsForKind } from 'stryker-parent/plugins';23const plugins = pluginsForKind('test-runner');24console.log(plugins);25import { pluginsForKind } from 'stryker-parent/plugins';26const plugins = pluginsForKind('test-runner');27console.log(plugins);28import { pluginsForKind } from 'stryker-parent/plugins';29const plugins = pluginsForKind('test-runner');30console.log(plugins);31import { pluginsForKind } from 'stryker-parent/plugins';

Full Screen

Using AI Code Generation

copy

Full Screen

1var plugins_1 = require("stryker-api/plugins");2var plugins = plugins_1.PluginLoader.instance().pluginsForKind('reporter');3console.log(plugins);4var plugins_1 = require("stryker/src/plugins");5var plugins = plugins_1.PluginLoader.instance().pluginsForKind('reporter');6console.log(plugins);7var plugins_1 = require("stryker-api/plugins");8var plugins = plugins_1.PluginLoader.instance().pluginsForKind('reporter');9console.log(plugins);10var plugins_1 = require("stryker/src/plugins");11var plugins = plugins_1.PluginLoader.instance().pluginsForKind('reporter');12console.log(plugins);

Full Screen

Using AI Code Generation

copy

Full Screen

1var plugins = require('stryker').pluginsForKind('reporter');2var reporters = plugins.map(function (plugin) {3 return plugin.create();4});5console.log(reporters);6module.exports = function (config) {7 config.set({8 });9};

Full Screen

Using AI Code Generation

copy

Full Screen

1var stryker = require('stryker');2var plugins = stryker.pluginsForKind('reporter');3console.log(plugins);4var stryker = require('stryker');5var plugins = stryker.pluginsForKind('reporter');6console.log(plugins);7var stryker = require('stryker');8var plugins = stryker.pluginsForKind('reporter');9console.log(plugins);10var stryker = require('stryker');11var plugins = stryker.pluginsForKind('reporter');12console.log(plugins);13var stryker = require('stryker');14var plugins = stryker.pluginsForKind('reporter');15console.log(plugins);16var stryker = require('stryker');17var plugins = stryker.pluginsForKind('reporter');18console.log(plugins);19var stryker = require('stryker');20var plugins = stryker.pluginsForKind('reporter');21console.log(plugins);22var stryker = require('stryker');23var plugins = stryker.pluginsForKind('reporter');24console.log(plugins);

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2var path = require('path');3var stryker = require('stryker');4var plugins = stryker.pluginsForKind('reporter');5var pluginNames = Object.keys(plugins);6var pluginVersions = pluginNames.map(function (pluginName) {7 return pluginName + '@' + plugins[pluginName].version;8});9fs.writeFileSync(path.join(__dirname, 'plugins.txt'), pluginVersions.join('10'));

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