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 broken tests #749

Merged
merged 1 commit into from
Nov 2, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/functions/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,5 +378,5 @@ exports.getCustomHtmlRuleOptions = (api, url) =>
for await (const item of entity) {
result.push(item);
}
resolve(result || {})
resolve(result || [])
})
2 changes: 1 addition & 1 deletion docker/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ exports.getCustomHtmlRuleOptions = (api, url) => {
headers: { "Content-Type": "application/json" },
}).then((res) => {
if (res) {
return res.json();
return res.ok ? res.json() : [];
} else {
throw Error("Failed to get custom html rule options");
}
Expand Down
4 changes: 2 additions & 2 deletions docker/customHtmlRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const HTMLHint = require("htmlhint").default;
const findPhoneNumbersInText = require('libphonenumber-js').findPhoneNumbersInText;

exports.addCustomHtmlRule = async (apiToken, url) => {
const customRuleOptions = await getCustomHtmlRuleOptions(apiToken, url)
const customRuleOptions = await getCustomHtmlRuleOptions(apiToken, url);

HTMLHint.addRule({
id: "code-block-missing-language",
Expand Down Expand Up @@ -503,9 +503,9 @@ exports.addCustomHtmlRule = async (apiToken, url) => {
init: function (parser, reporter) {
const self = this;
let isInCodeBlock = false;
let optionValue = '';
parser.addListener("tagstart", (event) => {
// Check if custom options exist in this rule
let optionValue = '';
if (customRuleOptions && customRuleOptions.length > 0 && customRuleOptions.filter(option => option.ruleId === ruleId).length > 0) {
optionValue = customRuleOptions.find(option => option.ruleId === ruleId).optionValue
}
Expand Down
4 changes: 2 additions & 2 deletions docker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ const processAndUpload = async (

if (args.htmlhint) {
if (args.token) {
addCustomHtmlRule(args.token, args.url);
await addCustomHtmlRule(args.token, args.url);
} else {
addCustomHtmlRule();
await addCustomHtmlRule();
};
[htmlIssuesSummary, htmlIssues] = await runHtmlHint(
args.url,
Expand Down
5 changes: 4 additions & 1 deletion docker/test/anchor-names-must-be-valid.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ const {addCustomHtmlRule} = require('../customHtmlRules')

ruleOptions[ruldId] = true

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruldId}`, () => {
addCustomHtmlRule();
it('Anchor name starts with letter and contains no space should not result in an error', () => {
const code = '<a name="ThisisAnchor">Anchor</a>'
const messages = HTMLHint.verify(code, ruleOptions)
Expand Down
5 changes: 4 additions & 1 deletion docker/test/code-block-missing-language.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ const {addCustomHtmlRule} = require('../customHtmlRules')

ruleOptions[ruldId] = true

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruldId}`, () => {
addCustomHtmlRule();
it('Code block with data language specifier should not result in an error', () => {
const code = '<pre data-language="javascript">Some Code</pre>'
const messages = HTMLHint.verify(code, ruleOptions)
Expand Down
5 changes: 4 additions & 1 deletion docker/test/common-spelling-mistakes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ const { addCustomHtmlRule } = require("../customHtmlRules");

ruleOptions[ruleId] = true;

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruleId}`, () => {
addCustomHtmlRule();
it("terms used correctly should not result in an error", () => {
const code = "<p>aka email cannot website username taskbar</p>";
const messages = HTMLHint.verify(code, ruleOptions);
Expand Down
5 changes: 4 additions & 1 deletion docker/test/detect-absolute-references-correctly.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ const { addCustomHtmlRule } = require("../customHtmlRules");

ruleOptions[ruldId] = true;

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruldId}`, () => {
addCustomHtmlRule();
it("Bad example should result in an error", () => {
const code = '<a href="https://ssw.com.au/rules/when-you-use-mentions-in-a-pbi/" />';
const messages = HTMLHint.verify(code, ruleOptions);
Expand Down
5 changes: 4 additions & 1 deletion docker/test/figure-must-use-the-right-code.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ const { addCustomHtmlRule } = require("../customHtmlRules");

ruleOptions[ruldId] = true;

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruldId}`, () => {
addCustomHtmlRule();
it("Figures not wrapped in figcaption must result in an error", () => {
const code = "<p>Figure: Caption</p>";
const messages = HTMLHint.verify(code, ruleOptions);
Expand Down
5 changes: 4 additions & 1 deletion docker/test/font-tag-must-not-be-used.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ const {addCustomHtmlRule} = require('../customHtmlRules')

ruleOptions[ruldId] = true

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruldId}`, () => {
addCustomHtmlRule();
it('Anything that is not font tag should not result in an error', () => {
const code = '<p color="red">Text</p>'
const messages = HTMLHint.verify(code, ruleOptions)
Expand Down
5 changes: 4 additions & 1 deletion docker/test/grammar-scrum-terms.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ const { addCustomHtmlRule } = require("../customHtmlRules");

ruleOptions[ruldId] = true;

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruldId}`, () => {
addCustomHtmlRule();
it("Scrum terms that are cased correctly should not result in an error", () => {
const code =
"<p>Scrum, Sprint, Product Owner, Scrum Master, Product Backlog, Sprint Review, Sprint Planning, Sprint Retrospective, Sprint Retro, Specification Review, Spec Review</p>";
Expand Down
5 changes: 4 additions & 1 deletion docker/test/link-must-not-show-unc.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ const {addCustomHtmlRule} = require('../customHtmlRules')

ruleOptions[ruldId] = true

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruldId}`, () => {
addCustomHtmlRule();
it('Href that does not show UNC should not result in an error', () => {
const code = '<a href="/ssw">somelink</a>'
const messages = HTMLHint.verify(code, ruleOptions)
Expand Down
5 changes: 4 additions & 1 deletion docker/test/meta-tags-must-not-redirect.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ const {addCustomHtmlRule} = require('../customHtmlRules')

ruleOptions[ruldId] = true

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruldId}`, () => {
addCustomHtmlRule();
it('Meta tags that does not refresh should not result in an error', () => {
const code = '<meta name="description" />'
const messages = HTMLHint.verify(code, ruleOptions)
Expand Down
5 changes: 4 additions & 1 deletion docker/test/page-must-not-show-email-addresses.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ const {addCustomHtmlRule} = require('../customHtmlRules')

ruleOptions[ruldId] = true

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruldId}`, () => {
addCustomHtmlRule();
it('Page that does not show email addresses should not result in an error', () => {
const code = '<a href="...">email address</a>'
const messages = HTMLHint.verify(code, ruleOptions)
Expand Down
5 changes: 4 additions & 1 deletion docker/test/phone-numbers-without-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ const nonPhoneNumbers = [
"20231024.16"
];

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruleId}`, () => {
addCustomHtmlRule();

phoneNumbers.forEach((phone) => {
it(`text containing "${phone}" without hyperlink should error`, () => {
Expand Down
5 changes: 4 additions & 1 deletion docker/test/url-must-be-formatted-correctly.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ const { addCustomHtmlRule } = require("../customHtmlRules");

ruleOptions[ruldId] = true;

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruldId}`, () => {
addCustomHtmlRule();
it("URL with full stop at the end should result in an error", () => {
const code = '<a href="www.ssw.com.au/Thisisarule." />';
const messages = HTMLHint.verify(code, ruleOptions);
Expand Down
5 changes: 4 additions & 1 deletion docker/test/url-must-not-have-click-here.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ const {addCustomHtmlRule} = require('../customHtmlRules')

ruleOptions[ruldId] = true

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruldId}`, () => {
addCustomHtmlRule();
it('URL text without words click here should not result in an error', () => {
const code = '<a href="www.ssw.com.au/Thisisarule">Not Click Here</a>'
const messages = HTMLHint.verify(code, ruleOptions)
Expand Down
5 changes: 4 additions & 1 deletion docker/test/url-must-not-have-space.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ const {addCustomHtmlRule} = require('../customHtmlRules')

ruleOptions[ruldId] = true

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruldId}`, () => {
addCustomHtmlRule();
it('URL without space should not result in an error', () => {
const code = '<a href="www.ssw.com.au/Thisisarule" />'
const messages = HTMLHint.verify(code, ruleOptions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ const { addCustomHtmlRule } = require("../customHtmlRules");

ruleOptions[ruldId] = true;

before(async () => {
await addCustomHtmlRule();
});

describe(`Rules: ${ruldId}`, () => {
addCustomHtmlRule();
it("Non code tag with special char should result in an error", () => {
const code = '<span>aaa>bbb<ccc</span>';
const messages = HTMLHint.verify(code, ruleOptions);
Expand Down
Loading