How to use metaSchemaBuilder method in stryker-parent

Best JavaScript code snippet using stryker-parent

1-prepare-executor.spec.ts

Source:1-prepare-executor.spec.ts Github

copy

Full Screen

1import path from 'path';2import sinon from 'sinon';3import { JSONSchema7 } from 'json-schema';4import { Injector } from 'typed-inject';5import { expect } from 'chai';6import { testInjector, factory } from '@stryker-mutator/test-helpers';7import { PartialStrykerOptions, LogLevel } from '@stryker-mutator/api/core';8import { BaseContext } from '@stryker-mutator/api/plugin';9import { MutantInstrumenterContext, PrepareExecutor } from '../../../src/process/index.js';10import { coreTokens, PluginLoader, LoadedPlugins } from '../../../src/di/index.js';11import { LogConfigurator, LoggingClientContext } from '../../../src/logging/index.js';12import { Project, ProjectReader } from '../../../src/fs/index.js';13import { TemporaryDirectory } from '../../../src/utils/temporary-directory.js';14import { ConfigError } from '../../../src/errors.js';15import { ConfigReader, OptionsValidator, MetaSchemaBuilder } from '../../../src/config/index.js';16import { BroadcastReporter, reporterPluginsFileUrl } from '../../../src/reporters/index.js';17import { UnexpectedExitHandler } from '../../../src/unexpected-exit-handler.js';18import { FileSystemTestDouble } from '../../helpers/file-system-test-double.js';19interface AllContext extends MutantInstrumenterContext {20 [coreTokens.validationSchema]: unknown;21 [coreTokens.optionsValidator]: OptionsValidator;22 [coreTokens.pluginsByKind]: PluginLoader;23}24describe(PrepareExecutor.name, () => {25 let cliOptions: PartialStrykerOptions;26 let configReaderMock: sinon.SinonStubbedInstance<ConfigReader>;27 let pluginLoaderMock: sinon.SinonStubbedInstance<PluginLoader>;28 let metaSchemaBuilderMock: sinon.SinonStubbedInstance<MetaSchemaBuilder>;29 let configureMainProcessStub: sinon.SinonStub;30 let optionsValidatorMock: sinon.SinonStubbedInstance<OptionsValidator>;31 let configureLoggingServerStub: sinon.SinonStub;32 let injectorMock: sinon.SinonStubbedInstance<Injector<AllContext>>;33 let projectReaderMock: sinon.SinonStubbedInstance<ProjectReader>;34 let project: Project;35 let temporaryDirectoryMock: sinon.SinonStubbedInstance<TemporaryDirectory>;36 let loadedPlugins: LoadedPlugins;37 let sut: PrepareExecutor;38 beforeEach(() => {39 const fsTestDouble = new FileSystemTestDouble({ 'index.js': 'console.log("hello world");' });40 project = new Project(fsTestDouble, fsTestDouble.toFileDescriptions());41 cliOptions = {};42 configReaderMock = sinon.createStubInstance(ConfigReader);43 configReaderMock.readConfig.resolves(testInjector.options);44 metaSchemaBuilderMock = sinon.createStubInstance(MetaSchemaBuilder);45 configureMainProcessStub = sinon.stub(LogConfigurator, 'configureMainProcess');46 pluginLoaderMock = sinon.createStubInstance(PluginLoader);47 loadedPlugins = { pluginModulePaths: [], pluginsByKind: new Map(), schemaContributions: [] };48 pluginLoaderMock.load.resolves(loadedPlugins);49 temporaryDirectoryMock = sinon.createStubInstance(TemporaryDirectory);50 projectReaderMock = sinon.createStubInstance(ProjectReader);51 optionsValidatorMock = sinon.createStubInstance(OptionsValidator);52 configureLoggingServerStub = sinon.stub(LogConfigurator, 'configureLoggingServer');53 injectorMock = factory.injector() as unknown as sinon.SinonStubbedInstance<Injector<AllContext>>;54 injectorMock.resolve.withArgs(coreTokens.temporaryDirectory).returns(temporaryDirectoryMock);55 injectorMock.injectClass56 .withArgs(PluginLoader)57 .returns(pluginLoaderMock)58 .withArgs(OptionsValidator)59 .returns(optionsValidatorMock)60 .withArgs(MetaSchemaBuilder)61 .returns(metaSchemaBuilderMock)62 .withArgs(ConfigReader)63 .returns(configReaderMock)64 .withArgs(ProjectReader)65 .returns(projectReaderMock);66 projectReaderMock.read.resolves(project);67 sut = new PrepareExecutor(injectorMock as Injector<BaseContext>);68 });69 it('should provide the cliOptions to the config reader', async () => {70 await sut.execute(cliOptions);71 expect(configReaderMock.readConfig).calledWithExactly(cliOptions);72 });73 it('should load the plugins', async () => {74 // Arrange75 testInjector.options.appendPlugins = ['appended'];76 testInjector.options.plugins = ['@stryker-mutator/*', './my-custom-plugin.js'];77 // Act78 await sut.execute(cliOptions);79 // Assert80 sinon.assert.calledWithExactly(pluginLoaderMock.load, ['@stryker-mutator/*', './my-custom-plugin.js', reporterPluginsFileUrl, 'appended']);81 });82 it('should provided the loaded modules as pluginModulePaths', async () => {83 // Arrange84 const expectedPluginPaths = ['@stryker-mutator/core', path.resolve('./my-custom-plugin.js'), 'appended'];85 loadedPlugins.pluginModulePaths.push(...expectedPluginPaths);86 // Act87 await sut.execute(cliOptions);88 // Assert89 sinon.assert.calledWithExactly(injectorMock.provideValue, coreTokens.pluginModulePaths, expectedPluginPaths);90 });91 it('should validate final options with the meta schema', async () => {92 // Arrange93 const contributions = [{ some: 'schema contributions' }];94 const metaSchema: JSONSchema7 = { properties: { meta: { $comment: 'schema' } } };95 loadedPlugins.schemaContributions.push(...contributions);96 metaSchemaBuilderMock.buildMetaSchema.returns(metaSchema);97 // Act98 await sut.execute(cliOptions);99 // Assert100 sinon.assert.calledWithExactly(metaSchemaBuilderMock.buildMetaSchema, contributions);101 sinon.assert.calledWithExactly(injectorMock.provideValue, coreTokens.validationSchema, metaSchema);102 sinon.assert.calledWithExactly(optionsValidatorMock.validate, testInjector.options, true);103 });104 it('should configure logging for the main process', async () => {105 await sut.execute(cliOptions);106 expect(configureMainProcessStub).calledOnce;107 });108 it('should configure the logging server', async () => {109 const expectedLoggingContext: LoggingClientContext = {110 level: LogLevel.Fatal,111 port: 1337,112 };113 configureLoggingServerStub.resolves(expectedLoggingContext);114 testInjector.options.logLevel = LogLevel.Information;115 testInjector.options.fileLogLevel = LogLevel.Trace;116 testInjector.options.allowConsoleColors = true;117 await sut.execute(cliOptions);118 expect(configureLoggingServerStub).calledWithExactly(LogLevel.Information, LogLevel.Trace, true);119 expect(injectorMock.provideValue).calledWithExactly(coreTokens.loggingContext, expectedLoggingContext);120 });121 it('should resolve input files', async () => {122 await sut.execute(cliOptions);123 expect(projectReaderMock.read).called;124 expect(injectorMock.provideValue).calledWithExactly(coreTokens.project, project);125 });126 it('should provide the reporter the reporter', async () => {127 await sut.execute(cliOptions);128 sinon.assert.calledWithExactly(injectorMock.provideClass, coreTokens.reporter, BroadcastReporter);129 });130 it('should provide the UnexpectedExitRegister', async () => {131 await sut.execute(cliOptions);132 sinon.assert.calledWithExactly(injectorMock.provideClass, coreTokens.unexpectedExitRegistry, UnexpectedExitHandler);133 });134 it('should reject when logging server rejects', async () => {135 const expectedError = Error('expected error');136 configureLoggingServerStub.rejects(expectedError);137 await expect(sut.execute(cliOptions)).rejectedWith(expectedError);138 });139 it('should reject when input file globbing results in a rejection', async () => {140 const expectedError = Error('expected error');141 projectReaderMock.read.rejects(expectedError);142 await expect(sut.execute(cliOptions)).rejectedWith(expectedError);143 });144 it('should reject when no input files where found', async () => {145 projectReaderMock.read.resolves(new Project(new FileSystemTestDouble(), {}));146 await expect(sut.execute(cliOptions)).rejectedWith(ConfigError, 'No input files found');147 });148 it('should not create the temp directory when no input files where found', async () => {149 projectReaderMock.read.resolves(new Project(new FileSystemTestDouble(), {}));150 await expect(sut.execute(cliOptions)).rejected;151 expect(temporaryDirectoryMock.initialize).not.called;152 });...

Full Screen

Full Screen

1-prepare-executor.ts

Source:1-prepare-executor.ts Github

copy

Full Screen

1import { StrykerOptions, PartialStrykerOptions, strykerCoreSchema } from '@stryker-mutator/api/core';2import { BaseContext, commonTokens, Injector, tokens } from '@stryker-mutator/api/plugin';3import { deepFreeze } from '@stryker-mutator/util';4import { execaCommand } from 'execa';5import { ConfigReader } from '../config/config-reader.js';6import { LogConfigurator } from '../logging/index.js';7import { coreTokens, PluginCreator } from '../di/index.js';8import { TemporaryDirectory } from '../utils/temporary-directory.js';9import { ConfigError } from '../errors.js';10import { PluginLoader } from '../di/plugin-loader.js';11import { reporterPluginsFileUrl } from '../reporters/index.js';12import { Timer } from '../utils/timer.js';13import { MetaSchemaBuilder, OptionsValidator } from '../config/index.js';14import { BroadcastReporter } from '../reporters/broadcast-reporter.js';15import { UnexpectedExitHandler } from '../unexpected-exit-handler.js';16import { FileSystem, ProjectReader } from '../fs/index.js';17import { MutantInstrumenterContext } from './index.js';18export class PrepareExecutor {19 public static readonly inject = tokens(commonTokens.injector);20 constructor(private readonly injector: Injector<BaseContext>) {}21 public async execute(cliOptions: PartialStrykerOptions): Promise<Injector<MutantInstrumenterContext>> {22 // greedy initialize, so the time starts immediately23 const timer = new Timer();24 // Already configure the logger, so next classes can use25 LogConfigurator.configureMainProcess(cliOptions.logLevel, cliOptions.fileLogLevel, cliOptions.allowConsoleColors);26 // Read the config file27 const configReaderInjector = this.injector28 .provideValue(coreTokens.validationSchema, strykerCoreSchema)29 .provideClass(coreTokens.optionsValidator, OptionsValidator);30 const configReader = configReaderInjector.injectClass(ConfigReader);31 const options: StrykerOptions = await configReader.readConfig(cliOptions);32 // Load plugins33 const pluginLoader = configReaderInjector.injectClass(PluginLoader);34 const pluginDescriptors = [...options.plugins, reporterPluginsFileUrl, ...options.appendPlugins];35 const loadedPlugins = await pluginLoader.load(pluginDescriptors);36 // Revalidate the options with plugin schema additions37 const metaSchemaBuilder = configReaderInjector.injectClass(MetaSchemaBuilder);38 const metaSchema = metaSchemaBuilder.buildMetaSchema(loadedPlugins.schemaContributions);39 const optionsValidatorInjector = configReaderInjector.provideValue(coreTokens.validationSchema, metaSchema);40 const validator: OptionsValidator = optionsValidatorInjector.injectClass(OptionsValidator);41 validator.validate(options, true);42 // Done reading config, deep freeze it so it won't change unexpectedly43 deepFreeze(options);44 // Final logging configuration, open the logging server45 const loggingContext = await LogConfigurator.configureLoggingServer(options.logLevel, options.fileLogLevel, options.allowConsoleColors);46 // Resolve input files47 const projectFileReaderInjector = optionsValidatorInjector48 .provideValue(commonTokens.options, options)49 .provideClass(coreTokens.temporaryDirectory, TemporaryDirectory)50 .provideClass(coreTokens.fs, FileSystem)51 .provideValue(coreTokens.pluginsByKind, loadedPlugins.pluginsByKind);52 const project = await projectFileReaderInjector.injectClass(ProjectReader).read();53 if (project.isEmpty) {54 throw new ConfigError('No input files found.');55 } else {56 // Done preparing, finish up and return57 await projectFileReaderInjector.resolve(coreTokens.temporaryDirectory).initialize();58 return projectFileReaderInjector59 .provideValue(coreTokens.project, project)60 .provideValue(commonTokens.fileDescriptions, project.fileDescriptions)61 .provideClass(coreTokens.pluginCreator, PluginCreator)62 .provideClass(coreTokens.reporter, BroadcastReporter)63 .provideValue(coreTokens.timer, timer)64 .provideValue(coreTokens.project, project)65 .provideValue(coreTokens.loggingContext, loggingContext)66 .provideValue(coreTokens.execa, execaCommand)67 .provideValue(coreTokens.process, process)68 .provideClass(coreTokens.unexpectedExitRegistry, UnexpectedExitHandler)69 .provideValue(coreTokens.pluginModulePaths, loadedPlugins.pluginModulePaths);70 }71 }...

Full Screen

Full Screen

meta-schema-builder.spec.ts

Source:meta-schema-builder.spec.ts Github

copy

Full Screen

1import type { JSONSchema7 } from 'json-schema';2import { expect } from 'chai';3import { deepFreeze } from '@stryker-mutator/util';4import { testInjector } from '@stryker-mutator/test-helpers';5import { MetaSchemaBuilder } from '../../../src/config/index.js';6import { coreTokens } from '../../../src/di/index.js';7describe(MetaSchemaBuilder.name, () => {8 it('should merge `properties`', () => {9 const input: JSONSchema7 = deepFreeze({ properties: { foo: { type: 'string' } } });10 const additionalSchema: JSONSchema7 = deepFreeze({ properties: { bar: { type: 'string' } } });11 const additionalSchema2: JSONSchema7 = deepFreeze({ properties: { baz: { type: 'number' } } });12 const sut = testInjector.injector.provideValue(coreTokens.validationSchema, input).injectClass(MetaSchemaBuilder);13 const actual = sut.buildMetaSchema([additionalSchema, additionalSchema2] as Array<Record<string, unknown>>);14 expect(actual).deep.eq({ definitions: {}, properties: { ...input.properties, ...additionalSchema.properties, ...additionalSchema2.properties } });15 });16 it('should merge `definitions`', () => {17 const input: JSONSchema7 = deepFreeze({ definitions: { foo: { type: 'string' } } });18 const additionalSchema: JSONSchema7 = deepFreeze({ definitions: { bar: { type: 'string' } } });19 const additionalSchema2: JSONSchema7 = deepFreeze({ definitions: { baz: { type: 'number' } } });20 const sut = testInjector.injector.provideValue(coreTokens.validationSchema, input).injectClass(MetaSchemaBuilder);21 const actual = sut.buildMetaSchema([additionalSchema, additionalSchema2] as Array<Record<string, unknown>>);22 expect(actual).deep.eq({23 properties: {},24 definitions: { ...input.definitions, ...additionalSchema.definitions, ...additionalSchema2.definitions },25 });26 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const metaSchemaBuilder = require('stryker-parent').metaSchemaBuilder;2const metaSchemaBuilder = require('stryker-parent').metaSchemaBuilder;3const schema = metaSchemaBuilder('stryker-mocha-runner', {4 properties: {5 mochaOptions: {6 default: {}7 }8 }9});10module.exports = schema;11const testSchema = require('./test.js');12const strykerCoreSchema = require('stryker-parent').schema;13module.exports = strykerCoreSchema.merge(testSchema);14const schema = require('stryker-parent').schema;15const mergedSchema = schema.merge(require('./test.js'));16const config = {17 mochaOptions: {18 }19};20const result = mergedSchema.validate(config);21if (result.error) {22 throw new Error(result.error);23}24const mochaOptions = result.value.mochaOptions;

Full Screen

Using AI Code Generation

copy

Full Screen

1var metaSchemaBuilder = require('stryker-parent').metaSchemaBuilder;2var metaSchema = metaSchemaBuilder('testSchema');3var metaSchemaBuilder = require('stryker').metaSchemaBuilder;4var metaSchema = metaSchemaBuilder('testSchema');5var metaSchemaBuilder = require('stryker-api').metaSchemaBuilder;6var metaSchema = metaSchemaBuilder('testSchema');

Full Screen

Using AI Code Generation

copy

Full Screen

1var metaSchemaBuilder = require('stryker-parent').metaSchemaBuilder;2var metaSchema = metaSchemaBuilder('testSchema');3console.log(metaSchema);4module.exports = {5 properties: {6 name: {7 }8 }9};10{11 properties: {12 name: {13 }14 }15}16module.exports = {17 properties: {18 name: {19 }20 }21};22{23 properties: {24 name: {25 }26 },27}28module.exports = {29 properties: {30 name: {31 }32 }33};34{35 properties: {36 name: {37 }38 },39}40module.exports = {41 properties: {42 name: {43 }44 }45};46{47 properties: {48 name: {49 }50 },51}52module.exports = {53 properties: {54 name: {55 }56 }57};58{59 properties: {60 name: {61 }62 },

Full Screen

Using AI Code Generation

copy

Full Screen

1var metaSchema = metaSchemaBuilder(__filename);2var metaSchema = metaSchemaBuilder(__filename);3var metaSchema = metaSchemaBuilder(__filename);4var metaSchema = metaSchemaBuilder(__filename);5var metaSchema = metaSchemaBuilder(__filename);6var metaSchema = metaSchemaBuilder(__filename);7var metaSchema = metaSchemaBuilder(__filename);8var metaSchema = metaSchemaBuilder(__filename);

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