How to use stubFileSystem method in stryker-parent

Best JavaScript code snippet using stryker-parent

input-file-resolver.spec.ts

Source:input-file-resolver.spec.ts Github

copy

Full Screen

...19 readdirStub = sinon.stub(fsPromises, 'readdir');20 readFileStub = sinon.stub(fsPromises, 'readFile');21 });22 it('should log a warning if no files were resolved', async () => {23 stubFileSystem({}); // emtpy dir24 const sut = createSut();25 await sut.resolve();26 expect(testInjector.logger.warn).calledWith(27 `No files found in directory ${process.cwd()} using ignore rules: ["node_modules",".git","/reports","*.tsbuildinfo","/stryker.log",".stryker-tmp"]. Make sure you run Stryker from the root directory of your project with the correct "ignorePatterns".`28 );29 });30 describe('file resolving', () => {31 it('should discover files recursively using readdir', async () => {32 // Arrange33 stubFileSystem({34 app: {35 'app.component.js': '@Component()',36 },37 util: {38 'index.js': 'foo.bar',39 object: {40 'object-helper.js': 'export const helpers = {}',41 },42 },43 });44 const sut = createSut();45 // Act46 const result = await sut.resolve();47 assertions.expectTextFilesEqual(result.files, [48 new File(path.resolve('app', 'app.component.js'), '@Component()'),49 new File(path.resolve('util', 'index.js'), 'foo.bar'),50 new File(path.resolve('util', 'object', 'object-helper.js'), 'export const helpers = {}'),51 ]);52 expect(readdirStub).calledWith(process.cwd(), { withFileTypes: true });53 });54 it('should respect ignore patterns', async () => {55 stubFileSystem({56 src: { 'index.js': 'export * from "./app"' },57 dist: { 'index.js': 'module.exports = require("./app")' },58 });59 testInjector.options.ignorePatterns = ['dist'];60 const sut = createSut();61 const result = await sut.resolve();62 assertions.expectTextFilesEqual(result.files, [new File(path.resolve('src', 'index.js'), 'export * from "./app"')]);63 });64 it('should respect deep ignore patterns', async () => {65 stubFileSystem({66 packages: {67 app: {68 src: { 'index.js': 'export * from "./app"' },69 dist: { 'index.js': 'module.exports = require("./app")' },70 },71 },72 });73 testInjector.options.ignorePatterns = ['/packages/*/dist'];74 const sut = createSut();75 const { files } = await sut.resolve();76 expect(files).lengthOf(1);77 expect(files[0].name).eq(path.resolve('packages', 'app', 'src', 'index.js'));78 });79 it('should ignore node_modules, .git, reports, stryker.log, *.tsbuildinfo and .stryker-tmp by default', async () => {80 // Arrange81 stubFileSystem({82 '.git': { config: '' },83 node_modules: { rimraf: { 'index.js': '' } },84 '.stryker-tmp': { 'stryker-sandbox-123': { src: { 'index.js': '' } } },85 'index.js': '',86 'stryker.log': '',87 'tsconfig.src.tsbuildinfo': '',88 dist: {89 'tsconfig.tsbuildinfo': '',90 },91 reports: { mutation: { 'mutation.json': '' } },92 });93 const sut = createSut();94 // Act95 const { files } = await sut.resolve();96 // Assert97 expect(files).lengthOf(1);98 expect(files[0].name).eq(path.resolve('index.js'));99 });100 it('should not ignore deep report directories by default', async () => {101 // Arrange102 stubFileSystem({103 app: { reports: { 'reporter.component.js': '' } },104 });105 const sut = createSut();106 // Act107 const { files } = await sut.resolve();108 // Assert109 expect(files).lengthOf(1);110 expect(files[0].name).eq(path.resolve('app', 'reports', 'reporter.component.js'));111 });112 it('should ignore a deep node_modules directory by default', async () => {113 // Arrange114 stubFileSystem({115 testResources: { 'require-resolve': { node_modules: { bar: { 'index.js': '' } } } },116 });117 const sut = createSut();118 // Act119 const { files } = await sut.resolve();120 // Assert121 expect(files).lengthOf(0);122 });123 it('should ignore an alternative stryker-tmp dir', async () => {124 // Arrange125 stubFileSystem({126 '.git': { config: '' },127 node_modules: { rimraf: { 'index.js': '' } },128 'stryker-tmp': { 'stryker-sandbox-123': { src: { 'index.js': '' } } },129 'index.js': '',130 });131 testInjector.options.tempDirName = 'stryker-tmp';132 const sut = createSut();133 // Act134 const { files } = await sut.resolve();135 // Assert136 expect(files).lengthOf(1);137 expect(files[0].name).eq(path.resolve('index.js'));138 });139 it('should allow un-ignore', async () => {140 // Arrange141 stubFileSystem({142 '.git': { config: '' },143 node_modules: { rimraf: { 'index.js': '' } },144 '.stryker-tmp': { 'stryker-sandbox-123': { src: { 'index.js': '' } } },145 'index.js': '',146 });147 testInjector.options.ignorePatterns = ['!node_modules'];148 const sut = createSut();149 // Act150 const { files } = await sut.resolve();151 // Assert152 expect(files).lengthOf(2);153 expect(files[0].name).eq(path.resolve('index.js'));154 expect(files[1].name).eq(path.resolve('node_modules', 'rimraf', 'index.js'));155 });156 it('should allow un-ignore deep node_modules directory', async () => {157 // Arrange158 stubFileSystem({159 node_modules: { rimraf: { 'index.js': '' } },160 testResources: { 'require-resolve': { node_modules: { bar: { 'index.js': '' } } } },161 });162 testInjector.options.ignorePatterns = ['!testResources/**/node_modules'];163 const sut = createSut();164 // Act165 const { files } = await sut.resolve();166 // Assert167 expect(files).lengthOf(1);168 expect(files[0].name).eq(path.resolve('testResources', 'require-resolve', 'node_modules', 'bar', 'index.js'));169 });170 it('should reject if fs commands fail', async () => {171 const expectedError = factory.fileNotFoundError();172 readdirStub.rejects(expectedError);173 await expect(createSut().resolve()).rejectedWith(expectedError);174 });175 it('should allow whitelisting with "**"', async () => {176 stubFileSystem({177 src: { 'index.js': 'export * from "./app"' },178 dist: { 'index.js': 'module.exports = require("./app")' },179 });180 testInjector.options.ignorePatterns = ['**', '!src/**/*.js'];181 const sut = createSut();182 const { files } = await sut.resolve();183 assertions.expectTextFilesEqual(files, [new File(path.resolve('src', 'index.js'), 'export * from "./app"')]);184 });185 it('should allow deep whitelisting with "**"', async () => {186 stubFileSystem({187 app: {188 src: { 'index.js': 'export * from "./app"' },189 },190 dist: { 'index.js': 'module.exports = require("./app")' },191 });192 testInjector.options.ignorePatterns = ['**', '!app/src/index.js'];193 const sut = createSut();194 const { files } = await sut.resolve();195 assertions.expectTextFilesEqual(files, [new File(path.resolve('app', 'src', 'index.js'), 'export * from "./app"')]);196 });197 it('should not open too many file handles', async () => {198 // Arrange199 const maxFileIO = 256;200 const sut = createSut();201 const fileHandles: Array<{ fileName: string; task: Task<Buffer> }> = [];202 for (let i = 0; i < maxFileIO + 1; i++) {203 const fileName = `file_${i}.js`;204 const readFileTask = new Task<Buffer>();205 fileHandles.push({ fileName, task: readFileTask });206 readFileStub.withArgs(sinon.match(fileName)).returns(readFileTask.promise);207 }208 readdirStub.withArgs(process.cwd(), sinon.match.object).resolves(fileHandles.map(({ fileName }) => createDirent(fileName, false)));209 // Act210 const onGoingWork = sut.resolve();211 await tick();212 expect(readFileStub).callCount(maxFileIO);213 fileHandles[0].task.resolve(Buffer.from('content'));214 await tick();215 // Assert216 expect(readFileStub).callCount(maxFileIO + 1);217 fileHandles.forEach(({ task }) => task.resolve(Buffer.from('content')));218 await onGoingWork;219 });220 });221 describe('without mutate files', () => {222 beforeEach(() => {223 stubFileSystem({224 'file1.js': 'file 1 content',225 'file2.js': 'file 2 content',226 'file3.js': 'file 3 content',227 'mute1.js': 'mutate 1 content',228 'mute2.js': 'mutate 2 content',229 });230 });231 it('should warn about dry-run', async () => {232 const sut = createSut();233 await sut.resolve();234 expect(testInjector.logger.warn).calledWith(235 'No files marked to be mutated, Stryker will perform a dry-run without actually mutating anything. You can configure the `mutate` property in your config file (or use `--mutate` via command line).'236 );237 });238 });239 function stubFileSystemWith5Files() {240 stubFileSystem({241 'file1.js': 'file 1 content',242 'file2.js': 'file 2 content',243 'file3.js': 'file 3 content',244 'mute1.js': 'mutate 1 content',245 'mute2.js': 'mutate 2 content',246 });247 }248 describe('with mutation range definitions', () => {249 beforeEach(() => {250 stubFileSystem({251 'file1.js': 'file 1 content',252 'file2.js': 'file 2 content',253 'file3.js': 'file 3 content',254 'mute1.js': 'mutate 1 content',255 'mute2.js': 'mutate 2 content',256 });257 });258 it('should remove specific mutant descriptors when matching with line and column', async () => {259 testInjector.options.mutate = ['mute1.js:1:2-2:2'];260 testInjector.options.files = ['file1', 'mute1', 'file2', 'mute2', 'file3'];261 const sut = createSut();262 const result = await sut.resolve();263 expect(result.filesToMutate.map((_) => _.name)).to.deep.equal([path.resolve('mute1.js')]);264 });265 it('should parse the mutation range', async () => {266 testInjector.options.mutate = ['mute1:1:2-2:2'];267 testInjector.options.files = ['file1', 'mute1', 'file2', 'mute2', 'file3'];268 const sut = createSut();269 const result = await sut.resolve();270 const expectedRanges: MutationRange[] = [271 {272 start: {273 column: 2,274 line: 0, // internally, Stryker works 0-based275 },276 end: {277 column: 2,278 line: 1,279 },280 fileName: path.resolve('mute1'),281 },282 ];283 expect(result.mutationRanges).deep.eq(expectedRanges);284 });285 it('should default column numbers if not present', async () => {286 testInjector.options.mutate = ['mute1:6-12'];287 testInjector.options.files = ['file1', 'mute1', 'file2', 'mute2', 'file3'];288 const sut = createSut();289 const result = await sut.resolve();290 expect(result.mutationRanges[0].start).deep.eq({ column: 0, line: 5 });291 expect(result.mutationRanges[0].end).deep.eq({ column: Number.MAX_SAFE_INTEGER, line: 11 });292 });293 });294 describe('with mutate file patterns', () => {295 it('should result in the expected mutate files', async () => {296 stubFileSystemWith5Files();297 testInjector.options.mutate = ['mute*'];298 const sut = createSut();299 const result = await sut.resolve();300 expect(result.filesToMutate.map((_) => _.name)).to.deep.equal([path.resolve('mute1.js'), path.resolve('mute2.js')]);301 expect(result.files.map((file) => file.name)).to.deep.equal([302 path.resolve('file1.js'),303 path.resolve('file2.js'),304 path.resolve('file3.js'),305 path.resolve('mute1.js'),306 path.resolve('mute2.js'),307 ]);308 });309 it('should only report a mutate file when it is included in the resolved files', async () => {310 stubFileSystemWith5Files();311 testInjector.options.mutate = ['mute*'];312 testInjector.options.ignorePatterns = ['mute2.js'];313 const sut = createSut();314 const result = await sut.resolve();315 expect(result.filesToMutate.map((_) => _.name)).to.deep.equal([path.resolve('mute1.js')]);316 });317 it('should report OnAllSourceFilesRead', async () => {318 stubFileSystemWith5Files();319 testInjector.options.mutate = ['mute*'];320 const sut = createSut();321 await sut.resolve();322 const expected: SourceFile[] = [323 { path: path.resolve('file1.js'), content: 'file 1 content' },324 { path: path.resolve('file2.js'), content: 'file 2 content' },325 { path: path.resolve('file3.js'), content: 'file 3 content' },326 { path: path.resolve('mute1.js'), content: 'mutate 1 content' },327 { path: path.resolve('mute2.js'), content: 'mutate 2 content' },328 ];329 expect(reporterMock.onAllSourceFilesRead).calledWith(expected);330 });331 it('should report OnSourceFileRead', async () => {332 stubFileSystemWith5Files();333 testInjector.options.mutate = ['mute*'];334 const sut = createSut();335 await sut.resolve();336 const expected: SourceFile[] = [337 { path: path.resolve('file1.js'), content: 'file 1 content' },338 { path: path.resolve('file2.js'), content: 'file 2 content' },339 { path: path.resolve('file3.js'), content: 'file 3 content' },340 { path: path.resolve('mute1.js'), content: 'mutate 1 content' },341 { path: path.resolve('mute2.js'), content: 'mutate 2 content' },342 ];343 expected.forEach((sourceFile) => expect(reporterMock.onSourceFileRead).calledWith(sourceFile));344 });345 it('should warn about useless patterns custom "mutate" patterns', async () => {346 testInjector.options.mutate = ['src/**/*.js', '!src/index.js', 'types/global.d.ts'];347 stubFileSystem({348 src: {349 'foo.js': 'foo();',350 },351 });352 const sut = createSut();353 await sut.resolve();354 expect(testInjector.logger.warn).calledTwice;355 expect(testInjector.logger.warn).calledWith('Glob pattern "!src/index.js" did not exclude any files.');356 expect(testInjector.logger.warn).calledWith('Glob pattern "types/global.d.ts" did not result in any files.');357 });358 it('should not warn about useless patterns if "mutate" isn\'t overridden', async () => {359 stubFileSystem({360 src: {361 'foo.js': 'foo();',362 },363 });364 const sut = createSut();365 await sut.resolve();366 expect(testInjector.logger.warn).not.called;367 });368 });369 function createSut() {370 return testInjector.injector.provideValue(coreTokens.reporter, reporterMock).injectClass(InputFileResolver);371 }372 // eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style373 type DirectoryEntry = string | { [name: string]: DirectoryEntry };374 function stubFileSystem(dirEntry: DirectoryEntry, fullName = process.cwd()) {375 if (typeof dirEntry === 'string') {376 readFileStub.withArgs(fullName).resolves(Buffer.from(dirEntry));377 } else {378 readdirStub379 .withArgs(fullName, sinon.match.object)380 .resolves(Object.entries(dirEntry).map(([name, value]) => createDirent(name, typeof value !== 'string')));381 Object.entries(dirEntry).map(([name, value]) => stubFileSystem(value, path.resolve(fullName, name)));382 }383 }384 function createDirent(name: string, isDirectory: boolean): Dirent {385 const dummy = () => true;386 return {387 isBlockDevice: dummy,388 isCharacterDevice: dummy,389 isDirectory: () => isDirectory,390 isFIFO: dummy,391 isFile: () => !isDirectory,392 isSocket: dummy,393 isSymbolicLink: dummy,394 name,395 };...

Full Screen

Full Screen

render_tag_test.js

Source:render_tag_test.js Github

copy

Full Screen

1'use strict';2const assert = require('assert').strict;3const Dry = require('../../..');4const { Template } = Dry;5const {6 assert_raises,7 assert_template_result,8 StubFileSystem9} = require('../../test_helpers');10class TestEnumerable extends Dry.Drop {11 async each(block) {12 const array = [{ foo: 1, bar: 2 }, { foo: 2, bar: 1 }, { foo: 3, bar: 3 }];13 for (let index = 0; index < array.length; index++) {14 await block(array[index], index);15 }16 }17}18describe('render_tag_test', () => {19 it('test_render_with_no_arguments', async () => {20 Dry.Template.file_system = new StubFileSystem({ source: 'rendered content' });21 await assert_template_result('rendered content', '{% render "source" %}');22 });23 it('test_render_tag_looks_for_file_system_in_registers_first', async () => {24 const file_system = new StubFileSystem({ pick_a_source: 'from register file system' });25 assert.equal('from register file system',26 await Template.parse('{% render "pick_a_source" %}').render_strict({}, { registers: { file_system } }));27 });28 it('test_render_passes_named_arguments_into_inner_scope', async () => {29 Dry.Template.file_system = new StubFileSystem({ product: '{{ inner_product.title }}' });30 await assert_template_result('My Product', '{% render "product", inner_product: outer_product %}',31 { outer_product: { title: 'My Product' } });32 });33 it('test_render_accepts_literals_as_arguments', async () => {34 Dry.Template.file_system = new StubFileSystem({ snippet: '{{ price }}' });35 await assert_template_result('123', '{% render "snippet", price: 123 %}');36 });37 it('test_render_accepts_multiple_named_arguments', async () => {38 Dry.Template.file_system = new StubFileSystem({ snippet: '{{ one }} {{ two }}' });39 await assert_template_result('1 2', '{% render "snippet", one: 1, two: 2 %}');40 });41 it('test_render_does_not_inherit_parent_scope_variables', async () => {42 Dry.Template.file_system = new StubFileSystem({ snippet: '{{ outer_variable }}' });43 await assert_template_result('', '{% assign outer_variable = "should not be visible" %}{% render "snippet" %}');44 });45 it('test_render_does_not_inherit_variable_with_same_name_as_snippet', async () => {46 Dry.Template.file_system = new StubFileSystem({ snippet: '{{ snippet }}' });47 await assert_template_result('', "{% assign snippet = 'should not be visible' %}{% render 'snippet' %}");48 });49 it('test_render_does_not_mutate_parent_scope', async () => {50 Dry.Template.file_system = new StubFileSystem({ snippet: '{% assign inner = 1 %}' });51 await assert_template_result('', "{% render 'snippet' %}{{ inner }}");52 });53 it('test_nested_render_tag', async () => {54 Dry.Template.file_system = new StubFileSystem({55 one: "one {% render 'two' %}",56 two: 'two'57 });58 await assert_template_result('one two', "{% render 'one' %}");59 });60 it('test_recursively_rendered_template_does_not_produce_endless_loop', async () => {61 Dry.Template.file_system = new StubFileSystem({ loop: '{% render "loop" %}' });62 assert_raises(Dry.StackLevelError, () => {63 Template.parse('{% render "loop" %}').render_strict();64 });65 });66 it('test_sub_contexts_count_towards_the_same_recursion_limit', async () => {67 Dry.Template.file_system = new StubFileSystem({68 loop_render: '{% render "loop_render" %}'69 });70 assert_raises(Dry.StackLevelError, () => {71 Template.parse('{% render "loop_render" %}').render_strict();72 });73 });74 it('test_dynamically_choosen_templates_are_not_allowed', async () => {75 Dry.Template.file_system = new StubFileSystem({ snippet: 'should not be rendered' });76 await assert_raises(Dry.SyntaxError, () => {77 return Dry.Template.parse("{% assign name = 'snippet' %}{% render name %}");78 });79 });80 it('test_include_tag_caches_second_read_of_same_partial', async () => {81 const file_system = new StubFileSystem({ snippet: 'echo' });82 assert.equal('echoecho',83 await Template.parse('{% render "snippet" %}{% render "snippet" %}')84 .render_strict({}, { registers: { file_system } }));85 assert.equal(1, file_system.file_read_count);86 });87 it('test_render_tag_doesnt_cache_partials_across_renders', async () => {88 const file_system = new StubFileSystem({ snippet: 'my message' });89 assert.equal('my message',90 await Template.parse('{% include "snippet" %}').render_strict({}, { registers: { file_system } }));91 assert.equal(1, file_system.file_read_count);92 assert.equal('my message',93 await Template.parse('{% include "snippet" %}').render_strict({}, { registers: { file_system } }));94 assert.equal(2, file_system.file_read_count);95 });96 it('test_render_tag_within_if_statement', async () => {97 Dry.Template.file_system = new StubFileSystem({ snippet: 'my message' });98 await assert_template_result('my message', '{% if true %}{% render "snippet" %}{% endif %}');99 });100 it('test_break_through_render', async () => {101 Dry.Template.file_system = new StubFileSystem({ break: '{% break %}' });102 await assert_template_result('1', '{% for i in (1..3) %}{{ i }}{% break %}{{ i }}{% endfor %}');103 await assert_template_result('112233', '{% for i in (1..3) %}{{ i }}{% render "break" %}{{ i }}{% endfor %}');104 });105 it('test_increment_is_isolated_between_renders', async () => {106 Dry.Template.file_system = new StubFileSystem({ incr: '{% increment %}' });107 await assert_template_result('010', '{% increment %}{% increment %}{% render "incr" %}');108 });109 it('test_decrement_is_isolated_between_renders', async () => {110 Dry.Template.file_system = new StubFileSystem({ decr: '{% decrement %}' });111 await assert_template_result('-1-2-1', '{% decrement %}{% decrement %}{% render "decr" %}');112 });113 it('test_includes_will_not_render_inside_render_tag', async () => {114 Dry.Template.file_system = new StubFileSystem({115 foo: 'bar',116 test_include: '{% include "foo" %}'117 });118 const exc = await assert_raises(Dry.DisabledError, () => {119 return Dry.Template.parse('{% render "test_include" %}').render_strict();120 });121 assert.equal('Dry error: include usage is not allowed in this context', exc.message);122 });123 it('test_includes_will_not_render_inside_nested_sibling_tags', async () => {124 Dry.Template.file_system = new StubFileSystem({125 foo: 'bar',126 nested_render_with_sibling_include: '{% render "test_include" %}{% include "foo" %}',127 test_include: '{% include "foo" %}'128 });129 const output = await Dry.Template.parse('{% render "nested_render_with_sibling_include" %}').render();130 assert.match(output, /include usage is not allowed in this context/);131 });132 it('test_render_tag_with', async () => {133 Dry.Template.file_system = new StubFileSystem({134 product: 'Product: {{ product.title }} ',135 product_alias: 'Product: {{ product.title }} '136 });137 await assert_template_result('Product: Draft 151cm ',138 "{% render 'product' with products[0] %}", { products: [{ title: 'Draft 151cm' }, { title: 'Element 155cm' }] });139 });140 it('test_render_tag_with_alias', async () => {141 Dry.Template.file_system = new StubFileSystem({142 product: 'Product: {{ product.title }} ',143 product_alias: 'Product: {{ product.title }} '144 });145 await assert_template_result('Product: Draft 151cm ',146 "{% render 'product_alias' with products[0] as product %}", { products: [{ title: 'Draft 151cm' }, { title: 'Element 155cm' }] });147 });148 it('test_render_tag_for_alias', async () => {149 Dry.Template.file_system = new StubFileSystem({150 product: 'Product: {{ product.title }} ',151 product_alias: 'Product: {{ product.title }} '152 });153 await assert_template_result('Product: Draft 151cm Product: Element 155cm ',154 "{% render 'product_alias' for products as product %}", { products: [{ title: 'Draft 151cm' }, { title: 'Element 155cm' }] });155 });156 it('test_render_tag_for', async () => {157 Dry.Template.file_system = new StubFileSystem({158 product: 'Product: {{ product.title }} ',159 product_alias: 'Product: {{ product.title }} '160 });161 await assert_template_result('Product: Draft 151cm Product: Element 155cm ',162 "{% render 'product' for products %}", { products: [{ title: 'Draft 151cm' }, { title: 'Element 155cm' }] });163 });164 it('test_render_tag_forloop', async () => {165 Dry.Template.file_system = new StubFileSystem({166 product: 'Product: {{ product.title }} {% if forloop.first %}first{% endif %} {% if forloop.last %}last{% endif %} index:{{ forloop.index }} '167 });168 await assert_template_result('Product: Draft 151cm first index:1 Product: Element 155cm last index:2 ',169 "{% render 'product' for products %}", { products: [{ title: 'Draft 151cm' }, { title: 'Element 155cm' }] });170 });171 it('test_render_tag_for_drop', async () => {172 Dry.Template.file_system = new StubFileSystem({173 loop: '{{ value.foo }}'174 });175 await assert_template_result('123',176 "{% render 'loop' for loop as value %}", { loop: new TestEnumerable() });177 });178 it('test_render_tag_with_drop', async () => {179 Dry.Template.file_system = new StubFileSystem({180 loop: '{{ value }}'181 });182 await assert_template_result('TestEnumerable',183 "{% render 'loop' with loop as value %}", { loop: new TestEnumerable() });184 });...

Full Screen

Full Screen

Projection.test.ts

Source:Projection.test.ts Github

copy

Full Screen

1import { strictEqual as eq, rejects } from "assert";2import { describe, it } from "zunit";3import { object, array, string } from "yup";4import { TemporalRecordType } from "../src";5import LocalDataSource from "../src/datasources/LocalDataSource";6import StubProjection from "./stubs/StubProjection";7import StubFileSystem from "./stubs/StubFileSystem";8export default describe("Projection", () => {9 it("should generate temporal records", async () => {10 const fileSystem = new StubFileSystem(STAFF_DATA, SCHEMAS);11 const dataSource = new LocalDataSource("staff", { fileSystem });12 const projection = new StubProjection("1.0.0", dataSource, fileSystem);13 const records = await projection.generate();14 eq(records.length, 2);15 eq(records[0].data.length, 2);16 eq(records[0].data[0].fullName, "John Wayne");17 eq(records[0].data[1].fullName, "John Paul Sartre");18 eq(records[1].data.length, 2);19 eq(records[1].data[0].fullName, "Marrion Robert Morrison");20 eq(records[1].data[1].fullName, "John Paul Sartre");21 });22 it("should validate projections@major using matching schema version", async () => {23 const schemas = [24 {25 version: "1.0.0",26 schema: array().test(() => false),27 },28 ];29 const fileSystem = new StubFileSystem(STAFF_DATA, schemas);30 const dataSource = new LocalDataSource("staff", { fileSystem });31 const projection = new StubProjection("1.0.0", dataSource, fileSystem);32 await rejects(33 () => projection.generate(),34 (err: Error) => {35 eq(err.constructor.name, "ValidationError");36 return true;37 }38 );39 });40 it("should validate projections@major using compatible patch schema", async () => {41 const schemas = [42 {43 version: "1.0.1",44 schema: array().test(() => false),45 },46 ];47 const fileSystem = new StubFileSystem(STAFF_DATA, schemas);48 const dataSource = new LocalDataSource("staff", { fileSystem });49 const projection = new StubProjection("1.0.0", dataSource, fileSystem);50 await rejects(51 () => projection.generate(),52 (err: Error) => {53 eq(err.constructor.name, "ValidationError");54 return true;55 }56 );57 });58 it("should validate projections@major using compatible minor schema", async () => {59 const schemas = [60 {61 version: "1.0.0",62 schema: array(),63 },64 {65 version: "1.1.0",66 schema: array().test(() => false),67 },68 ];69 const fileSystem = new StubFileSystem(STAFF_DATA, schemas);70 const dataSource = new LocalDataSource("staff", { fileSystem });71 const projection = new StubProjection("1.0.0", dataSource, fileSystem);72 await rejects(73 () => projection.generate(),74 (err: Error) => {75 eq(err.constructor.name, "ValidationError");76 return true;77 }78 );79 });80 it("should validate projections@minor using matching schema version", async () => {81 const schemas = [82 {83 version: "0.1.0",84 schema: array().test(() => false),85 },86 ];87 const fileSystem = new StubFileSystem(STAFF_DATA, schemas);88 const dataSource = new LocalDataSource("staff", { fileSystem });89 const projection = new StubProjection("0.1.0", dataSource, fileSystem);90 await rejects(91 () => projection.generate(),92 (err: Error) => {93 eq(err.constructor.name, "ValidationError");94 return true;95 }96 );97 });98 it("should validate projections@minor using compatible patch schema", async () => {99 const schemas = [100 {101 version: "0.1.1",102 schema: array().test(() => false),103 },104 ];105 const fileSystem = new StubFileSystem(STAFF_DATA, schemas);106 const dataSource = new LocalDataSource("staff", { fileSystem });107 const projection = new StubProjection("0.1.0", dataSource, fileSystem);108 await rejects(109 () => projection.generate(),110 (err: Error) => {111 eq(err.constructor.name, "ValidationError");112 return true;113 }114 );115 });116 it("should validate projections@patch using matching schema version", async () => {117 const schemas = [118 {119 version: "0.0.1",120 schema: array().test(() => false),121 },122 ];123 const fileSystem = new StubFileSystem(STAFF_DATA, schemas);124 const dataSource = new LocalDataSource("staff", { fileSystem });125 const projection = new StubProjection("0.0.1", dataSource, fileSystem);126 await rejects(127 () => projection.generate(),128 (err: Error) => {129 eq(err.constructor.name, "ValidationError");130 return true;131 }132 );133 });134 it("should ignore incompatible schemas for projections@major", async () => {135 const schemas = [136 {137 version: "2.0.0",138 schema: array(),139 },140 {141 version: "1.0.0",142 schema: array().test(() => false),143 },144 {145 version: "3.0.0",146 schema: array().test(() => false),147 },148 ];149 const fileSystem = new StubFileSystem(STAFF_DATA, schemas);150 const dataSource = new LocalDataSource("staff", { fileSystem });151 const projection = new StubProjection("2.0.0", dataSource, fileSystem);152 await projection.generate();153 });154 it("should ignore incompatible schemas for projections@minor", async () => {155 const schemas = [156 {157 version: "0.2.0",158 schema: array(),159 },160 {161 version: "0.3.0",162 schema: array().test(() => false),163 },164 {165 version: "0.1.0",166 schema: array().test(() => false),167 },168 {169 version: "0.0.1",170 schema: array().test(() => false),171 },172 {173 version: "1.2.0",174 schema: array().test(() => false),175 },176 ];177 const fileSystem = new StubFileSystem(STAFF_DATA, schemas);178 const dataSource = new LocalDataSource("staff", { fileSystem });179 const projection = new StubProjection("0.2.0", dataSource, fileSystem);180 await projection.generate();181 });182 it("should ignore incompatible schemas for projections@patch", async () => {183 const schemas = [184 {185 version: "0.0.2",186 schema: array(),187 },188 {189 version: "0.0.3",190 schema: array().test(() => false),191 },192 {193 version: "0.0.1",194 schema: array().test(() => false),195 },196 ];197 const fileSystem = new StubFileSystem(STAFF_DATA, schemas);198 const dataSource = new LocalDataSource("staff", { fileSystem });199 const projection = new StubProjection("0.0.2", dataSource, fileSystem);200 await projection.generate();201 });202 it("should error when projection@major has no current schema", async () => {203 const schemas = [204 {205 version: "2.2.0",206 schema: array(),207 },208 {209 version: "2.0.0",210 schema: array(),211 },212 ];213 const fileSystem = new StubFileSystem(STAFF_DATA, schemas);214 const dataSource = new LocalDataSource("staff", { fileSystem });215 const projection = new StubProjection("2.1.0", dataSource, fileSystem);216 await rejects(217 () => projection.generate(),218 (err: Error) => {219 eq(err.message, "Projection staff-full-names@2.1.0 has no current schema");220 return true;221 }222 );223 });224 it("should error when projection@minor has no current schema", async () => {225 const schemas = [226 {227 version: "0.1.0",228 schema: array(),229 },230 {231 version: "0.3.0",232 schema: array(),233 },234 ];235 const fileSystem = new StubFileSystem(STAFF_DATA, schemas);236 const dataSource = new LocalDataSource("staff", { fileSystem });237 const projection = new StubProjection("0.2.0", dataSource, fileSystem);238 await rejects(239 () => projection.generate(),240 (err: Error) => {241 eq(err.message, "Projection staff-full-names@0.2.0 has no current schema");242 return true;243 }244 );245 });246});247const STAFF_DATA: TemporalRecordType<any>[] = [248 {249 effectiveDate: new Date("2022-01-01T00:00:00Z"),250 data: [251 {252 givenNames: ["John"],253 surname: "Wayne",254 },255 {256 givenNames: ["John", "Paul"],257 surname: "Sartre",258 },259 ],260 },261 {262 effectiveDate: new Date("2021-01-01T00:00:00Z"),263 data: [264 {265 givenNames: ["Marrion", "Robert"],266 surname: "Morrison",267 },268 {269 givenNames: ["John", "Paul"],270 surname: "Sartre",271 },272 ],273 },274];275const SCHEMAS = [276 {277 version: "1.0.0",278 schema: array().of(279 object()280 .shape({281 fullName: string(),282 })283 .noUnknown(true)284 ),285 },...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { stubFileSystem } = require('stryker-parent');2const { createSandbox } = require('stryker-parent');3const { expectTestResult } = require('stryker-parent');4const sandbox = sinon.createSandbox();5describe('Add', function () {6 const stub = sandbox.stub();7 stubFileSystem({8 'package.json': JSON.stringify({9 })10 });11 sandbox.stub(fs, 'readFile').callsFake((fileName, callback) => {12 callback(null, 'stryker-parent');13 });14 sandbox.stub(fs, 'writeFile').callsFake((fileName, data, callback) => {15 callback(null, data);16 });17 sandbox.stub(fs, 'readFileSync').callsFake((fileName) => {18 return 'stryker-parent';19 });20 sandbox.stub(fs, 'writeFileSync').callsFake((fileName, data) => {21 return data;22 });23 sandbox.stub(fs, 'existsSync').callsFake((fileName) => {24 return true;25 });26 sandbox.stub(fs, 'unlinkSync').callsFake((fileName) => {27 return true;28 });29 it('should add two numbers', function () {30 const result = add(3, 4);31 expect(result).to.equal(7);32 });33 expectTestResult('should add two numbers', function () {34 const result = add(3, 4);35 expect(result).to.equal(7);36 });37 sandbox.stub(console, 'log').callsFake((message) => {38 return message;39 });40 it('should add two numbers', function () {41 const result = add(3,

Full Screen

Using AI Code Generation

copy

Full Screen

1const { stubFileSystem } = require('stryker-parent');2describe('test', () => {3 it('test', () => {4 stubFileSystem({5 });6 });7});8import { TestResult, TestStatus } from 'stryker-api/test_runner';9export default class MyTestRunner {10 init() {11 return Promise.resolve();12 }13 run() {14 const result = new TestResult();15 result.status = TestStatus.Success;16 return Promise.resolve(result);17 }18 dispose() {19 return Promise.resolve();20 }21}

Full Screen

Using AI Code Generation

copy

Full Screen

1var stubFileSystem = require('stryker-parent').stubFileSystem;2describe('my test', function () {3 it('should run', function () {4 stubFileSystem({5 });6 });7});

Full Screen

Using AI Code Generation

copy

Full Screen

1var stryker = require('stryker-parent');2var stubFileSystem = stryker.stubFileSystem;3var files = {4 'test.js': 'console.log("Hello World");',5 'test2.js': 'console.log("Hello World");'6};7var fileSystem = stubFileSystem(files);8var sandbox = fileSystem.createSandbox();9var config = {10 {pattern: 'test.js', included: true, mutated: true},11 {pattern: 'test2.js', included: true, mutated: false}12 karma: {13 }14};15var stryker = new Stryker(config);16stryker.runMutationTest();

Full Screen

Using AI Code Generation

copy

Full Screen

1export class ParentClass {2 constructor() {3 this._name = 'Parent';4 }5 getName() {6 return this._name;7 }8}9import { ParentClass } from './parentClass';10export class TestClass extends ParentClass {11 constructor() {12 super();13 this._name = 'Test';14 }15 getName() {16 return this._name;17 }18}19import { ParentClass } from './parentClass';20import { TestClass } from './testClass';21describe('Test Class', () => {22 it('should return the name', () => {23 const testClass = new TestClass();24 jest.spyOn(ParentClass.prototype, 'getName').mockReturnValue('Child');25 const name = testClass.getName();26 expect(name).toBe('Child');27 });28});

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