Skip to content

Commit

Permalink
fix(api): allow for different api versions of File (#2042)
Browse files Browse the repository at this point in the history
Customize the way we serialize files to make sure different versions of `stryker-api` can be mixed and matched (although not recommended).

Fixes #2025

Co-authored-by: Simon de Lang <simondelang@gmail.com>
  • Loading branch information
nicojs and simondel committed Feb 16, 2020
1 parent 9eb9b2b commit 9d1fcc1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
},
"dependencies": {
"mutation-testing-report-schema": "^1.1.0",
"surrial": "^2.0.1",
"tslib": "~1.10.0"
},
"devDependencies": {
"@types/node": "^13.7.1",
"surrial": "~1.0.0",
"typed-inject": "~2.1.1"
}
}
12 changes: 11 additions & 1 deletion packages/api/src/core/File.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Surrializable, surrial } from 'surrial';

/**
* Represents a file within Stryker. Could be a strictly in-memory file.
*/
export default class File {
export default class File implements Surrializable {
private _textContent: string | undefined;
private readonly _content: Buffer;

Expand Down Expand Up @@ -35,4 +37,12 @@ export default class File {
}
return this._textContent;
}

/**
* This fixes the issue of different File versions not being compatible.
* @see https://github.com/stryker-mutator/stryker/issues/2025
*/
public surrialize(): string {
return surrial`new File(${this.name}, ${this.content})`;
}
}
8 changes: 8 additions & 0 deletions packages/api/test/unit/core/File.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,13 @@ describe('File', () => {
const serialized = serialize(expected);
const actual = deserialize(serialized, [File]);
expect(actual).deep.eq(expected);
expect(actual).instanceOf(File);
});

/**
* @see https://github.com/stryker-mutator/stryker/issues/2025
*/
it('should customize serialization to allow different instances of the class file to be compatible', () => {
expect(new File('foo', Buffer.from('bar')).surrialize()).eq('new File("foo", Buffer.from("bar", "binary"))');
});
});
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"rimraf": "~3.0.0",
"rxjs": "~6.5.1",
"source-map": "~0.7.3",
"surrial": "~1.0.0",
"surrial": "^2.0.1",
"tree-kill": "~1.2.0",
"tslib": "~1.10.0",
"typed-inject": "~2.1.1",
Expand Down
7 changes: 6 additions & 1 deletion workspace.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,12 @@
"task.autoDetect": "off",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
},
"cSpell.words": [
"Surrializable",
"serializable",
"surrialize"
]
},
"extensions": {
"recommendations": [
Expand Down

0 comments on commit 9d1fcc1

Please sign in to comment.