Skip to content

Commit

Permalink
Breaking: Rename getRuleName to getRulePath
Browse files Browse the repository at this point in the history
Fix #1054
Fix #1134

Close #1140
  • Loading branch information
molant authored and alrra committed Jun 21, 2018
1 parent 1e2e54f commit 232564d
Show file tree
Hide file tree
Showing 62 changed files with 279 additions and 310 deletions.
8 changes: 4 additions & 4 deletions packages/rule-amp-validator/tests/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import { RuleTest } from 'sonarwhal/dist/tests/helpers/rule-test-type';
import { readFile } from 'sonarwhal/dist/src/lib/utils/misc';
import { getRuleName } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import { getRulePath } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import * as ruleRunner from 'sonarwhal/dist/tests/helpers/rule-runner';

const ruleName = getRuleName(__dirname);
const rulePath = getRulePath(__filename);

const validAMPHTML = readFile(`${__dirname}/fixtures/valid-amp.html`);
const invalidAMPHTML = readFile(`${__dirname}/fixtures/invalid-amp.html`);
Expand Down Expand Up @@ -44,5 +44,5 @@ const configuredTests: Array<RuleTest> = [{
serverConfig: deprecateAMP
}];

ruleRunner.testRule(ruleName, defaultTests);
ruleRunner.testRule(ruleName, configuredTests, { ruleOptions: { 'errors-only': true } });
ruleRunner.testRule(rulePath, defaultTests);
ruleRunner.testRule(rulePath, configuredTests, { ruleOptions: { 'errors-only': true } });
6 changes: 3 additions & 3 deletions packages/rule-apple-touch-icons/tests/tests.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as fs from 'fs';

import { generateHTMLPage } from 'sonarwhal/dist/tests/helpers/misc';
import { getRuleName } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import { getRulePath } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import { RuleTest } from 'sonarwhal/dist/tests/helpers/rule-test-type';
import * as ruleRunner from 'sonarwhal/dist/tests/helpers/rule-runner';

const ruleName = getRuleName(__dirname);
const rulePath = getRulePath(__filename);

const defaultImage = fs.readFileSync(`${__dirname}/fixtures/apple-touch-icon.png`); // eslint-disable-line no-sync
const imageWithIncorrectDimensions = fs.readFileSync(`${__dirname}/fixtures/incorrect-dimensions.png`); // eslint-disable-line no-sync
Expand Down Expand Up @@ -162,4 +162,4 @@ const tests: Array<RuleTest> = [
}
];

ruleRunner.testRule(ruleName, tests);
ruleRunner.testRule(rulePath, tests);
8 changes: 4 additions & 4 deletions packages/rule-axe/tests/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import { RuleTest } from 'sonarwhal/dist/tests/helpers/rule-test-type';
import * as ruleRunner from 'sonarwhal/dist/tests/helpers/rule-runner';
import { getRuleName } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import { getRulePath } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import { generateHTMLPage } from 'sonarwhal/dist/tests/helpers/misc';

const ruleName = getRuleName(__dirname);
const rulePath = getRulePath(__filename);

const html = {
noProblems: generateHTMLPage(undefined, '<div role="main"><h1>test</h1></div>'),
Expand Down Expand Up @@ -63,8 +63,8 @@ const testsWithCustomConfiguration: Array<RuleTest> = [
}
];

