Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private transpileFile(file: File) {
const relativeOptions: babel.TransformOptions = {
cwd: this.projectRoot,
filename: file.name,
filenameRelative: path.relative(this.projectRoot, file.name)
};
const options: babel.TransformOptions = { ...this.babelConfig.options, ...relativeOptions };
const result: babel.BabelFileResult | null = babel.transformSync(file.textContent, options);
if (!result) {
// File is ignored by babel
return file;
} else if (result.code === undefined || result.code === null) {
throw new Error(`Could not transpile file "${file.name}". Babel transform function delivered \`undefined\`.`);
} else {
return new File(toJSFileName(file.name), result.code);
}
}
testRunner: 'command',
thresholds: { high: 80, low: 20, break: null},
timeoutFactor: 1.5,
timeoutMS: 5000,
transpilers: [],
dashboard: {
baseUrl: 'baseUrl',
reportType: ReportType.MutationScore,
module: 'module',
project: 'project',
version: 'version'
},
tempDirName: '.stryker-tmp',
};
const textFile: File = new File('foo/bar.js', Buffer.from('foobar'));
const range: Range = [1, 2];
const position: Position = { column: 2, line: 2 };
const location: Location = { start: position, end: position };
console.log(range, position, location, textFile, optionsAllArgs);
public transpile(files: ReadonlyArray): Promise> {
return Promise.resolve([new File('foo/bar.js', 'bar content')]);
}
}
export function file() {
return new File('', '');
}
public emit(fileName: string): EmitOutput {
const emittedFiles = this.languageService.getEmitOutput(fileName).outputFiles;
const jsFile = emittedFiles.find(isJavaScriptFile);
const mapFile = emittedFiles.find(isMapFile);
if (jsFile) {
const outputFiles: File[] = [new File(normalizeFileFromTypescript(jsFile.name), jsFile.text)];
if (mapFile) {
outputFiles.push(new File(normalizeFileFromTypescript(mapFile.name), mapFile.text));
}
return { singleResult: !!this.compilerOptions.outFile, outputFiles };
} else {
throw new Error(`Emit error! Could not emit file ${fileName}`);
}
}
public emit(fileName: string): EmitOutput {
const emittedFiles = this.languageService.getEmitOutput(fileName).outputFiles;
const jsFile = emittedFiles.find(isJavaScriptFile);
const mapFile = emittedFiles.find(isMapFile);
if (jsFile) {
const outputFiles: File[] = [new File(normalizeFileFromTypescript(jsFile.name), jsFile.text)];
if (mapFile) {
outputFiles.push(new File(normalizeFileFromTypescript(mapFile.name), mapFile.text));
}
return { singleResult: !!this.compilerOptions.outFile, outputFiles };
} else {
throw new Error(`Emit error! Could not emit file ${fileName}`);
}
}
private instrumentFile(sourceFile: File): File {
try {
const content = this.instrumenter.instrumentSync(sourceFile.textContent, sourceFile.name);
const fileCoverage = this.patchRanges(this.instrumenter.lastFileCoverage());
this.fileCoverageMaps[sourceFile.name] = this.retrieveCoverageMaps(fileCoverage);
return new File(sourceFile.name, Buffer.from(content));
} catch (error) {
throw new StrykerError(`Could not instrument "${sourceFile.name}" for code coverage`, error);
}
}
.then((content: Buffer) => new File(fileName, content))
.then((file: File) => {
private async transpileMutant(mutant: TestableMutant): Promise {
const filesToTranspile: File[] = [];
if (this.currentMutatedFile && this.currentMutatedFile.name !== mutant.fileName) {
filesToTranspile.push(this.currentMutatedFile.file);
}
this.currentMutatedFile = mutant.sourceFile;
const mutatedFile = new File(mutant.fileName, Buffer.from(mutant.mutatedCode));
filesToTranspile.push(mutatedFile);
try {
const transpiledFiles = await this.transpiler.transpile(filesToTranspile);
return this.createTranspiledMutant(mutant, { outputFiles: transpiledFiles, error: null });
} catch (error) {
return this.createTranspiledMutant(mutant, { outputFiles: [], error: errorToString(error) });
}
}
}