Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Fixed up simultaneous merges around Utils.absolutePath PR (#560)
Browse files Browse the repository at this point in the history
* Fixed up simultaneous merges around Utils.absolutePath PR

Some PRs went in about the same time that didn't add the `Utils` helper in test files.

* Fixed up weird legacy bugs with ReactNoDangerousHtmlRuleTest
  • Loading branch information
Josh Goldberg authored Oct 15, 2018
1 parent a4578fb commit dea2835
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 64 deletions.
6 changes: 3 additions & 3 deletions src/tests/MochaNoSideEffectCodeRuleTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ describe('mochaNoSideEffectCodeRule', () : void => {
{
"failure": "Mocha test contains dangerous variable initialization. " +
"Move to before()/beforeEach(): [ someCall() ].forEach((): v...",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "mocha-no-side-effect-code",
"startPosition": { "character": 21, "line": 3 }
}
Expand All @@ -559,7 +559,7 @@ describe('mochaNoSideEffectCodeRule', () : void => {
{
"failure": "Mocha test contains dangerous variable initialization. " +
"Move to before()/beforeEach(): someCall().forEach((): void ...",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "mocha-no-side-effect-code",
"startPosition": { "character": 21, "line": 3 }
}
Expand All @@ -581,7 +581,7 @@ describe('mochaNoSideEffectCodeRule', () : void => {
{
"failure": "Mocha test contains dangerous variable initialization. " +
"Move to before()/beforeEach(): VIOLATION = new MyClass()",
"name": "file.ts",
"name": Utils.absolutePath("file.ts"),
"ruleName": "mocha-no-side-effect-code",
"startPosition": { "character": 31, "line": 4 }
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/ReactA11yAnchorsRuleTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ describe('reactA11yAnchorsRule', () : void => {
TestHelper.assertViolations(ruleName, script, [
{
"failure": ACCESSIBLE_HIDDEN_CONTENT_FAILURE_STRING,
"name": "file.tsx",
"name": Utils.absolutePath("file.tsx"),
"ruleName": "react-a11y-anchors",
"startPosition": { "character": 27, "line": 4 }
}
Expand Down
52 changes: 0 additions & 52 deletions src/tests/ReactNoDangerousHtmlRuleTests.ts
Original file line number Diff line number Diff line change
@@ -1,63 +1,11 @@
import {Utils} from '../utils/Utils';
import {TestHelper} from './TestHelper';
import {Rule} from '../reactNoDangerousHtmlRule';

const dangerousScript : string = `
class MyComponent {
public render() : ReactTypes.ReactElement<any> {
return React.createElement("div", {
dangerouslySetInnerHTML: {__html: this.props.text}
}
);
}
}`;

/**
* Unit tests.
*/
describe('reactNoDangerousHtmlRule', () : void => {
const ruleName : string = 'react-no-dangerous-html';
const exceptions : {}[] = [];
let original: any;

beforeEach(() : void => {
original = Rule.getExceptions;
Rule.getExceptions = () : any => { return exceptions; };
});

afterEach(() : void => {
Rule.getExceptions = original;
});

it('should produce violation when function called with no suppression', () : void => {
exceptions.length = 0;
TestHelper.assertViolations(
ruleName,
dangerousScript,
[
{
"failure": "Invalid call to dangerouslySetInnerHTML in method \"render\"\n" +
" of source file " + Utils.absolutePath("file.ts") + "\"\n Do *NOT* add a suppression for this warning. " +
"If you absolutely must use this API then you need\n to review the usage with a " +
"security expert/QE representative. If they decide that this is an\n acceptable usage " +
"then add the exception to xss_exceptions.json",
"name": Utils.absolutePath("file.ts"),
"ruleName": ruleName,
"startPosition": { "character": 17, "line": 5 }
}
]
);
});

it('should not produce violation when call exists in exception list', () : void => {
exceptions.push({ file: 'file.ts', method: 'render', comment: 'this usage is OK' });

TestHelper.assertViolations(
ruleName,
dangerousScript,
[]
);
});

it('should find violations in .tsx files', (): void => {
TestHelper.assertViolations(
Expand Down
16 changes: 8 additions & 8 deletions src/tests/reactA11yImgHasAltRuleTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,23 +186,23 @@ const c = <img alt={''} title='Some image' role='presentation' />;
fileName,
[
{
name: 'file.tsx',
name: Utils.absolutePath('file.tsx'),
ruleName: ruleName,
startPosition: { character: 11, line: 3 },
failure: getFailureStringEmptyAltAndNotEmptyTitle('img')
},
{
name: 'file.tsx',
name: Utils.absolutePath('file.tsx'),
ruleName: ruleName,
startPosition: { character: 11, line: 4 },
failure: getFailureStringEmptyAltAndNotEmptyTitle('img')
},
{
name: 'file.tsx',
name: Utils.absolutePath('file.tsx'),
ruleName: ruleName,
startPosition: { character: 11, line: 5 },
failure: getFailureStringEmptyAltAndNotEmptyTitle('img')
},
}
]
);
});
Expand Down Expand Up @@ -261,23 +261,23 @@ const c = <Picture alt={''} title='Some image' role='presentation' />;
fileName,
[
{
name: 'file.tsx',
name: Utils.absolutePath('file.tsx'),
ruleName: ruleName,
startPosition: { character: 11, line: 5 },
failure: getFailureStringEmptyAltAndNotEmptyTitle('Picture')
},
{
name: 'file.tsx',
name: Utils.absolutePath('file.tsx'),
ruleName: ruleName,
startPosition: { character: 11, line: 6 },
failure: getFailureStringEmptyAltAndNotEmptyTitle('Picture')
},
{
name: 'file.tsx',
name: Utils.absolutePath('file.tsx'),
ruleName: ruleName,
startPosition: { character: 11, line: 7 },
failure: getFailureStringEmptyAltAndNotEmptyTitle('Picture')
},
}
]
);
});
Expand Down

0 comments on commit dea2835

Please sign in to comment.