ruleRunner.testRule(ruleName, tests);
ruleRunner.testRule(ruleName, testsWithCustomConfiguration, {
ruleRunner.testRule(rulePath, tests);
ruleRunner.testRule(rulePath, testsWithCustomConfiguration, {
ruleOptions: {
runOnly: {
type: 'rule',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as path from 'path';

import { getRulePath } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import * as ruleRunner from 'sonarwhal/dist/tests/helpers/rule-runner';
import { RuleLocalTest } from 'sonarwhal/dist/tests/helpers/rule-test-type';

const ruleName = 'babel-config/is-valid';
const rulePath = getRulePath(__filename, true);

const tests: Array<RuleLocalTest> = [
{
Expand Down Expand Up @@ -59,4 +60,4 @@ const tests: Array<RuleLocalTest> = [
}
];

ruleRunner.testLocalRule(ruleName, tests, { parsers: ['babel-config'] });
ruleRunner.testLocalRule(rulePath, tests, { parsers: ['babel-config'] });
8 changes: 4 additions & 4 deletions packages/rule-content-type/tests/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import * as fs from 'fs';

import { generateHTMLPage } from 'sonarwhal/dist/tests/helpers/misc';
import { getRuleName } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import { getRulePath } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import { RuleTest } from 'sonarwhal/dist/tests/helpers/rule-test-type';
import * as ruleRunner from 'sonarwhal/dist/tests/helpers/rule-runner';

const ruleName = getRuleName(__dirname);
const rulePath = getRulePath(__filename);

const pngFileContent = fs.readFileSync(`${__dirname}/fixtures/image.png`); // eslint-disable-line no-sync
const svgFileContent = '<svg xmlns="http://www.w3.org/2000/svg"><path d="M1,1"/></svg>';
Expand Down Expand Up @@ -313,8 +313,8 @@ const testsForConfigs: Array<RuleTest> = [
}
];

ruleRunner.testRule(ruleName, testsForDefaults);
ruleRunner.testRule(ruleName, testsForConfigs, {
ruleRunner.testRule(rulePath, testsForDefaults);
ruleRunner.testRule(rulePath, testsForConfigs, {
ruleOptions: {
'.*\\.js': 'application/javascript',
'test/test2\\.js': 'application/x-javascript; charset=utf-8',
Expand Down
10 changes: 5 additions & 5 deletions packages/rule-disown-opener/tests/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import { cutString } from 'sonarwhal/dist/src/lib/utils/misc';
import { generateHTMLPage } from 'sonarwhal/dist/tests/helpers/misc';
import { getRuleName } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import { getRulePath } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import { RuleTest } from 'sonarwhal/dist/tests/helpers/rule-test-type';
import * as ruleRunner from 'sonarwhal/dist/tests/helpers/rule-runner';

const ruleName = getRuleName(__dirname);
const rulePath = getRulePath(__filename);

const generateMissingMessage = (value: string, linkTypes: Array<string>): string => {
return `'${cutString(value, 100)}' is missing 'rel' ${linkTypes.length === 1 ? 'value' : 'values'} '${linkTypes.join('\', \'')}'`;
Expand Down Expand Up @@ -203,6 +203,6 @@ const testsForIncludeSameOriginURLsConfig: Array<RuleTest> = [
}
];

ruleRunner.testRule(ruleName, testsWithFullSupportBrowsers, { browserslist: ['chrome 60', 'firefox 55'] });
ruleRunner.testRule(ruleName, testsForOldBrowsers, { browserslist: ['ie 8'] });
ruleRunner.testRule(ruleName, testsForIncludeSameOriginURLsConfig, { ruleOptions: { includeSameOriginURLs: true } });
ruleRunner.testRule(rulePath, testsWithFullSupportBrowsers, { browserslist: ['chrome 60', 'firefox 55'] });
ruleRunner.testRule(rulePath, testsForOldBrowsers, { browserslist: ['ie 8'] });
ruleRunner.testRule(rulePath, testsForIncludeSameOriginURLsConfig, { ruleOptions: { includeSameOriginURLs: true } });
10 changes: 5 additions & 5 deletions packages/rule-highest-available-document-mode/tests/tests.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/* eslint sort-keys: 0, no-undefined: 0 */

import { generateHTMLPage } from 'sonarwhal/dist/tests/helpers/misc';
import { getRuleName } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import { getRulePath } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import { RuleTest } from 'sonarwhal/dist/tests/helpers/rule-test-type';
import * as ruleRunner from 'sonarwhal/dist/tests/helpers/rule-runner';

const ruleName = getRuleName(__dirname);
const rulePath = getRulePath(__filename);

const metaTag = '<meta http-equiv="x-ua-compatible" content="ie=edge">';

Expand Down Expand Up @@ -108,9 +108,9 @@ const testsForRequireMetaTagConfig: Array<RuleTest> = [
}
];

ruleRunner.testRule(ruleName, testsForNonDocumentModeBrowsers, { browserslist: ['ie >= 11', 'chrome >= 50', 'edge >= 13', 'firefox >= 45'] });
ruleRunner.testRule(ruleName, testsForRequireMetaTagConfig, {
ruleRunner.testRule(rulePath, testsForNonDocumentModeBrowsers, { browserslist: ['ie >= 11', 'chrome >= 50', 'edge >= 13', 'firefox >= 45'] });
ruleRunner.testRule(rulePath, testsForRequireMetaTagConfig, {
browserslist: ['ie 8'],
ruleOptions: { requireMetaTag: true }
});
ruleRunner.testRule(ruleName, testsForHeaders, { browserslist: ['ie 8'] });
ruleRunner.testRule(rulePath, testsForHeaders, { browserslist: ['ie 8'] });
16 changes: 8 additions & 8 deletions packages/rule-html-checker/tests/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import * as mock from 'mock-require';

import { RuleTest } from 'sonarwhal/dist/tests/helpers/rule-test-type';
import * as ruleRunner from 'sonarwhal/dist/tests/helpers/rule-runner';
import { getRuleName } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import { getRulePath } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import { delay } from 'sonarwhal/dist/src/lib/utils/misc';

const ruleName = getRuleName(__dirname);
const rulePath = getRulePath(__filename);
const exampleUrl = 'https://empty.sonarwhal.com/';
const validatorError = 'error';
const defaultValidator = 'https://validator.w3.org/nu/';
Expand Down Expand Up @@ -227,22 +227,22 @@ const testsForErrors: Array<RuleTest> = [
}
];

ruleRunner.testRule(ruleName, testsForDefaults, { serial: true });
ruleRunner.testRule(ruleName, testsForIgnoreStringConfigs, {
ruleRunner.testRule(rulePath, testsForDefaults, { serial: true });
ruleRunner.testRule(rulePath, testsForIgnoreStringConfigs, {
ruleOptions: { ignore: defaultCheckerMessages.messages[1].message },
serial: true
});
ruleRunner.testRule(ruleName, testsForIgnoreArrayConfigs, {
ruleRunner.testRule(rulePath, testsForIgnoreArrayConfigs, {
ruleOptions: { ignore: [defaultCheckerMessages.messages[0].message, defaultCheckerMessages.messages[1].message] },
serial: true
});
ruleRunner.testRule(ruleName, testsForValidatorConfig, {
ruleRunner.testRule(rulePath, testsForValidatorConfig, {
ruleOptions: { validator: configValidator },
serial: true
});
ruleRunner.testRule(ruleName, testsForDetailsConfig, {
ruleRunner.testRule(rulePath, testsForDetailsConfig, {
ruleOptions: { details: true },
serial: true
});

ruleRunner.testRule(ruleName, testsForErrors);
ruleRunner.testRule(rulePath, testsForErrors);
8 changes: 4 additions & 4 deletions packages/rule-http-cache/tests/tests.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { RuleTest } from 'sonarwhal/dist/tests/helpers/rule-test-type';
import { getRuleName } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import { getRulePath } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import * as ruleRunner from 'sonarwhal/dist/tests/helpers/rule-runner';
import { generateHTMLPage } from 'sonarwhal/dist/tests/helpers/misc';

const ruleName = getRuleName(__dirname);
const rulePath = getRulePath(__filename);

const defaultTests: Array<RuleTest> = [
{
Expand Down Expand Up @@ -458,5 +458,5 @@ const customRegexTests: Array<RuleTest> = [
}
}];

ruleRunner.testRule(ruleName, defaultTests);
ruleRunner.testRule(ruleName, customRegexTests, { ruleOptions: { revvingPatterns: ['\\/\\d+\\/\\w+\\.\\w{1,3}'] } });
ruleRunner.testRule(rulePath, defaultTests);
ruleRunner.testRule(rulePath, customRegexTests, { ruleOptions: { revvingPatterns: ['\\/\\d+\\/\\w+\\.\\w{1,3}'] } });
24 changes: 12 additions & 12 deletions packages/rule-http-compression/tests/tests-http.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getRuleName } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import { getRulePath } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import * as ruleRunner from 'sonarwhal/dist/tests/helpers/rule-runner';

import {
Expand All @@ -14,7 +14,7 @@ import {
testsForUserConfigs
} from './_tests';

const ruleName = getRuleName(__dirname);
const rulePath = getRulePath(__filename);

/*
* TODO: Remove `ignoredConnectors` part once headless
Expand All @@ -27,21 +27,21 @@ testConfigsSerial.serial = true;

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

ruleRunner.testRule(ruleName, testsForDefaults(), testConfigs);
ruleRunner.testRule(ruleName, testsForSpecialCases(), testConfigs);
ruleRunner.testRule(ruleName, testsForDisallowedCompressionMethods(), testConfigs);
ruleRunner.testRule(ruleName, testsForNoCompression(), testConfigsSerial);
ruleRunner.testRule(ruleName, testsForGzipZopfli(), testConfigsSerial);
ruleRunner.testRule(ruleName, testsForGzipZopfliCaching(), testConfigs);
ruleRunner.testRule(ruleName, testsForGzipZopfliSmallSize(), testConfigs);
ruleRunner.testRule(ruleName, testsForGzipZopfliUASniffing(), testConfigs);
ruleRunner.testRule(ruleName, testsForBrotliOverHTTP, testConfigs);
ruleRunner.testRule(rulePath, testsForDefaults(), testConfigs);
ruleRunner.testRule(rulePath, testsForSpecialCases(), testConfigs);
ruleRunner.testRule(rulePath, testsForDisallowedCompressionMethods(), testConfigs);
ruleRunner.testRule(rulePath, testsForNoCompression(), testConfigsSerial);
ruleRunner.testRule(rulePath, testsForGzipZopfli(), testConfigsSerial);
ruleRunner.testRule(rulePath, testsForGzipZopfliCaching(), testConfigs);
ruleRunner.testRule(rulePath, testsForGzipZopfliSmallSize(), testConfigs);
ruleRunner.testRule(rulePath, testsForGzipZopfliUASniffing(), testConfigs);
ruleRunner.testRule(rulePath, testsForBrotliOverHTTP, testConfigs);

// Tests for the user options.
[true, false].forEach((isTarget) => {
['gzip', 'zopfli', 'brotli'].forEach((encoding) => {
ruleRunner.testRule(
ruleName,
rulePath,
testsForUserConfigs(`${encoding}`, isTarget),
Object.assign(
{},
Expand Down
28 changes: 14 additions & 14 deletions packages/rule-http-compression/tests/tests-https.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getRuleName } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import { getRulePath } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import * as ruleRunner from 'sonarwhal/dist/tests/helpers/rule-runner';

import {
Expand All @@ -16,7 +16,7 @@ import {
testsForUserConfigs
} from './_tests';

const ruleName = getRuleName(__dirname);
const rulePath = getRulePath(__filename);

/*
* TODO: Remove `ignoredConnectors` part once headless
Expand All @@ -34,24 +34,24 @@ testConfigsSerial.serial = true;

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

ruleRunner.testRule(ruleName, testsForDefaults(true), testConfigs);
ruleRunner.testRule(ruleName, testsForSpecialCases(true), testConfigs);
ruleRunner.testRule(ruleName, testsForDisallowedCompressionMethods(true), testConfigs);
ruleRunner.testRule(ruleName, testsForNoCompression(true), testConfigsSerial);
ruleRunner.testRule(ruleName, testsForGzipZopfli(true), testConfigsSerial);
ruleRunner.testRule(ruleName, testsForGzipZopfliCaching(true), testConfigs);
ruleRunner.testRule(ruleName, testsForGzipZopfliSmallSize(true), testConfigs);
ruleRunner.testRule(ruleName, testsForGzipZopfliUASniffing(true), testConfigs);
ruleRunner.testRule(rulePath, testsForDefaults(true), testConfigs);
ruleRunner.testRule(rulePath, testsForSpecialCases(true), testConfigs);
ruleRunner.testRule(rulePath, testsForDisallowedCompressionMethods(true), testConfigs);
ruleRunner.testRule(rulePath, testsForNoCompression(true), testConfigsSerial);
ruleRunner.testRule(rulePath, testsForGzipZopfli(true), testConfigsSerial);
ruleRunner.testRule(rulePath, testsForGzipZopfliCaching(true), testConfigs);
ruleRunner.testRule(rulePath, testsForGzipZopfliSmallSize(true), testConfigs);
ruleRunner.testRule(rulePath, testsForGzipZopfliUASniffing(true), testConfigs);

ruleRunner.testRule(ruleName, testsForBrotli, testConfigsSerial);
ruleRunner.testRule(ruleName, testsForBrotliSmallSize, testConfigs);
ruleRunner.testRule(ruleName, testsForBrotliUASniffing(), testConfigs);
ruleRunner.testRule(rulePath, testsForBrotli, testConfigsSerial);
ruleRunner.testRule(rulePath, testsForBrotliSmallSize, testConfigs);
ruleRunner.testRule(rulePath, testsForBrotliUASniffing(), testConfigs);

// Tests for the user options.
[true, false].forEach((isHTML) => {
['gzip', 'zopfli', 'brotli'].forEach((encoding) => {
ruleRunner.testRule(
ruleName,
rulePath,
testsForUserConfigs(`${encoding}`, isHTML, true),
Object.assign(
{},
Expand Down
6 changes: 3 additions & 3 deletions packages/rule-https-only/tests/tests-https.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { readFileSync } from 'fs';

import { RuleTest } from 'sonarwhal/dist/tests/helpers/rule-test-type';
import { getRuleName } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import { getRulePath } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import * as ruleRunner from 'sonarwhal/dist/tests/helpers/rule-runner';
import { generateHTMLPage } from 'sonarwhal/dist/tests/helpers/misc';

const ruleName = getRuleName(__dirname);
const rulePath = getRulePath(__filename);

const png = readFileSync(`${__dirname}/fixtures/nellie-studying.png`);

Expand Down Expand Up @@ -88,4 +88,4 @@ const testsHTTPS: Array<RuleTest> = [
}
];

ruleRunner.testRule(ruleName, testsHTTPS, { https: true });
ruleRunner.testRule(rulePath, testsHTTPS, { https: true });
6 changes: 3 additions & 3 deletions packages/rule-https-only/tests/tests.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { generateHTMLPage } from 'sonarwhal/dist/tests/helpers/misc';
import { RuleTest } from 'sonarwhal/dist/tests/helpers/rule-test-type';
import { getRuleName } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import { getRulePath } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import * as ruleRunner from 'sonarwhal/dist/tests/helpers/rule-runner';

const ruleName = getRuleName(__dirname);
const rulePath = getRulePath(__filename);

const testsNoHTTPS: Array<RuleTest> = [
{
Expand All @@ -13,4 +13,4 @@ const testsNoHTTPS: Array<RuleTest> = [
}
];

ruleRunner.testRule(ruleName, testsNoHTTPS);
ruleRunner.testRule(rulePath, testsNoHTTPS);
10 changes: 5 additions & 5 deletions packages/rule-image-optimization-cloudinary/tests/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { readFileSync } from 'fs';
import * as mock from 'mock-require';

import { generateHTMLPage } from 'sonarwhal/dist/tests/helpers/misc';
import { getRuleName } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import { getRulePath } from 'sonarwhal/dist/src/lib/utils/rule-helpers';
import { RuleTest } from 'sonarwhal/dist/tests/helpers/rule-test-type';
import * as ruleRunner from 'sonarwhal/dist/tests/helpers/rule-runner';

const ruleName = getRuleName(__dirname);
const rulePath = getRulePath(__filename);
const svg = readFileSync(`${__dirname}/fixtures/space-nellie.svg`);
const png = readFileSync(`${__dirname}/fixtures/nellie-studying.png`);
const invalid = readFileSync(`${__dirname}/fixtures/invalid-image.js`);
Expand Down Expand Up @@ -139,19 +139,19 @@ const noConfigTest: Array<RuleTest> = [
}
];

ruleRunner.testRule(ruleName, testThresholds, {
ruleRunner.testRule(rulePath, testThresholds, {
ignoredConnectors: ['chrome'],
ruleOptions: { apiKey: 'fakeApiName', apiSecret: 'fakeApiSecret', cloudName: 'fakeCloudName', threshold: 150 },
serial: true
});

ruleRunner.testRule(ruleName, tests, {
ruleRunner.testRule(rulePath, tests, {
ignoredConnectors: ['chrome'],
ruleOptions: { apiKey: 'fakeApiName', apiSecret: 'fakeApiSecret', cloudName: 'fakeCloudName' },
serial: true
});

ruleRunner.testRule(ruleName, noConfigTest, {
ruleRunner.testRule(rulePath, noConfigTest, {
ignoredConnectors: ['chrome'],
serial: true
});
Loading

0 comments on commit 232564d

Please sign in to comment.