Best JavaScript code snippet using stryker-parent
project-file.spec.ts
Source:project-file.spec.ts
...43 describe(ProjectFile.prototype.readOriginal.name, () => {44 it('should read the content from disk', async () => {45 const sut = createSut({ name: 'foo.js' });46 fileSystemMock.readFile.resolves('content');47 const result = await sut.readOriginal();48 expect(result).eq('content');49 sinon.assert.calledOnceWithExactly(fileSystemMock.readFile, 'foo.js', 'utf-8');50 });51 it('should read the content from disk only the first time', async () => {52 // Arrange53 const sut = createSut({ name: 'foo.js' });54 fileSystemMock.readFile.resolves('content');55 // Act56 await sut.readOriginal();57 const result = await sut.readOriginal();58 // Assert59 expect(result).eq('content');60 sinon.assert.calledOnceWithExactly(fileSystemMock.readFile, 'foo.js', 'utf-8');61 });62 it('should also cache original when readContent is called', async () => {63 // Arrange64 const sut = createSut({ name: 'foo.js' });65 fileSystemMock.readFile.resolves('content');66 // Act67 await sut.readContent();68 const result = await sut.readOriginal();69 // Assert70 expect(result).eq('content');71 sinon.assert.calledOnceWithExactly(fileSystemMock.readFile, 'foo.js', 'utf-8');72 });73 it('should still read the content from disk when the content is set in-memory', async () => {74 // Arrange75 const sut = createSut();76 fileSystemMock.readFile.resolves('original');77 // Act78 sut.setContent('bar');79 const result = await sut.readOriginal();80 // Assert81 expect(result).eq('original');82 });83 });84 describe(ProjectFile.prototype.toInstrumenterFile.name, () => {85 it('should read content', async () => {86 // Arrange87 const mutate = [{ start: { column: 1, line: 2 }, end: { column: 3, line: 4 } }];88 const sut = createSut({ name: 'bar.js', mutate });89 fileSystemMock.readFile.resolves('original');90 // Act91 const result = await sut.toInstrumenterFile();92 // Assert93 const expected: File = { content: 'original', mutate, name: 'bar.js' };94 expect(result).deep.eq(expected);95 });96 });97 describe('hasChanges', () => {98 it('should be false when nothing changed', () => {99 const sut = createSut();100 fileSystemMock.readFile.resolves('original');101 expect(sut.hasChanges).false;102 });103 it('should be false when content is read but not overridden', async () => {104 const sut = createSut();105 fileSystemMock.readFile.resolves('original');106 await sut.readOriginal();107 expect(sut.hasChanges).false;108 });109 it('should be false when content is overridden with the same content', async () => {110 const sut = createSut();111 fileSystemMock.readFile.resolves('original');112 await sut.readOriginal();113 sut.setContent('original');114 expect(sut.hasChanges).false;115 });116 it('should be true when content is overridden', async () => {117 const sut = createSut();118 sut.setContent('something');119 expect(sut.hasChanges).true;120 });121 it('should be true when content is overridden after read', async () => {122 const sut = createSut();123 fileSystemMock.readFile.resolves('original');124 await sut.readOriginal();125 sut.setContent('');126 expect(sut.hasChanges).true;127 });128 });129 describe(ProjectFile.prototype.writeInPlace.name, () => {130 it('should not do anything when there are no changes', async () => {131 const sut = createSut();132 await sut.writeInPlace();133 sinon.assert.notCalled(fileSystemMock.writeFile);134 });135 it('should override current file when content was overridden', async () => {136 const sut = createSut({ name: 'src/foo.js' });137 sut.setContent('some content');138 await sut.writeInPlace();139 sinon.assert.calledOnceWithExactly(fileSystemMock.writeFile, 'src/foo.js', 'some content', 'utf-8');140 });141 it('should not do anything when the content written had no changes', async () => {142 // Arrange143 const sut = createSut({ name: 'src/foo.js' });144 fileSystemMock.readFile.resolves('original');145 await sut.readContent();146 sut.setContent('original');147 // Act148 await sut.writeInPlace();149 // Assert150 sinon.assert.notCalled(fileSystemMock.writeFile);151 });152 });153 describe(ProjectFile.prototype.writeToSandbox.name, () => {154 it('should write to the sandbox', async () => {155 // Arrange156 const sut = createSut({ name: path.resolve('src', 'foo.js') });157 sut.setContent('foo();');158 // Act159 const actualSandboxFile = await sut.writeToSandbox(path.resolve('.stryker-tmp', 'sandbox123'));160 // Assert161 expect(actualSandboxFile).eq(path.resolve('.stryker-tmp', 'sandbox123', 'src', 'foo.js'));162 sinon.assert.calledOnceWithExactly(fileSystemMock.writeFile, actualSandboxFile, 'foo();', 'utf-8');163 sinon.assert.notCalled(fileSystemMock.copyFile);164 });165 it('should resolve the correct file name when a sandbox outside of the current dir is used', async () => {166 // Arrange167 const sut = createSut({ name: path.resolve('src', 'foo.js') });168 sut.setContent('foo();');169 // Act170 const actualSandboxFile = await sut.writeToSandbox(path.resolve('..', '.stryker-tmp', 'sandbox123'));171 // Assert172 expect(actualSandboxFile).eq(path.resolve('..', '.stryker-tmp', 'sandbox123', 'src', 'foo.js'));173 });174 it('should make the dir before write', async () => {175 // Arrange176 const sut = createSut({ name: path.resolve('src', 'foo.js') });177 sut.setContent('foo();');178 // Act179 const actualSandboxFile = await sut.writeToSandbox(path.resolve('.stryker-tmp', 'sandbox123'));180 // Assert181 sinon.assert.calledOnceWithExactly(fileSystemMock.mkdir, path.dirname(actualSandboxFile), { recursive: true });182 sinon.assert.callOrder(fileSystemMock.mkdir, fileSystemMock.writeFile);183 });184 it('should copy the file instead of reading/writing when the file is not read to memory', async () => {185 // Arrange186 const originalFileName = path.resolve('src', 'foo.js');187 const sut = createSut({ name: originalFileName });188 // Act189 const actualSandboxFile = await sut.writeToSandbox(path.resolve('.stryker-tmp', 'sandbox123'));190 // Assert191 expect(actualSandboxFile).eq(path.resolve('.stryker-tmp', 'sandbox123', 'src', 'foo.js'));192 sinon.assert.calledOnceWithExactly(fileSystemMock.copyFile, originalFileName, actualSandboxFile);193 sinon.assert.notCalled(fileSystemMock.writeFile);194 });195 });196 describe(ProjectFile.prototype.backupTo.name, () => {197 it('should write to the sandbox', async () => {198 // Arrange199 const sut = createSut({ name: path.resolve('src', 'foo.js') });200 fileSystemMock.readFile.resolves('original');201 await sut.readOriginal();202 // Act203 const actualBackupFile = await sut.writeToSandbox(path.resolve('.stryker-tmp', 'backup123'));204 // Assert205 expect(actualBackupFile).eq(path.resolve('.stryker-tmp', 'backup123', 'src', 'foo.js'));206 sinon.assert.calledOnceWithExactly(fileSystemMock.writeFile, actualBackupFile, 'original', 'utf-8');207 sinon.assert.notCalled(fileSystemMock.copyFile);208 });209 it('should make the dir before write', async () => {210 // Arrange211 const sut = createSut({ name: path.resolve('src', 'foo.js') });212 fileSystemMock.readFile.resolves('original');213 await sut.readOriginal();214 // Act215 const actualBackupFile = await sut.writeToSandbox(path.resolve('.stryker-tmp', 'backup123'));216 // Assert217 sinon.assert.calledOnceWithExactly(fileSystemMock.mkdir, path.dirname(actualBackupFile), { recursive: true });218 sinon.assert.callOrder(fileSystemMock.mkdir, fileSystemMock.writeFile);219 });220 it('should copy the file instead of reading/writing when the file is present in memory', async () => {221 // Arrange222 const originalFileName = path.resolve('src', 'foo.js');223 const sut = createSut({ name: originalFileName });224 // Act225 const actualBackupFile = await sut.backupTo(path.resolve('.stryker-tmp', 'backup-123'));226 // Assert227 expect(actualBackupFile).eq(path.resolve('.stryker-tmp', 'backup-123', 'src', 'foo.js'));...
transform.ts
Source:transform.ts
...96 this.data.set(node, data);97 }98 return data;99 }100 readOriginal(node: WithSrc, type?: 'string'): string;101 readOriginal(node: WithSrc, type: 'buffer'): Buffer;102 readOriginal(node: WithSrc, type: 'string' | 'buffer' = 'string'): string | Buffer {103 const { source, start, length } = this.decodeSrc(node.src);104 const { originalBuf } = this.state[source];105 const buf = originalBuf.slice(start, start + length);106 if (type === 'buffer') {107 return buf;108 } else {109 return buf.toString('utf8');110 }111 }112 read(node: WithSrc): string {113 const { source, ...bounds } = this.decodeSrc(node.src);114 const { shifts, transformations, content } = this.state[source];115 const incompatible = (t: Transformation) => {116 const c = compareContainment(t, bounds);...
compiler.js
Source:compiler.js
...13try {14 fs.mkdirSync(compiler.outputPath);15}16catch(ex){}17function readOriginal(cb) {18 fs.readdir(compiler.outputPath, function (err, files) {19 if (err) throw err;20 var fil = {};21 for (var i in files) {22 fil[files[i]] = path.join(compiler.outputPath, files[i]);23 }24 parseFiles(fil);25 if (cb) cb();26 });27}28function generateManifestFile(entries){29 let files = Object.keys(entries)30 .map(function(e){ return "/" + e; })31 .join("\n");32 module.exports.manifestFile = manifestTemplate.replace("{{files}}", files);33}34function parseFiles(filemap, removeOld) {35 var files = Object.keys(filemap);36 var oldFiles = Object.keys(module.exports.files);37 var entries = {};38 for (var i in files) {39 let match = /\.(.*)\.entry\.(?!.*\.map)/.exec(files[i]);40 if (match && match[1]) {41 entries[match[1]] = files[i];42 }43 }44 if (removeOld) {45 for (var i in oldFiles) {46 var curFile = oldFiles[i];47 if (files.indexOf(curFile) == -1) fs.unlink(module.exports.files[curFile]);48 }49 }50 module.exports.files = filemap;51 module.exports.entries = entries;52 generateManifestFile(filemap);53}54function compiled(err, stats) {55 if (err) throw err;56 var files = {};57 for (var i in stats.compilation.assets) {58 files[i] = stats.compilation.assets[i].existsAt;59 }60 console.log("Compiled. Took " + (stats.endTime - stats.startTime) + " ms.");61 parseFiles(files, true);62}63module.exports.watch = function () {64 readOriginal(function () {65 compiler.watch({}, compiled);66 });67};68module.exports.build = function () {69 readOriginal(function () {70 compiler.run(compiled);71 });72};73module.exports.readOnly = function () {74 readOriginal();...
Using AI Code Generation
1const readOriginal = require('stryker-parent').readOriginal;2const originalContent = readOriginal('./test.js');3const readOriginal = require('stryker').readOriginal;4const originalContent = readOriginal('./test.js');5const readOriginal = require('stryker-api').readOriginal;6const originalContent = readOriginal('./test.js');
Using AI Code Generation
1var parent = require("stryker-parent");2var str = "Hello World";3console.log(parent.readOriginal(str));4var parent = require("stryker-parent");5var str = "Hello World";6console.log(parent.readOriginal(str));7var parent = require("stryker-parent");8var str = "Hello World";9console.log(parent.readOriginal(str));10var parent = require("stryker-parent");11var str = "Hello World";12console.log(parent.readOriginal(str));13var parent = require("stryker-parent");14var str = "Hello World";15console.log(parent.readOriginal(str));16var parent = require("stryker-parent");17var str = "Hello World";18console.log(parent.readOriginal(str));19var parent = require("stryker-parent");20var str = "Hello World";21console.log(parent.readOriginal(str));22var parent = require("stryker-parent");23var str = "Hello World";24console.log(parent.readOriginal(str));25var parent = require("stryker-parent");26var str = "Hello World";27console.log(parent.readOriginal(str));28var parent = require("stryker-parent");29var str = "Hello World";30console.log(parent.readOriginal(str));31var parent = require("stryker-parent");32var str = "Hello World";33console.log(parent.readOriginal(str));34var parent = require("stryker-parent");35var str = "Hello World";36console.log(parent.readOriginal(str));
Using AI Code Generation
1var stryker = require('stryker-parent');2var strykerOptions = {3};4var strykerConfig = new stryker.StrykerConfig(strykerOptions);5var stryker = new stryker.Stryker(strykerConfig);6stryker.runMutationTest();
Using AI Code Generation
1var strykerParent = require('stryker-parent');2var original = strykerParent.readOriginal('path/to/file.js');3console.log(original);4var strykerParent = require('stryker-parent');5var original = strykerParent.readOriginal('path/to/file.js');6console.log(original);7var strykerParent = require('stryker-parent');8var original = strykerParent.readOriginal('path/to/file.js');9console.log(original);10var strykerParent = require('stryker-parent');11var original = strykerParent.readOriginal('path/to/file.js');12console.log(original);13var strykerParent = require('stryker-parent');14var original = strykerParent.readOriginal('path/to/file.js');15console.log(original);16var strykerParent = require('stryker-parent');17var original = strykerParent.readOriginal('path/to/file.js');18console.log(original);19var strykerParent = require('stryker-parent');20var original = strykerParent.readOriginal('path/to/file.js');21console.log(original);22var strykerParent = require('stryker-parent');23var original = strykerParent.readOriginal('path/to/file.js');24console.log(original);25var strykerParent = require('stryker-parent');26var original = strykerParent.readOriginal('path/to/file.js');27console.log(original);28var strykerParent = require('stryker-parent');29var original = strykerParent.readOriginal('path/to/file.js');30console.log(original);
Using AI Code Generation
1const strykerParent = require('stryker-parent');2const original = strykerParent.readOriginal('path/to/your/file.js');3console.log(original);4const strykerParent = require('stryker-parent');5const original = strykerParent.readOriginal('path/to/your/file.js');6console.log(original);
Using AI Code Generation
1const strykerParent = require('stryker-parent');2strykerParent.readOriginal('stryker-parent');3exports.readOriginal = function readOriginal(moduleName) {4};5exports.readOriginal = function readOriginal(moduleName) {6};7exports.readOriginal = function readOriginal(moduleName) {8};9exports.readOriginal = function readOriginal(moduleName) {10};11exports.readOriginal = function readOriginal(moduleName) {12};13exports.readOriginal = function readOriginal(moduleName) {14};
Using AI Code Generation
1var parent = require('stryker-parent');2var str = 'This is a test string';3var orig = parent.readOriginal(str);4console.log(orig);5var child = require('stryker-child');6exports.readOriginal = function(str) {7 return child.readOriginal(str);8}9var parent = require('stryker-parent');10exports.readOriginal = function(str) {11 return parent.readOriginal(str);12}13var parent = require('../node_modules/stryker-parent');14var str = 'This is a test string';15var orig = parent.readOriginal(str);16console.log(orig);17var parent = require('./node_modules/stryker-parent');18var str = 'This is a test string';19var orig = parent.readOriginal(str);20console.log(orig);21var parent = require('/node_modules/stryker-parent');22var str = 'This is a test string';23var orig = parent.readOriginal(str);24console.log(orig);25var parent = require('node_modules/stryker-parent');26var str = 'This is a test string';27var orig = parent.readOriginal(str);28console.log(orig);29var parent = require('/node_modules/stryker-parent/index.js');30var str = 'This is a test string';31var orig = parent.readOriginal(str);32console.log(orig);33var parent = require('/node_modules/stryker-parent/index.js');
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!