Skip to content
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

fix(string-literal-mutator): don't mutate class property keys #2544

Merged
merged 1 commit into from Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -40,6 +40,7 @@ export class StringLiteralMutator implements NodeMutator {
types.isExpressionStatement(parent) ||
types.isTSLiteralType(parent) ||
(types.isObjectProperty(parent) && parent.key === child.node) ||
(types.isClassProperty(parent) && parent.key === child.node) ||
(types.isCallExpression(parent) && types.isIdentifier(parent.callee, { name: 'require' }))
);
}
Expand Down
Expand Up @@ -55,6 +55,9 @@ describe('instrumenter integration', () => {
it('should be able to instrument switch case statements (using the switchCaseMutantPlacer)', async () => {
await arrangeAndActAssert('switch-case.js');
});
it('should be able to instrument string literals in different places', async () => {
await arrangeAndActAssert('string-mutations.ts');
});

describe('type declarations', () => {
it('should not produce mutants for TS type definitions', async () => {
Expand Down
Expand Up @@ -87,6 +87,12 @@ describe(StringLiteralMutator.name, () => {
it('should still mutate inside object property values', () => {
expectJSMutation(sut, 'const foo = { bar: "baz" };', 'const foo = { bar: "" };');
});
it('should not mutate class property keys', () => {
expectJSMutation(sut, 'class Foo { "baz-bar" = 4; }');
});
it('should mutate class property values', () => {
expectJSMutation(sut, 'class Foo { bar = "4"; }', 'class Foo { bar = ""; }');
});
});

describe('jsx', () => {
Expand Down
@@ -0,0 +1,7 @@
require('foo'); // no mutation
import 'foo'; // no mutation

class Foo {
public 'bar-baz': string; // no mutation
}

@@ -0,0 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`instrumenter integration should be able to instrument string literals in different places 1`] = `
"require('foo'); // no mutation


import 'foo'; // no mutation

class Foo {
public 'bar-baz': string; // no mutation

}"
`;