Skip to content

Commit

Permalink
fix(typescript-checker): support empty files (#2310)
Browse files Browse the repository at this point in the history
Fix for `inner error: TypeError: Cannot read property 'modifiedTime' of undefined` error.
  • Loading branch information
nicojs committed Jul 10, 2020
1 parent 13c780d commit 284a28c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
4 changes: 4 additions & 0 deletions e2e/test/vue-cli-typescript-mocha/stryker.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"testRunner": "mocha",
"concurrency": 2,
"coverageAnalysis": "perTest",
"symlinkNodeModules": false,
"reporters": ["progress", "clear-text", "event-recorder"],
"buildCommand": "webpack --config webpack.test.config.js",
"mochaOptions": {
Expand All @@ -21,5 +22,8 @@
"plugins": [
"@stryker-mutator/mocha-runner",
"@stryker-mutator/typescript-checker"
],
"checkers": [
"typescript"
]
}
8 changes: 4 additions & 4 deletions e2e/test/vue-cli-typescript-mocha/verify/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ describe('Verify stryker has ran correctly', () => {

it('should report correct score', async () => {
await expectMetrics({
killed: 4,
killed: 2,
survived: 1,
noCoverage: 12,
compileErrors: 0,
noCoverage: 11,
compileErrors: 3,
runtimeErrors: 0,
timeout: 0,
mutationScore: 23.53
mutationScore: 14.29
});
});
});
2 changes: 1 addition & 1 deletion packages/typescript-checker/src/fs/hybrid-file-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class HybridFileSystem {
fileName = toTSFileName(fileName);
if (!this.files.has(fileName)) {
let content = ts.sys.readFile(fileName);
if (content) {
if (typeof content === 'string') {
let modifiedTime = ts.sys.getModifiedTime!(fileName)!;
this.files.set(fileName, new ScriptFile(content, fileName, modifiedTime));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ describe('fs', () => {
expect(helper.getModifiedTimeStub).calledWith('test/foo/a.js');
});

it('should support empty files', () => {
helper.readFileStub.returns('');
helper.getModifiedTimeStub.returns(new Date(2010, 1, 1));
const actual = sut.getFile('foo.js');
expect(actual).ok;
expect(actual!.fileName).eq('foo.js');
expect(actual!.content).eq('');
});

it("should cache a file that doesn't exists", () => {
sut.getFile('not-exists.js');
sut.getFile('not-exists.js');
Expand Down

0 comments on commit 284a28c

Please sign in to comment.