Skip to content
Permalink
Browse files

Chore: Refactor location tests to match similar text

Makes it easier to write tests with correct location
information by allowing tests to provide substrings
representing where a report should occur.

Previously tests had hard-coded locations which were
prone to mistakes due to difficulty visualizing how
they aligned with the actual text in a file.
  • Loading branch information...
antross committed Feb 24, 2019
1 parent 9af363d commit ae5124479d63d9d4bdafa0cac211eb2857485f50
Showing with 214 additions and 172 deletions.
  1. +1 βˆ’0 packages/hint-amp-validator/tests/tests.ts
  2. +6 βˆ’24 packages/hint-babel-config/tests/is-valid.ts
  3. +14 βˆ’14 packages/hint-compat-api/tests/css-next.ts
  4. +12 βˆ’12 packages/hint-compat-api/tests/css.ts
  5. +1 βˆ’1 packages/hint-compat-api/tests/fixtures/css/appearance-splitted.css
  6. +2 βˆ’2 packages/hint-compat-api/tests/fixtures/css/appearance.css
  7. +1 βˆ’1 packages/hint-compat-api/tests/fixtures/css/box-flex-prefixes.css
  8. +7 βˆ’7 packages/hint-compat-api/tests/html-next.ts
  9. +5 βˆ’5 packages/hint-compat-api/tests/html.ts
  10. +1 βˆ’1 packages/hint-css-prefix-order/tests/fixtures/interleaved-prefixes.css
  11. +1 βˆ’1 packages/hint-css-prefix-order/tests/fixtures/mixed-with-prefixes-last.css
  12. +2 βˆ’2 packages/hint-css-prefix-order/tests/fixtures/multi-block.css
  13. +2 βˆ’2 packages/hint-css-prefix-order/tests/fixtures/multi-property.css
  14. +1 βˆ’1 packages/hint-css-prefix-order/tests/fixtures/prefixed-values-last.css
  15. +1 βˆ’1 packages/hint-css-prefix-order/tests/fixtures/prefixes-last-moz.css
  16. +1 βˆ’1 packages/hint-css-prefix-order/tests/fixtures/prefixes-last-same-line.css
  17. +1 βˆ’1 packages/hint-css-prefix-order/tests/fixtures/prefixes-last-webkit.css
  18. +10 βˆ’40 packages/hint-css-prefix-order/tests/tests.ts
  19. +3 βˆ’3 packages/hint-doctype/tests/tests.ts
  20. +3 βˆ’12 packages/hint-manifest-is-valid/tests/tests.ts
  21. +3 βˆ’3 packages/hint-no-protocol-relative-urls/tests/tests.ts
  22. +4 βˆ’16 packages/hint-typescript-config/tests/is-valid.ts
  23. +1 βˆ’4 packages/hint-typescript-config/tests/no-comments.ts
  24. +37 βˆ’1 packages/hint/docs/contributor-guide/how-to/test-rules.md
  25. +88 βˆ’16 packages/utils-tests-helpers/src/hint-runner.ts
  26. +6 βˆ’1 packages/utils-tests-helpers/src/hint-test-type.ts
