How to use fsTestDouble method in stryker-parent

Best JavaScript code snippet using stryker-parent

sandbox.spec.ts

Source:sandbox.spec.ts Github

copy

Full Screen

1import path from 'path';2import type { execaNode } from 'execa';3import { npmRunPathEnv } from 'npm-run-path';4import { expect } from 'chai';5import sinon from 'sinon';6import { testInjector, factory } from '@stryker-mutator/test-helpers';7import { I, normalizeWhitespaces } from '@stryker-mutator/util';8import { FileDescriptions } from '@stryker-mutator/api/src/core/file-description.js';9import { Sandbox } from '../../../src/sandbox/sandbox.js';10import { coreTokens } from '../../../src/di/index.js';11import { TemporaryDirectory } from '../../../src/utils/temporary-directory.js';12import { fileUtils } from '../../../src/utils/file-utils.js';13import { UnexpectedExitHandler } from '../../../src/unexpected-exit-handler.js';14import { Project } from '../../../src/fs/index.js';15import { FileSystemTestDouble } from '../../helpers/file-system-test-double.js';16describe(Sandbox.name, () => {17 let temporaryDirectoryMock: sinon.SinonStubbedInstance<TemporaryDirectory>;18 let symlinkJunctionStub: sinon.SinonStub;19 let findNodeModulesListStub: sinon.SinonStub;20 let execaCommandMock: sinon.SinonStubbedInstance<I<typeof execaNode>>;21 let unexpectedExitHandlerMock: sinon.SinonStubbedInstance<I<UnexpectedExitHandler>>;22 let moveDirectoryRecursiveSyncStub: sinon.SinonStub;23 let fsTestDouble: FileSystemTestDouble;24 const SANDBOX_WORKING_DIR = path.resolve('.stryker-tmp/sandbox-123');25 const BACKUP_DIR = 'backup-123';26 beforeEach(() => {27 temporaryDirectoryMock = sinon.createStubInstance(TemporaryDirectory);28 temporaryDirectoryMock.getRandomDirectory.withArgs('sandbox').returns(SANDBOX_WORKING_DIR).withArgs('backup').returns(BACKUP_DIR);29 symlinkJunctionStub = sinon.stub(fileUtils, 'symlinkJunction');30 findNodeModulesListStub = sinon.stub(fileUtils, 'findNodeModulesList');31 moveDirectoryRecursiveSyncStub = sinon.stub(fileUtils, 'moveDirectoryRecursiveSync');32 execaCommandMock = sinon.stub();33 unexpectedExitHandlerMock = {34 registerHandler: sinon.stub(),35 dispose: sinon.stub(),36 };37 fsTestDouble = new FileSystemTestDouble(Object.create(null) as Record<string, string>);38 symlinkJunctionStub.resolves();39 findNodeModulesListStub.resolves(['node_modules']);40 });41 function createSut(42 project = new Project(43 fsTestDouble,44 Object.keys(fsTestDouble.files).reduce<FileDescriptions>((fileDescriptions, fileName) => {45 fileDescriptions[fileName] = { mutate: true };46 return fileDescriptions;47 // eslint-disable-next-line @typescript-eslint/no-unsafe-argument48 }, Object.create(null))49 )50 ): Sandbox {51 return testInjector.injector52 .provideValue(coreTokens.project, project)53 .provideValue(coreTokens.temporaryDirectory, temporaryDirectoryMock)54 .provideValue(coreTokens.execa, execaCommandMock as unknown as typeof execaNode)55 .provideValue(coreTokens.unexpectedExitRegistry, unexpectedExitHandlerMock)56 .injectClass(Sandbox);57 }58 describe('init()', () => {59 describe('with inPlace = false', () => {60 beforeEach(() => {61 testInjector.options.inPlace = false;62 });63 it('should have created a sandbox folder', async () => {64 const sut = createSut();65 await sut.init();66 expect(temporaryDirectoryMock.getRandomDirectory).calledWith('sandbox');67 expect(temporaryDirectoryMock.createDirectory).calledWith(SANDBOX_WORKING_DIR);68 });69 it('should copy regular input files', async () => {70 fsTestDouble.files[path.resolve('a', 'main.js')] = 'foo("bar")';71 fsTestDouble.files[path.resolve('a', 'b.txt')] = 'b content';72 fsTestDouble.files[path.resolve('c', 'd', 'e.log')] = 'e content';73 const project = new Project(fsTestDouble, {74 [path.resolve('a', 'main.js')]: { mutate: true },75 [path.resolve('a', 'b.txt')]: { mutate: false },76 [path.resolve('c', 'd', 'e.log')]: { mutate: false },77 });78 project.files.get(path.resolve('a', 'main.js'))!.setContent('foo("mutated")');79 const sut = createSut(project);80 await sut.init();81 expect(fsTestDouble.files[path.join(SANDBOX_WORKING_DIR, 'a', 'main.js')]).eq('foo("mutated")');82 expect(fsTestDouble.files[path.join(SANDBOX_WORKING_DIR, 'a', 'b.txt')]).eq('b content');83 expect(fsTestDouble.files[path.join(SANDBOX_WORKING_DIR, 'c', 'd', 'e.log')]).eq('e content');84 });85 it('should be able to copy a local file', async () => {86 fsTestDouble.files['localFile.txt'] = 'foobar';87 const sut = createSut();88 await sut.init();89 expect(fsTestDouble.files[path.join(SANDBOX_WORKING_DIR, 'localFile.txt')]).eq('foobar');90 });91 it('should symlink node modules in sandbox directory if exists', async () => {92 const sut = createSut();93 await sut.init();94 expect(findNodeModulesListStub).calledWith(process.cwd());95 expect(symlinkJunctionStub).calledWith(path.resolve('node_modules'), path.join(SANDBOX_WORKING_DIR, 'node_modules'));96 });97 });98 describe('with inPlace = true', () => {99 beforeEach(() => {100 testInjector.options.inPlace = true;101 });102 it('should have created a backup directory', async () => {103 const sut = createSut();104 await sut.init();105 expect(temporaryDirectoryMock.getRandomDirectory).calledWith('backup');106 expect(temporaryDirectoryMock.createDirectory).calledWith(BACKUP_DIR);107 });108 it('should not override the current file if no changes were detected', async () => {109 fsTestDouble.files[path.resolve('a', 'b.txt')] = 'b content';110 const sut = createSut();111 await sut.init();112 expect(Object.keys(fsTestDouble.files)).lengthOf(1);113 });114 it('should override original file if changes were detected', async () => {115 // Arrange116 const fileName = path.resolve('a', 'b.js');117 fsTestDouble.files[fileName] = 'b content';118 const project = new Project(fsTestDouble, { [fileName]: { mutate: true } });119 project.files.get(fileName)!.setContent('b mutated content');120 // Act121 const sut = createSut(project);122 await sut.init();123 // Assert124 expect(fsTestDouble.files[fileName]).eq('b mutated content');125 });126 it('should backup the original before overriding it', async () => {127 // Arrange128 const fileName = path.resolve('a', 'b.js');129 const originalContent = 'b content';130 const mutatedContent = 'b mutated content';131 fsTestDouble.files[fileName] = originalContent;132 const project = new Project(fsTestDouble, { [fileName]: { mutate: true } });133 project.files.get(fileName)!.setContent(mutatedContent);134 const expectedBackupFileName = path.join(path.join(BACKUP_DIR, 'a'), 'b.js');135 // Act136 const sut = createSut(project);137 await sut.init();138 // Assert139 expect(fsTestDouble.files[expectedBackupFileName]).eq(originalContent);140 expect(fsTestDouble.files[fileName]).eq(mutatedContent);141 });142 it('should log the backup file location', async () => {143 // Arrange144 const fileName = path.resolve('a', 'b.js');145 const originalContent = 'b content';146 const mutatedContent = 'b mutated content';147 fsTestDouble.files[fileName] = originalContent;148 const project = new Project(fsTestDouble, { [fileName]: { mutate: true } });149 project.files.get(fileName)!.setContent(mutatedContent);150 const expectedBackupFileName = path.join(path.join(BACKUP_DIR, 'a'), 'b.js');151 // Act152 const sut = createSut(project);153 await sut.init();154 // Assert155 expect(testInjector.logger.debug).calledWith('Stored backup file at %s', expectedBackupFileName);156 });157 it('should register an unexpected exit handler', async () => {158 // Act159 const sut = createSut();160 await sut.init();161 // Assert162 expect(unexpectedExitHandlerMock.registerHandler).called;163 });164 });165 it('should symlink node modules in sandbox directory if node_modules exist', async () => {166 findNodeModulesListStub.resolves(['node_modules', 'packages/a/node_modules']);167 const sut = createSut();168 await sut.init();169 const calls = symlinkJunctionStub.getCalls();170 expect(calls[0]).calledWithExactly(path.resolve('node_modules'), path.join(SANDBOX_WORKING_DIR, 'node_modules'));171 expect(calls[1]).calledWithExactly(172 path.resolve('packages', 'a', 'node_modules'),173 path.join(SANDBOX_WORKING_DIR, 'packages', 'a', 'node_modules')174 );175 });176 it('should not symlink node_modules in sandbox directory if no node_modules exist', async () => {177 findNodeModulesListStub.resolves([]);178 const sut = createSut();179 await sut.init();180 expect(testInjector.logger.debug).calledWithMatch('Could not find a node_modules');181 expect(testInjector.logger.debug).calledWithMatch(process.cwd());182 expect(symlinkJunctionStub).not.called;183 });184 it('should log a warning if "node_modules" already exists in the working folder', async () => {185 findNodeModulesListStub.resolves(['node_modules']);186 symlinkJunctionStub.rejects(factory.fileAlreadyExistsError());187 const sut = createSut();188 await sut.init();189 expect(testInjector.logger.warn).calledWithMatch(190 normalizeWhitespaces(191 `Could not symlink "node_modules" in sandbox directory, it is already created in the sandbox.192 Please remove the node_modules from your sandbox files. Alternatively, set \`symlinkNodeModules\`193 to \`false\` to disable this warning.`194 )195 );196 });197 it('should log a warning if linking "node_modules" results in an unknown error', async () => {198 findNodeModulesListStub.resolves(['basePath/node_modules']);199 const error = new Error('unknown');200 symlinkJunctionStub.rejects(error);201 const sut = createSut();202 await sut.init();203 expect(testInjector.logger.warn).calledWithMatch(204 normalizeWhitespaces('Unexpected error while trying to symlink "basePath/node_modules" in sandbox directory.'),205 error206 );207 });208 it('should not symlink node modules in sandbox directory if `symlinkNodeModules` is `false`', async () => {209 testInjector.options.symlinkNodeModules = false;210 const sut = createSut();211 await sut.init();212 expect(symlinkJunctionStub).not.called;213 expect(findNodeModulesListStub).not.called;214 });215 it('should execute the buildCommand in the sandbox', async () => {216 testInjector.options.buildCommand = 'npm run build';217 const sut = createSut();218 await sut.init();219 expect(execaCommandMock).calledWith('npm run build', { cwd: SANDBOX_WORKING_DIR, env: npmRunPathEnv() });220 expect(testInjector.logger.info).calledWith('Running build command "%s" in "%s".', 'npm run build', SANDBOX_WORKING_DIR);221 });222 it('should not execute a build command when non is configured', async () => {223 testInjector.options.buildCommand = undefined;224 const sut = createSut();225 await sut.init();226 expect(execaCommandMock).not.called;227 });228 it('should execute the buildCommand before the node_modules are symlinked', async () => {229 // It is important to first run the buildCommand, otherwise the build dependencies are not correctly resolved230 testInjector.options.buildCommand = 'npm run build';231 const sut = createSut();232 await sut.init();233 expect(execaCommandMock).calledBefore(symlinkJunctionStub);234 });235 });236 describe('dispose', () => {237 it("shouldn't do anything when inPlace = false", () => {238 const sut = createSut();239 sut.dispose();240 expect(moveDirectoryRecursiveSyncStub).not.called;241 });242 it('should recover from the backup dir synchronously if inPlace = true', () => {243 testInjector.options.inPlace = true;244 const sut = createSut();245 sut.dispose();246 expect(moveDirectoryRecursiveSyncStub).calledWith(BACKUP_DIR, process.cwd());247 });248 it('should recover from the backup dir if stryker exits unexpectedly while inPlace = true', () => {249 testInjector.options.inPlace = true;250 const errorStub = sinon.stub(console, 'error');251 createSut();252 unexpectedExitHandlerMock.registerHandler.callArg(0);253 expect(moveDirectoryRecursiveSyncStub).calledWith(BACKUP_DIR, process.cwd());254 expect(errorStub).calledWith(`Detecting unexpected exit, recovering original files from ${BACKUP_DIR}`);255 });256 });257 describe('workingDirectory', () => {258 it('should retrieve the sandbox directory when inPlace = false', async () => {259 const sut = createSut();260 await sut.init();261 expect(sut.workingDirectory).eq(SANDBOX_WORKING_DIR);262 });263 it('should retrieve the cwd directory when inPlace = true', async () => {264 testInjector.options.inPlace = true;265 const sut = createSut();266 await sut.init();267 expect(sut.workingDirectory).eq(process.cwd());268 });269 });270 // describe(Sandbox.prototype.sandboxFileFor.name, () => {271 // it('should return the sandbox file if exists', async () => {272 // const originalFileName = path.resolve('src/foo.js');273 // fsTestDouble.push(new File(originalFileName, ''));274 // const sut = createSut();275 // await sut.init();276 // const actualSandboxFile = sut.sandboxFileFor(originalFileName);277 // expect(actualSandboxFile).eq(path.join(SANDBOX_WORKING_DIR, 'src/foo.js'));278 // });279 // it("should throw when the sandbox file doesn't exists", async () => {280 // const notExistingFile = 'src/bar.js';281 // fsTestDouble.push(new File(path.resolve('src/foo.js'), ''));282 // const sut = createSut();283 // await sut.init();284 // expect(() => sut.sandboxFileFor(notExistingFile)).throws('Cannot find sandbox file for src/bar.js');285 // });286 // });287 describe(Sandbox.prototype.originalFileFor.name, () => {288 it('should remap the file to the original', async () => {289 const sut = createSut();290 await sut.init();291 const sandboxFile = path.join(SANDBOX_WORKING_DIR, 'src/foo.js');292 expect(sut.originalFileFor(sandboxFile)).eq(path.resolve('src/foo.js'));293 });294 });...

Full Screen

Full Screen

ts-config-preprocessor.spec.ts

Source:ts-config-preprocessor.spec.ts Github

copy

Full Screen

1import path from 'path';2import { expect } from 'chai';3import { testInjector } from '@stryker-mutator/test-helpers';4import { TSConfigPreprocessor } from '../../../src/sandbox/ts-config-preprocessor.js';5import { FileSystemTestDouble } from '../../helpers/file-system-test-double.js';6import { Project } from '../../../src/fs/project.js';7import { serializeTSConfig } from '../../helpers/producers.js';8describe(TSConfigPreprocessor.name, () => {9 let fsTestDouble: FileSystemTestDouble;10 let sut: TSConfigPreprocessor;11 const tsconfigFileName = path.resolve('tsconfig.json');12 beforeEach(() => {13 fsTestDouble = new FileSystemTestDouble();14 sut = testInjector.injector.injectClass(TSConfigPreprocessor);15 });16 it('should not do anything if the tsconfig file does not exist', async () => {17 fsTestDouble.files['foo.js'] = 'console.log("foo");';18 const project = new Project(fsTestDouble, fsTestDouble.toFileDescriptions());19 await sut.preprocess(project);20 expect(project.files.size).eq(1);21 expect(await project.files.get('foo.js')!.readContent()).eq('console.log("foo");');22 });23 it('should ignore missing "extends"', async () => {24 // Arrange25 const tsconfigInput = serializeTSConfig({ extends: './tsconfig.src.json' });26 fsTestDouble.files[tsconfigFileName] = tsconfigInput;27 const project = new Project(fsTestDouble, fsTestDouble.toFileDescriptions());28 // Act29 await sut.preprocess(project);30 // Assert31 expect(await project.files.get(tsconfigFileName)!.readContent()).eq(tsconfigInput);32 });33 it('should ignore missing "references"', async () => {34 // Arrange35 const tsconfigInput = serializeTSConfig({ references: [{ path: './tsconfig.src.json' }] });36 fsTestDouble.files[tsconfigFileName] = tsconfigInput;37 const project = new Project(fsTestDouble, fsTestDouble.toFileDescriptions());38 // Act39 await sut.preprocess(project);40 // Assert41 expect(await project.files.get(tsconfigFileName)!.readContent()).eq(tsconfigInput);42 });43 it('should rewrite "extends" if it falls outside of sandbox', async () => {44 // Arrange45 const tsconfigInput = serializeTSConfig({ extends: '../tsconfig.settings.json' });46 fsTestDouble.files[tsconfigFileName] = tsconfigInput;47 const project = new Project(fsTestDouble, fsTestDouble.toFileDescriptions());48 // Act49 await sut.preprocess(project);50 // Assert51 expect(await project.files.get(tsconfigFileName)!.readContent()).eq(serializeTSConfig({ extends: '../../../tsconfig.settings.json' }));52 });53 it('should rewrite "references" if it falls outside of sandbox', async () => {54 // Arrange55 fsTestDouble.files[tsconfigFileName] = serializeTSConfig({ references: [{ path: '../model' }] });56 const project = new Project(fsTestDouble, fsTestDouble.toFileDescriptions());57 // Act58 await sut.preprocess(project);59 // Assert60 expect(await project.files.get(tsconfigFileName)!.readContent()).eq(61 serializeTSConfig({ references: [{ path: '../../../model/tsconfig.json' }] })62 );63 });64 it('should rewrite "include" array items located outside of the sandbox', async () => {65 // See https://github.com/stryker-mutator/stryker-js/issues/328166 fsTestDouble.files[tsconfigFileName] = serializeTSConfig({67 include: ['./**/*', '../../../node_modules/self-service-server/lib/main/shared/@types/**/*.d.ts'],68 });69 const project = new Project(fsTestDouble, fsTestDouble.toFileDescriptions());70 await sut.preprocess(project);71 expect(await project.files.get(tsconfigFileName)!.readContent()).eq(72 serializeTSConfig({73 include: ['./**/*', '../../../../../node_modules/self-service-server/lib/main/shared/@types/**/*.d.ts'],74 })75 );76 });77 it('should rewrite "exclude" array items located outside of the sandbox', async () => {78 fsTestDouble.files[tsconfigFileName] = serializeTSConfig({79 exclude: ['./**/*', '../foo.ts'],80 });81 const project = new Project(fsTestDouble, fsTestDouble.toFileDescriptions());82 await sut.preprocess(project);83 expect(await project.files.get(tsconfigFileName)!.readContent()).eq(84 serializeTSConfig({85 exclude: ['./**/*', '../../../foo.ts'],86 })87 );88 });89 it('should rewrite "files" array items located outside of the sandbox', async () => {90 // See https://github.com/stryker-mutator/stryker-js/issues/328191 fsTestDouble.files[tsconfigFileName] = serializeTSConfig({92 files: ['foo/bar.ts', '../global.d.ts'],93 });94 const project = new Project(fsTestDouble, fsTestDouble.toFileDescriptions());95 await sut.preprocess(project);96 expect(await project.files.get(tsconfigFileName)!.readContent()).eq(97 serializeTSConfig({98 files: ['foo/bar.ts', '../../../global.d.ts'],99 })100 );101 });102 it('should not do anything when inPlace = true', async () => {103 testInjector.options.inPlace = true;104 const tsconfigInput = serializeTSConfig({ extends: '../tsconfig.settings.json' });105 fsTestDouble.files[tsconfigFileName] = tsconfigInput;106 const project = new Project(fsTestDouble, fsTestDouble.toFileDescriptions());107 await sut.preprocess(project);108 expect(await project.files.get(tsconfigFileName)!.readContent()).eq(tsconfigInput);109 });110 it('should support comments and other settings', async () => {111 fsTestDouble.files[tsconfigFileName] = `{112 "extends": "../tsconfig.settings.json",113 "compilerOptions": {114 // Here are the options115 "target": "es5", // and a trailing comma116 }117 }`;118 const project = new Project(fsTestDouble, fsTestDouble.toFileDescriptions());119 await sut.preprocess(project);120 expect(await project.files.get(tsconfigFileName)!.readContent()).eq(121 serializeTSConfig({ extends: '../../../tsconfig.settings.json', compilerOptions: { target: 'es5' } })122 );123 });124 it('should rewrite referenced tsconfig files that are also located in the sandbox', async () => {125 // Arrange126 fsTestDouble.files[tsconfigFileName] = serializeTSConfig({ extends: './tsconfig.settings.json', references: [{ path: './src' }] });127 fsTestDouble.files[path.resolve('tsconfig.settings.json')] = serializeTSConfig({ extends: '../../tsconfig.root-settings.json' });128 fsTestDouble.files[path.resolve('src/tsconfig.json')] = serializeTSConfig({ references: [{ path: '../../model' }] });129 const project = new Project(fsTestDouble, fsTestDouble.toFileDescriptions());130 // Act131 await sut.preprocess(project);132 // Assert133 expect(await project.files.get(tsconfigFileName)!.readContent()).eq(134 serializeTSConfig({ extends: './tsconfig.settings.json', references: [{ path: './src' }] })135 );136 expect(await project.files.get(path.resolve('tsconfig.settings.json'))!.readContent()).eq(137 serializeTSConfig({ extends: '../../../../tsconfig.root-settings.json' })138 );139 expect(await project.files.get(path.resolve('src/tsconfig.json'))!.readContent()).eq(140 serializeTSConfig({ references: [{ path: '../../../../model/tsconfig.json' }] })141 );142 });143 it('should be able to rewrite a monorepo style project', async () => {144 // Arrange145 fsTestDouble.files[path.resolve('tsconfig.root.json')] = serializeTSConfig({146 extends: '../../tsconfig.settings.json',147 references: [{ path: 'src' }, { path: 'test/tsconfig.test.json' }],148 });149 fsTestDouble.files[path.resolve('src/tsconfig.json')] = serializeTSConfig({150 extends: '../../../tsconfig.settings.json',151 references: [{ path: '../../model' }],152 });153 fsTestDouble.files[path.resolve('test/tsconfig.test.json')] = serializeTSConfig({154 extends: '../tsconfig.root.json',155 references: [{ path: '../src' }],156 });157 testInjector.options.tsconfigFile = 'tsconfig.root.json';158 const project = new Project(fsTestDouble, fsTestDouble.toFileDescriptions());159 // Act160 await sut.preprocess(project);161 // Assert162 expect(await project.files.get(path.resolve('tsconfig.root.json'))!.readContent()).eq(163 serializeTSConfig({164 extends: '../../../../tsconfig.settings.json',165 references: [{ path: 'src' }, { path: 'test/tsconfig.test.json' }],166 })167 );168 expect(await project.files.get(path.resolve('src/tsconfig.json'))!.readContent()).eq(169 serializeTSConfig({170 extends: '../../../../../tsconfig.settings.json',171 references: [{ path: '../../../../model/tsconfig.json' }],172 })173 );174 expect(await project.files.get(path.resolve('test/tsconfig.test.json'))!.readContent()).eq(175 serializeTSConfig({ extends: '../tsconfig.root.json', references: [{ path: '../src' }] })176 );177 });...

Full Screen

Full Screen

create-preprocessor.spec.ts

Source:create-preprocessor.spec.ts Github

copy

Full Screen

1import path from 'path';2import { testInjector } from '@stryker-mutator/test-helpers';3import { expect } from 'chai';4import { FilePreprocessor, createPreprocessor } from '../../../src/sandbox/index.js';5import { FileSystemTestDouble } from '../../helpers/file-system-test-double.js';6import { serializeTSConfig } from '../../helpers/producers.js';7import { Project } from '../../../src/fs/index.js';8describe(createPreprocessor.name, () => {9 let fsTestDouble: FileSystemTestDouble;10 let sut: FilePreprocessor;11 beforeEach(() => {12 fsTestDouble = new FileSystemTestDouble();13 sut = testInjector.injector.injectFunction(createPreprocessor);14 });15 it('should rewrite tsconfig files', async () => {16 // Arrange17 const tsconfigFileName = path.resolve('tsconfig.json');18 const tsconfigInput = serializeTSConfig({ extends: '../tsconfig.settings.json' });19 fsTestDouble.files[tsconfigFileName] = tsconfigInput;20 const project = new Project(fsTestDouble, fsTestDouble.toFileDescriptions());21 // Act22 await sut.preprocess(project);23 // Assert24 expect(await project.files.get(tsconfigFileName)!.readContent()).eq(serializeTSConfig({ extends: '../../../tsconfig.settings.json' }));25 });26 it('should disable type checking for .ts files', async () => {27 const fileName = path.resolve('src/app.ts');28 fsTestDouble.files[fileName] = 'foo.bar()';29 const project = new Project(fsTestDouble, fsTestDouble.toFileDescriptions());30 await sut.preprocess(project);31 expect(await project.files.get(fileName)!.readContent()).eq('// @ts-nocheck\nfoo.bar()');32 });33 it('should strip // @ts-expect-error (see https://github.com/stryker-mutator/stryker-js/issues/2364)', async () => {34 const fileName = path.resolve('src/app.ts');35 fsTestDouble.files[fileName] = '// @ts-expect-error\nfoo.bar()';36 const project = new Project(fsTestDouble, fsTestDouble.toFileDescriptions());37 await sut.preprocess(project);38 expect(await project.files.get(fileName)!.readContent()).eq('// @ts-nocheck\n// \nfoo.bar()');39 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const fs = require('fs');2const fsTestDouble = require('stryker-parent').fsTestDouble;3fsTestDouble(fs);4const fs = require('fs');5const fsTestDouble = require('stryker').fsTestDouble;6fsTestDouble(fs);7const fs = require('fs');8const fsTestDouble = require('stryker').fsTestDouble;9fsTestDouble(fs);10const fs = require('fs');11const fsTestDouble = require('stryker').fsTestDouble;12fsTestDouble(fs);13const fs = require('fs');14const fsTestDouble = require('stryker').fsTestDouble;15fsTestDouble(fs);16const fs = require('fs');17const fsTestDouble = require('stryker').fsTestDouble;18fsTestDouble(fs);19const fs = require('fs');20const fsTestDouble = require('stryker').fsTestDouble;21fsTestDouble(fs);22const fs = require('fs');23const fsTestDouble = require('stryker').fsTestDouble;24fsTestDouble(fs);25const fs = require('fs');26const fsTestDouble = require('stryker').fsTestDouble;27fsTestDouble(fs);28const fs = require('fs');29const fsTestDouble = require('stryker').fsTestDouble;30fsTestDouble(fs);31const fs = require('fs');32const fsTestDouble = require('stryker').fsTestDouble;33fsTestDouble(fs);

Full Screen

Using AI Code Generation

copy

Full Screen

1var fsTestDouble = require('stryker-parent').fsTestDouble;2fsTestDouble.stub('fs', 'readdirSync', function() {3 return ['file1.js', 'file2.js'];4});5var files = fs.readdirSync('.');6console.log(files);7module.exports = {8 fsTestDouble: require('./lib/fsTestDouble')9};10var testDouble = require('testdouble');11module.exports = {12 stub: function() {13 testDouble.stub.apply(testDouble, arguments);14 }15};16var testDouble = require('testdouble');17module.exports = {18 stub: function() {19 testDouble.stub.apply(testDouble, arguments);20 }21};22module.exports = {23 stub: function() {24 var testDouble = require('testdouble');25 testDouble.stub.apply(testDouble, arguments);26 }27};28var testDouble;29module.exports = {30 stub: function() {31 if (!testDouble) {32 testDouble = require('testdouble');33 }34 testDouble.stub.apply(testDouble, arguments);35 }36};37var testDouble;38module.exports = {39 stub: function() {40 if (!testDouble

Full Screen

Using AI Code Generation

copy

Full Screen

1import { fsTestDouble } from 'stryker-parent';2import { fsTestDouble } from 'stryker-parent';3When you want to use the fsTestDouble method in your test file, you can import it from the stryker-parent package. The fsTestDouble method is a function that returns a mock of the fs module. This mock is based on the fs-extra library. You can use the fsTestDouble method in your test files to mock the fs module. For example:4import { fsTestDouble } from 'stryker-parent';5import { fsTestDouble } from 'stryker-parent';6import { fsTestDouble } from 'stryker-parent';7import { fsTestDouble } from 'stryker-parent';8When you want to use the fsTestDouble method in your test file, you can import it from the stryker-parent package. The fsTestDouble method is a function that returns a mock of the fs module. This mock is based on the fs-extra library. You can use the fsTestDouble method in your test files to mock the fs module. For example:9import { fsTestDouble } from 'stryker-parent';10import { fsTestDouble } from 'stryker-parent';11import { fsTestDouble } from 'stryker-parent';12import { fsTestDouble } from 'stryker-parent';13When you want to use the fsTestDouble method in your test file, you can import it from the stryker-parent package. The fsTestDouble method is a function that returns a mock of the fs module. This mock is based on the fs-extra library. You can use the fsTestDouble method in your test files to mock the fs module. For example:14import { fsTestDouble } from 'stryker-parent';15import { fsTestDouble } from 'stryker-parent';16import { fsTest

Full Screen

Using AI Code Generation

copy

Full Screen

1const fsTestDouble = require('stryker-parent').fsTestDouble;2const fs = require('fs');3const path = require('path');4const testDir = path.join(__dirname, 'test');5 .init()6 .then(() => {7 fs.mkdirSync(testDir);8 fs.writeFileSync(path.join(testDir, 'test.txt'), 'test');9 });10module.exports = function(config) {11 config.set({12 commandRunner: {13 }14 });15};16The fsTestDouble.getTempFolder() method will return the temporary directory. You can use this to create a file in the temporary directory. For example:17fs.writeFileSync(path.join(fsTestDouble.getTempFolder(), 'test.txt'), 'test');18The fsTestDouble.getOriginalWorkingDirectory() method will return the original working directory. You can use this to create a file in the original working directory. For example:19fs.writeFileSync(path.join(fsTestDouble.getOriginalWorkingDirectory(), 'test.txt'), 'test');20The fsTestDouble.getOriginalNodePath() method will return the original NODE_PATH. You can use this to create a file in the original directory. For example:21fs.writeFileSync(path.join(fsTestDouble.getOriginalNodePath(), 'test.txt'), 'test');22The fsTestDouble.getOriginalCwd() method will return the original cwd. You can use this to create a file in the original directory. For example:23fs.writeFileSync(path.join(fsTestDouble.getOriginalCwd(), 'test.txt'), 'test');24The fsTestDouble.getOriginalEnv() method will return the original environment variables. You can use this to create a file in the original directory. For example:25fs.writeFileSync(path.join(fsTestDouble.getOriginalEnv().MY_VAR, 'test.txt'), 'test');

Full Screen

Using AI Code Generation

copy

Full Screen

1const fs = require('fs');2const fsTestDouble = require('stryker-parent').fsTestDouble;3fsTestDouble.mock({4});5describe('foo', () => {6 it('should do bar', () => {7 expect(fs.readFileSync('foo/bar').toString()).to.equal('some content');8 });9});10describe('foo', () => {11 it('should do bar', () => {12 expect(fs.readFileSync('foo/bar').toString()).to.equal('some content');13 });14});15describe('foo', () => {16 it('should do bar', () => {17 expect(fs.readFileSync('foo/bar').toString()).to.equal('some content');18 });19});20describe('foo', () => {21 it('should do bar', () => {22 expect(fs.readFileSync('foo/bar').toString()).to.equal('some content');23 });24});25describe('foo', () => {26 it('should do bar', () => {27 expect(fs.readFileSync('foo/bar').toString()).to.equal('some content');28 });29});30describe('foo', () => {31 it('should do bar', () => {32 expect(fs.readFileSync('foo/bar').toString()).to.equal('some content');33 });34});35describe('foo', () => {36 it('should do bar', () => {37 expect(fs.readFileSync('foo/bar').toString()).to.equal('some content');38 });39});40describe('foo', () => {41 it('should do bar', () => {42 expect(fs.readFileSync('foo/bar').toString()).to.equal('some content');43 });44});45describe('foo', () => {46 it('should do bar', () => {47 expect(fs.readFileSync('foo/bar').toString()).to.equal('some content');48 });49});50describe('foo', () => {51 it('should do bar', () => {52 expect(fs.readFileSync('foo/bar').toString()).to.equal('some content');53 });54});55describe('foo', () => {56 it('should do bar', () => {57 expect(fs.readFileSync('foo/bar').toString()).to.equal('some content');58 });59});60describe('foo', () => {61 it('should do bar', () => {62 expect(fs.readFileSync('foo/bar').toString()).to.equal('

Full Screen

Using AI Code Generation

copy

Full Screen

1const fs = require('fs');2const fsTestDouble = require('stryker-parent/fsTestDouble');3const assert = require('assert');4describe('fsTestDouble', function() {5 it('should be a function', function() {6 assert.equal(typeof fsTestDouble, 'function');7 });8 it('should return a double of fs', function() {9 assert.equal(fsTestDouble(), fs);10 });11});

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