How to use the @stryker-mutator/api/core.File function in @stryker-mutator/api

To help you get started, we’ve selected a few @stryker-mutator/api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stryker-mutator / stryker / packages / babel-transpiler / src / BabelTranspiler.ts View on Github external
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);
    }
  }
github stryker-mutator / stryker / packages / api / testResources / module / useCore.ts View on Github external
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);
github stryker-mutator / stryker / packages / api / testResources / module / useTranspile.ts View on Github external
public transpile(files: ReadonlyArray): Promise> {
    return Promise.resolve([new File('foo/bar.js', 'bar content')]);
  }
}
github stryker-mutator / stryker / packages / typescript / src / transpiler / TranspilingLanguageService.ts View on Github external
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}`);
    }
  }
github stryker-mutator / stryker / packages / typescript / src / transpiler / TranspilingLanguageService.ts View on Github external
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}`);
    }
  }
github stryker-mutator / stryker / packages / core / src / transpiler / CoverageInstrumenterTranspiler.ts View on Github external
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);
    }
  }
github stryker-mutator / stryker / packages / core / src / input / InputFileResolver.ts View on Github external
      .then((content: Buffer) => new File(fileName, content))
      .then((file: File) => {
github stryker-mutator / stryker / packages / core / src / transpiler / MutantTranspileScheduler.ts View on Github external
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) });
    }
  }
}