@@ -25,6 +25,7 @@ const defaultTests: HintTest[] = [
reports: [
{
message: `The mandatory attribute '⚑' is missing in tag 'html'. (https://www.ampproject.org/docs/reference/spec#required-markup)`,
// TODO: position: { match: '<html lang="en">' } // { column: 0, line: 1 }
position: {
column: 0,
line: 2
@@ -16,10 +16,7 @@ const tests: HintLocalTest[] = [
path: path.join(__dirname, 'fixtures', 'invalid-schema', '.babelrc'),
reports: [{
message: `'moduleId' should be 'string'.`,
position: {
column: 5,
line: 4
}
position: { match: 'moduleId' }
}]
},
{
@@ -40,32 +37,23 @@ const tests: HintLocalTest[] = [
path: path.join(__dirname, 'fixtures', 'has-invalid-babel-package-json', 'package.json'),
reports: [{
message: `'moduleId' should be 'string'.`,
position: {
column: 5,
line: 3
}
position: { match: 'moduleId' }
}]
},
{
name: `If .babelrc contains an additional property, it should fail`,
path: path.join(__dirname, 'fixtures', 'has-additional-property', '.babelrc'),
reports: [{
message: `'root' should NOT have additional properties. Additional property found 'additional'.`,
position: {
column: 5,
line: 10
}
position: { match: 'additional' }
}]
},
{
name: `If .babelrc contains an invalid value, it should fail`,
path: path.join(__dirname, 'fixtures', 'has-invalid-enum-property', '.babelrc'),
reports: [{
message: `'sourceMaps' should be equal to one of the allowed values 'both, inline, true, false'. Value found 'invalidValue'`,
position: {
column: 5,
line: 14
}
position: { match: 'sourceMaps' }
}]
},
{
@@ -74,10 +62,7 @@ const tests: HintLocalTest[] = [
reports: [
{
message: `Circular reference found in file ${path.join(__dirname, 'fixtures', 'circular-2', '.babelrc')}`,
position: {
column: 3,
line: 1
}
position: { match: 'extends' }
}
]
},
@@ -87,10 +72,7 @@ const tests: HintLocalTest[] = [
reports: [
{
message: `Unexpected token ' in JSON at position 191`,
position: {
column: 3,
line: 1
}
position: { match: 'extends' }
}
]
}
@@ -170,9 +170,9 @@ const featureVersionAddedLaterThanTargetedBrowsers: HintTest[] = [
{
name: 'Features that were added after the targeted browser should fail.',
reports: [
{ message: 'keyframes is not supported by chrome 40.', position: { column: 0, line: 0 }},
{ message: 'keyframes is not supported by chrome 40.', position: { column: 0, line: 6 }},
{ message: 'keyframes is not supported by chrome 40.', position: { column: 0, line: 12 }}
{ message: 'keyframes is not supported by chrome 40.', position: { match: '@keyframes name' }},
{ message: 'keyframes is not supported by chrome 40.', position: { match: '@keyframes name2' }},
{ message: 'keyframes is not supported by chrome 40.', position: { match: '@keyframes name3' }}
],
serverConfig: generateCSSConfig('keyframes')
}
@@ -183,7 +183,7 @@ hintRunner.testHint(hintPath, featureVersionAddedLaterThanTargetedBrowsers, { br
const prefixedFeatureVersionAddedLaterThanTargetedBrowsers: HintTest[] = [
{
name: 'Prefixed features that were added after the targeted browser should fail.',
reports: [{ message: 'animation-duration prefixed with -webkit- is not supported by opera 12.', position: { column: 4, line: 1 }}],
reports: [{ message: 'animation-duration prefixed with -webkit- is not supported by opera 12.', position: { match: '-webkit-animation-duration' }}],
serverConfig: generateCSSConfig('animation-duration-prefix')
}
];
@@ -211,7 +211,7 @@ hintRunner.testHint(hintPath, prefixedFeaturesThatBecameStandardAndMarkedAsDepre
const childFeatureAddedLaterThanTargetedBrowsers: HintTest[] = [
{
name: 'Child features that were added later than targeted browsers should fail.',
reports: [{ message: 'flex is not supported by chrome 26-28.', position: { column: 4, line: 1 } }],
reports: [{ message: 'flex is not supported by chrome 26-28.', position: { match: 'display: flex;' } }],
serverConfig: generateCSSConfig('display-flex')
}
];
@@ -221,7 +221,7 @@ hintRunner.testHint(hintPath, childFeatureAddedLaterThanTargetedBrowsers, { brow
const childPrefixedFeatureAddedLaterThanTargetedBrowsers: HintTest[] = [
{
name: 'Child prefixed features that were added later than targeted browsers should fail.',
reports: [{ message: 'flex prefixed with -webkit- is not supported by chrome 17-19.', position: { column: 4, line: 1 } }],
reports: [{ message: 'flex prefixed with -webkit- is not supported by chrome 17-19.', position: { match: 'display: -webkit-flex;' } }],
serverConfig: generateCSSConfig('display-flex-prefix')
}
];
@@ -231,7 +231,7 @@ hintRunner.testHint(hintPath, childPrefixedFeatureAddedLaterThanTargetedBrowsers
const notSupportedPropertiesAndValuesShouldNotSeparatelyLog: HintTest[] = [
{
name: 'Features not supported and not deprecated should not separately log the feature and value.',
reports: [{ message: 'appearance is not supported by ie.', position: { column: 4, line: 3 }}],
reports: [{ message: 'appearance is not supported by ie.', position: { match: 'appearance: none; /* Report */' }}],
serverConfig: generateCSSConfig('appearance')
}
];
@@ -242,8 +242,8 @@ const notSupportedFeaturesWithoutFallbackShouldSeparatelyLog: HintTest[] = [
{
name: 'Features not supported and not deprecated should separately log vendor prefixes if fallback is not defined.',
reports: [
{ message: 'appearance prefixed with -webkit- is not supported by ie.', position: { column: 4, line: 1 }},
{ message: 'appearance prefixed with -moz- is not supported by ie.', position: { column: 4, line: 2 }}
{ message: 'appearance prefixed with -webkit- is not supported by ie.', position: { match: '-webkit-appearance' }},
{ message: 'appearance prefixed with -moz- is not supported by ie.', position: { match: '-moz-appearance' }}
],
serverConfig: generateCSSConfig('appearance-only-prefixes')
}
@@ -254,7 +254,7 @@ hintRunner.testHint(hintPath, notSupportedFeaturesWithoutFallbackShouldSeparatel
const notSupportedAndNotDeprecatedFeature: HintTest[] = [
{
name: 'Features not supported and not deprecated should fail.',
reports: [{ message: 'cursor is not supported by webview_android.', position: { column: 4, line: 1 }}],
reports: [{ message: 'cursor is not supported by webview_android.', position: { match: 'cursor' }}],
serverConfig: generateCSSConfig('cursor')
}
];
@@ -269,9 +269,9 @@ const notSupportedFeaturesSplittedByCSSRuleBlock: HintTest[] = [
{
name: 'Should handle reports separately by CSS blocks.',
reports: [
{ message: 'appearance prefixed with -webkit- is not supported by ie.', position: { column: 4, line: 1 }},
{ message: 'appearance prefixed with -moz- is not supported by ie.', position: { column: 4, line: 2 }},
{ message: 'appearance is not supported by ie.', position: { column: 4, line: 6 }}
{ message: 'appearance prefixed with -webkit- is not supported by ie.', position: { match: '-webkit-appearance' }},
{ message: 'appearance prefixed with -moz- is not supported by ie.', position: { match: '-moz-appearance' }},
{ message: 'appearance is not supported by ie.', position: { match: 'appearance: none; /* unprefixed */' }}
],
serverConfig: generateCSSConfig('appearance-splitted')
}
@@ -282,7 +282,7 @@ hintRunner.testHint(hintPath, notSupportedFeaturesSplittedByCSSRuleBlock, { brow
const disorderedNotSupportedFeatures: HintTest[] = [
{
name: 'Should handle disordered vendor prefixes',
reports: [{ message: 'appearance is not supported by ie.', position: { column: 4, line: 1 }}],
reports: [{ message: 'appearance is not supported by ie.', position: { match: 'appearance' }}],
serverConfig: generateCSSConfig('appearance-disordered-prefixes')
}
];
@@ -47,7 +47,7 @@ hintRunner.testHint(hintPath, prefixedFeatureNeverRemoved, { browserslist: ['saf
const featureRemoved: HintTest[] = [
{
name: 'Features that were removed in versions before the targeted browsers should fail.',
reports: [{ message: 'padding-box is not supported by firefox 52.', position: { column: 4, line: 1 }}],
reports: [{ message: 'padding-box is not supported by firefox 52.', position: { match: 'box-sizing: padding-box;' }}],
serverConfig: generateCSSConfig('box-sizing')
}
];
@@ -57,7 +57,7 @@ hintRunner.testHint(hintPath, featureRemoved, { browserslist: ['firefox 52'], pa
const prefixFeatureRemoved: HintTest[] = [
{
name: 'Prefixed features that were removed in versions before the targeted browsers should fail.',
reports: [{ message: 'box-lines prefixed with -webkit- is not supported by chrome 67-69.', position: { column: 4, line: 1 }}],
reports: [{ message: 'box-lines prefixed with -webkit- is not supported by chrome 67-69.', position: { match: '-webkit-box-lines' }}],
serverConfig: generateCSSConfig('box-lines-prefix-current')
}
];
@@ -85,7 +85,7 @@ hintRunner.testHint(hintPath, removedInEarlierVersionsAndAddedLater, { browsersl
const removedForPrefixEqualToTargetedBrowsers: HintTest[] = [
{
name: 'Prefixed features that were removed in a version equal to the targeted browser should fail.',
reports: [{ message: 'keyframes prefixed with -o- is not supported by opera 15.', position: { column: 0, line: 2 }}],
reports: [{ message: 'keyframes prefixed with -o- is not supported by opera 15.', position: { match: '@-o-keyframes' }}],
serverConfig: generateCSSConfig('keyframes-prefix-obsolete')
}
];
@@ -95,7 +95,7 @@ hintRunner.testHint(hintPath, removedForPrefixEqualToTargetedBrowsers, { browser
const removedForPrefixEarlierThanTargetedBrowsers: HintTest[] = [
{
name: 'Prefixed features that were removed in a version earlier than the targeted browser should fail.',
reports: [{ message: 'keyframes prefixed with -o- is not supported by opera 16, opera 18-19.', position: { column: 0, line: 2 }}],
reports: [{ message: 'keyframes prefixed with -o- is not supported by opera 16, opera 18-19.', position: { match: '@-o-keyframes' }}],
serverConfig: generateCSSConfig('keyframes-prefix-obsolete')
}
];
@@ -154,7 +154,7 @@ hintRunner.testHint(hintPath, prefixedFeatureThatBecameStandardAfterTarget, { br
const prefixedFeaturesThatBecameStandardAndPrefixWasDeprecated: HintTest[] = [
{
name: 'Prefixed features that became deprecated before the targeted browser should fail.',
reports: [{ message: 'background-size prefixed with -moz- is not supported by firefox 4.', position: { column: 4, line: 1 }}],
reports: [{ message: 'background-size prefixed with -moz- is not supported by firefox 4.', position: { match: '-moz-background-size' }}],
serverConfig: generateCSSConfig('background-size-prefix')
}
];
@@ -164,7 +164,7 @@ hintRunner.testHint(hintPath, prefixedFeaturesThatBecameStandardAndPrefixWasDepr
const featureVersionAddedFalse: HintTest[] = [
{
name: 'Features that have version added as false should fail.',
reports: [{ message: 'box-flex is not supported by ie.', position: { column: 4, line: 1}}],
reports: [{ message: 'box-flex is not supported by ie.', position: { match: 'box-flex' }}],
serverConfig: generateCSSConfig('box-flex')
}
];
@@ -174,7 +174,7 @@ hintRunner.testHint(hintPath, featureVersionAddedFalse, { browserslist: ['ie 11'
const featureVersionAddedMixedFalseAndNullForDifferentBrowsers: HintTest[] = [
{
name: 'Features with unknown support (version added is null) and no support (version added is false) for different browsers should fail for unsupported browsers.',
reports: [{ message: 'box-lines is not supported by firefox, firefox_android.', position: { column: 4, line: 1}}],
reports: [{ message: 'box-lines is not supported by firefox, firefox_android.', position: { match: 'box-lines' }}],
serverConfig: generateCSSConfig('box-lines')
}
];
@@ -184,7 +184,7 @@ hintRunner.testHint(hintPath, featureVersionAddedMixedFalseAndNullForDifferentBr
const mixedFeaturedCompatibility: HintTest[] = [
{
name: 'Features with mixed compatibility (version added null vs false) for different browsers should only throw errors for browsers in which the feature has never been added (false).',
reports: [{ message: 'box-lines is not supported by firefox.', position: { column: 4, line: 1 }}],
reports: [{ message: 'box-lines is not supported by firefox.', position: { match: 'box-lines' }}],
serverConfig: generateCSSConfig('box-lines')
}
];
@@ -194,7 +194,7 @@ hintRunner.testHint(hintPath, mixedFeaturedCompatibility, { browserslist: ['fire
const featureVersionAddedFalseForAllTargetedBrowsers: HintTest[] = [
{
name: 'Features with no support (version added is false) for multiple targeted browsers should fail.',
reports: [{ message: 'box-lines is not supported by any of your target browsers.', position: { column: 4, line: 1}}],
reports: [{ message: 'box-lines is not supported by any of your target browsers.', position: { match: 'box-lines' }}],
serverConfig: generateCSSConfig('box-lines')
}
];
@@ -213,7 +213,7 @@ hintRunner.testHint(hintPath, notSupportedAndNotDeprecatedFeature, { browserslis
const notSupportedFeaturesShouldNotSeparatelyLog: HintTest[] = [
{
name: 'Features not supported and not deprecated should not separately log the feature and value.',
reports: [{ message: 'box-flex is not supported by ie.', position: { column: 4, line: 3 }}],
reports: [{ message: 'box-flex is not supported by ie.', position: { match: 'box-flex: 1; /* Report */' }}],
serverConfig: generateCSSConfig('box-flex-prefixes')
}
];
@@ -240,7 +240,7 @@ hintRunner.testHint(hintPath, ignoredHintOptionsFeaturesShouldNotFail, {
const enabledDefaultIgnoredFeaturesShouldFail: HintTest[] = [
{
name: 'Features included in the ignored HintOptions should fail.',
reports: [{ message: 'ime-mode is not supported by chrome.', position: { column: 4, line: 1}}],
reports: [{ message: 'ime-mode is not supported by chrome.', position: { match: 'ime-mode' }}],
serverConfig: generateCSSConfig('ime-mode')
}
];
@@ -254,7 +254,7 @@ hintRunner.testHint(hintPath, enabledDefaultIgnoredFeaturesShouldFail, {
const enabledIgnoredHintOptionsFeaturesShouldFail: HintTest[] = [
{
name: 'Features included in the default ignored list should fail.',
reports: [{ message: 'box-flex is not supported by ie.', position: { column: 4, line: 1}}],
reports: [{ message: 'box-flex is not supported by ie.', position: { match: 'box-flex' }}],
serverConfig: generateCSSConfig('box-flex')
}
];
@@ -4,5 +4,5 @@
}

.example2 {
appearance: none;
appearance: none; /* unprefixed */
}
@@ -1,5 +1,5 @@
.example {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
appearance: none; /* Report */
}
@@ -1,5 +1,5 @@
.example {
-webkit-box-flex: 1;
-moz-box-flex: 1;
box-flex: 1;
box-flex: 1; /* Report */
}
Oops, something went wrong.

0 comments on commit ae51244

Please sign in to comment.
You can’t perform that action at this time.