-
Notifications
You must be signed in to change notification settings - Fork 250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(coverage analysis): Support transpiled code #559
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
07b758c
feat(coverage analysis): Implement coverage analysis with one
nicojs eb50f13
test(SourceMapper): Add integration test for SourceMapper
nicojs 9c79c25
test(initial test): Only produce source maps when needed
nicojs dd85bf4
test(SourceMapper): Add source mapper unit tests
nicojs 06aa187
refactor(MutantTestMatcher)
nicojs 0ab97db
feat(early result): Don't run when not needed
nicojs 07340ea
fix(build): Fix compiler warning
nicojs 5f401ec
refactor(typescript): review comments
nicojs 8a5260d
refactor(stryker): Refactor source mapping logic
nicojs bef6025
docs(stryker-api): Update jsdoc of `produceSourceMaps`
nicojs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,60 @@ | ||
import flatMap = require('lodash.flatmap'); | ||
import { Config } from 'stryker-api/config'; | ||
import { Transpiler, TranspileResult, TranspilerOptions, FileLocation } from 'stryker-api/transpile'; | ||
import { Transpiler, TranspileResult, TranspilerOptions } from 'stryker-api/transpile'; | ||
import { File } from 'stryker-api/core'; | ||
import { filterTypescriptFiles, getCompilerOptions, getProjectDirectory, filterNotEmpty, isHeaderFile, guardTypescriptVersion, isTypescriptFile } from './helpers/tsHelpers'; | ||
import { filterTypescriptFiles, getCompilerOptions, getProjectDirectory, isHeaderFile, guardTypescriptVersion, isTypescriptFile } from './helpers/tsHelpers'; | ||
import TranspilingLanguageService from './transpiler/TranspilingLanguageService'; | ||
import { setGlobalLogLevel } from 'log4js'; | ||
|
||
export default class TypescriptTranspiler implements Transpiler { | ||
private languageService: TranspilingLanguageService; | ||
private readonly next: Transpiler; | ||
private readonly config: Config; | ||
private readonly keepSourceMaps: boolean; | ||
private readonly produceSourceMaps: boolean; | ||
|
||
constructor(options: TranspilerOptions) { | ||
guardTypescriptVersion(); | ||
setGlobalLogLevel(options.config.logLevel); | ||
this.config = options.config; | ||
this.keepSourceMaps = options.keepSourceMaps; | ||
this.produceSourceMaps = options.produceSourceMaps; | ||
} | ||
|
||
transpile(files: File[]): Promise<TranspileResult> { | ||
const typescriptFiles = filterTypescriptFiles(files) | ||
.filter(file => file.transpiled); | ||
if (!this.languageService) { | ||
this.languageService = new TranspilingLanguageService( | ||
getCompilerOptions(this.config), typescriptFiles, getProjectDirectory(this.config), this.keepSourceMaps); | ||
getCompilerOptions(this.config), typescriptFiles, getProjectDirectory(this.config), this.produceSourceMaps); | ||
} else { | ||
this.languageService.replace(typescriptFiles); | ||
} | ||
return Promise.resolve(this.transpileAndResult(typescriptFiles, files)); | ||
} | ||
|
||
getMappedLocation(sourceFileLocation: FileLocation): FileLocation { | ||
const outputLocation = this.languageService.getMappedLocationFor(sourceFileLocation); | ||
if (outputLocation) { | ||
return this.next.getMappedLocation(outputLocation); | ||
} else { | ||
throw new Error(`Could not find mapped location for ${sourceFileLocation.fileName}:${sourceFileLocation.start.line}:${sourceFileLocation.start.column}`); | ||
} | ||
} | ||
|
||
private transpileAndResult(typescriptFiles: File[], allFiles: File[]) { | ||
const error = this.languageService.getSemanticDiagnostics(typescriptFiles.map(file => file.name)); | ||
if (error.length) { | ||
return this.createErrorResult(error); | ||
} else { | ||
const implementationFiles = typescriptFiles.filter(file => !isHeaderFile(file)); | ||
const outputFiles = this.languageService.emit(implementationFiles); | ||
// Keep original order of the files | ||
const resultFiles = filterNotEmpty(allFiles.map(file => { | ||
if (file.transpiled && isTypescriptFile(file)) { | ||
return outputFiles[file.name]; | ||
let moreOutput = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps |
||
const resultFiles: File[] = flatMap(allFiles, file => { | ||
if (isHeaderFile(file)) { | ||
// Header files are not compiled to output | ||
return []; | ||
} else if (file.transpiled && isTypescriptFile(file)) { | ||
// File is a typescript file. Only emit if more output is expected. | ||
if (moreOutput) { | ||
const emitOutput = this.languageService.emit(file); | ||
moreOutput = !emitOutput.singleResult; | ||
return emitOutput.outputFiles; | ||
} else { | ||
return []; | ||
} | ||
} else { | ||
return file; | ||
// File is not a typescript file | ||
return [file]; | ||
} | ||
})); | ||
}); | ||
return this.createSuccessResult(resultFiles); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment seems to be out of date