Skip to content

Commit

Permalink
Organize test files, use express-handlebars and json to render test c…
Browse files Browse the repository at this point in the history
…ases. (#1441)

* remove pp2002, closes #1431

* remove profile-amended

* fix test

* remove unused test file

* split profiles into track folders

* make track/profiles work

* Revert "make track/profiles work"

This reverts commit f52af89.

* Revert "Revert "make track/profiles work""

This reverts commit 14e624b.

* add all profiles under track

* align profiles

* Demo for test with handlebar template

* revert package.json

* add test case that fail, the new test case extends from current data.

* extend configs

* test: extend check to all rules for good documents. Add DNOTE and NOTE good data

* test: add all good profile documents

* remove files

* ad

* add tests for FPWD

* fix test and lint

* add pre-commit spelling check, fix spelling and lint

* fix REC good test

* commit dl.js without formatting

* fix test

* add more test cases for FPWD

* add test case for FPWD

* add deliverer id data

* add cases for FPWD

* finish FPWD tests

* fix tests

* resolve todos in FPWD

* Update test/data/TR/Recommendation/FPWD.js

Co-authored-by: Denis Ah-Kang <[email protected]>

* Update test/rules.js

Co-authored-by: Denis Ah-Kang <[email protected]>

* fix circular dependency

* add tests for all profiles, extract common data

* fix test

* fix test

* optimize tests

* update cspell config

* fix mock start and stop

* disasble mock for good documents at least

* fix test for good document

* try to fix test

* restore nock

* hide nock

* restore nock

* ignore nock, leave test for wrongPPFromCharter only

* ignore nock, leave test for noDisclosures only

* ignore nock, leave test for noDisclosures only

* restore NO_THROTTLE and nock

* add allowUnmocked to nock

* fix fake request

* fix profile finder

* add more nock mock APIs

* remove desscibe only

* remove console.log

* no longer rely on util.profiles

* fix mock

* remove commented code

* env var is passed in packages.json

* reduce mocha timeout + remove unnecessary callbacks

* fix comments

* clean up old test suite

Co-authored-by: Denis Ah-Kang <[email protected]>
Co-authored-by: Denis Ah-Kang <[email protected]>
  • Loading branch information
3 people authored Jan 31, 2022
1 parent 9a78b3f commit e95ca88
Show file tree
Hide file tree
Showing 222 changed files with 5,662 additions and 34,402 deletions.
12 changes: 11 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
{
"version": "0.2",
"words": [
"Çelik",
"ˈspɛk",
"apikey",
"badterms",
"Beihang",
"blocklist",
"Çelik",
"charmod",
"CRYD",
"csswg",
"datedlink",
"dcterms",
"deniak",
"DNOTE",
"doctypes",
"dvcs",
"ERCIM",
"exphbs",
"extractmetadataoptions",
"FPIG",
"FPLC",
Expand All @@ -25,6 +27,7 @@
"hilite",
"historyuri",
"howto",
"Imple",
"implelink",
"imsc",
"insafe",
Expand Down Expand Up @@ -58,14 +61,20 @@
"SPSD",
"SUBM",
"submlogo",
"SUMB",
"supersedable",
"Tantek",
"testtest",
"tocline",
"tocxref",
"ttml",
"uarr",
"Unmocked",
"unneutral",
"validateoptions",
"vcard",
"wcag",
"webidl",
"webrtc",
"Whut",
"wrongprocess"
Expand All @@ -78,6 +87,7 @@
"**/*.woff",
"**/*.svg",
".nyc_output/**",
".github/**",
"coverage/**",
"doc/api/**",
"test/**/*.html",
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged
npx lint-staged && npm run spelling
11 changes: 9 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,20 @@ io.on('connection', socket => {
return socket.emit('exception', {
message: 'Profile not provided.',
});
if (!util.profiles[data.profile])
const profilePath = util.allProfiles.find(p =>
p.endsWith(`/${data.profile}.js`)
);
let profile;
try {
// eslint-disable-next-line import/no-dynamic-require
profile = require(`./lib/profiles/${profilePath}`);
} catch (err) {
return socket.emit('exception', {
message: 'Profile does not exist.',
});
}
const specberus = new validator.Specberus(process.env.W3C_API_KEY);
const handler = new Sink();
const profile = util.profiles[data.profile];
const profileCode = profile.name;
socket.emit('start', {
rules: (profile.rules || []).map(rule => rule.name),
Expand Down
2 changes: 0 additions & 2 deletions lib/l10n-en_GB.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,6 @@ exports.messages = {
'Required patent policy paragraph not found. Expected text related to patent policy requirements: <blockquote>${expected}</blockquote>',
'sotd.pp.no-pp-from-charter':
'Cannot find the patent policy version from the groups charter. Please make sure the group has a current charter with a patent policy',
'sotd.pp.no-pp-link':
'Required patent policy link not found. Expected text related to patent policy requirements: <blockquote>${expected}</blockquote>',
'sotd.pp.undefined':
"Could not determine the patent policy the WG is operating under. Check the WG's charter.",
'sotd.pp.no-pp2017':
Expand Down
1 change: 1 addition & 0 deletions lib/profiles/SUBM/MEM-SUBM.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let rules = profileUtil.insertAfter(
'headers.w3c-state',
[require('../../rules/headers/memsub-copyright')]
);

rules = profileUtil.insertAfter(
rules,
'sotd.supersedable',
Expand Down
2 changes: 1 addition & 1 deletion lib/profiles/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ exports.rules = [
require('../rules/structure/display-only'),
require('../rules/structure/neutral'),

// , require("../rules/links/internal")
// , require('../rules/links/internal')
require('../rules/links/linkchecker'),
require('../rules/links/compound'),
require('../rules/links/reliability'),
Expand Down
5 changes: 2 additions & 3 deletions lib/rules/headers/dl.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ exports.check = async function (sr, done) {
let historyStatusCode;
const doAsync = require('doasync');
try {
const res = await doAsync(superagent).get(historyHref);
const res = await doAsync(superagent).head(historyHref);
historyStatusCode = res.statusCode;
} catch (err) {
historyStatusCode = err.status;
Expand All @@ -214,7 +214,7 @@ exports.check = async function (sr, done) {
const previousHistoryHref = `https://www.w3.org/standards/history/${previousShortname}`;
let previousHistoryStatusCode;
try {
const res = await doAsync(superagent).get(
const res = await doAsync(superagent).head(
previousHistoryHref
);
previousHistoryStatusCode = res.statusCode;
Expand Down Expand Up @@ -372,6 +372,5 @@ exports.check = async function (sr, done) {
// should at least have 1 editor
sr.error(editorError, 'editor-not-found');
}

done();
};
1 change: 0 additions & 1 deletion lib/rules/metadata/patent-policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ exports.name = 'metadata.patent-policy';

exports.check = async function (sr, done) {
const patentPolicies = await sr.getPatentPolicies();

return done({ patentPolicy: patentPolicies[0] });
};
20 changes: 10 additions & 10 deletions lib/rules/sotd/draft-stability.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ exports.check = function (sr, done) {

if (sotd) {
const txt = sr.norm(sotd.textContent);

// CRD and CRYD allows both sentence.
if (
((crType && crType === 'Draft') ||
(cryType && cryType === 'Draft')) &&
!txt.includes(STABILITY) &&
!txt.includes(STABILITY_2)
)
sr.error(self, 'not-found-either', {
expected1: STABILITY,
expected2: STABILITY_2,
});
(crType && crType === 'Draft') ||
(cryType && cryType === 'Draft')
) {
if (!txt.includes(STABILITY) && !txt.includes(STABILITY_2))
sr.error(self, 'not-found-either', {
expected1: STABILITY,
expected2: STABILITY_2,
});
}

// while other profiles allows only 'STABILITY' sentence
else if (!txt.includes(STABILITY))
sr.error(self, 'not-found', {
Expand Down
4 changes: 1 addition & 3 deletions lib/rules/sotd/pp.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ exports.check = async function (sr, done) {
if (
patent === pp2017 &&
possiblePP.includes(href) &&
/(1 August 2017 )?W3C Patent Policy/.test(text)
/1 August 2017 W3C Patent Policy/.test(text)
) {
found2017 = true;
return;
Expand Down Expand Up @@ -225,8 +225,6 @@ exports.check = async function (sr, done) {

if (patent === pp2017 && !found2017) sr.error(self, 'no-pp2017');
else if (patent === pp2020 && !found2020) sr.error(self, 'no-pp2020');
else if (!found2017 && !found2020)
sr.error(self, 'no-pp-link', { expected });
if (!foundPublicList && isRecTrack) sr.error(self, 'no-disclosures');
if (
(sr.config.track === 'Recommendation' ||
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/style/sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exports.check = function (sr, done) {
const lnk = sr.jsDocument.querySelectorAll(stylesheetLinks.join(', '));
if (!lnk.length) sr.error(missing, 'not-found', { url });
else {
const siblings = util.nextAll(lnk, 'link[rel=stylesheet], style');
const siblings = util.nextAll(lnk[0], 'link[rel=stylesheet], style');
if (
siblings.length ||
(siblings.length === 1 &&
Expand Down
31 changes: 11 additions & 20 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const fs = require('fs');

const filesTR = fs.readdirSync(`${__dirname}/profiles/TR/`);
const filesSUBM = fs.readdirSync(`${__dirname}/profiles/SUBM/`);
const profiles = {};

/**
* Build a JSON result (of validation, metadata extraction, etc).
Expand Down Expand Up @@ -34,7 +33,7 @@ const buildJSONresult = function (err, warn, inf, metadata) {
* @returns {Function} a function that builds an “options” object based on an HTTP query string or a similar object containing options.
*/

const buildProcessParamsFunction = function (profiles) {
const buildProcessParamsFunction = function () {
/**
* Build an “options” object based on an HTTP query string or a similar object containing options.
*
Expand All @@ -55,6 +54,7 @@ const buildProcessParamsFunction = function (profiles) {
return function (params, base, constraints) {
const result = base ? JSON.parse(JSON.stringify(base)) : {};
let originFound = false;
// eslint-disable-next-line no-restricted-syntax
for (const p in params) {
if (
p === 'url' ||
Expand All @@ -74,13 +74,14 @@ const buildProcessParamsFunction = function (profiles) {
if (Object.prototype.hasOwnProperty.call(result, p))
throw new Error(`Parameter “${p}” is used more than once`);
else if (typeof params[p] === 'string') {
if (
Object.prototype.hasOwnProperty.call(
profiles,
params[p]
)
)
result[p] = profiles[params[p]];
const subPath = `/${params[p]}.js`;
const profilePath = this.allProfiles.find(p =>
p.endsWith(subPath)
);

if (profilePath)
// eslint-disable-next-line import/no-dynamic-require
result[p] = require(`../lib/profiles/${profilePath}`);
else if (params[p] === 'auto') result[p] = 'auto';
else throw new Error(`Unknown profile “${params[p]}”`);
} else result[p] = params[p];
Expand Down Expand Up @@ -156,15 +157,6 @@ const allProfiles = [
...TRProfiles.map(x => `TR/${x}`),
...filesSUBM.map(x => `SUBM/${x}`),
];
allProfiles.forEach(i => {
const valid =
/((TR|SUBM)\/([A-Za-z]+\/)?([A-Z][A-Z-]*[A-Z](-Echidna)?))\.js$/.exec(
i
);
if (valid && valid.length > 3)
// eslint-disable-next-line import/no-dynamic-require
profiles[valid[4]] = require(`./profiles/${valid[1]}`);
});
exports.allProfiles = allProfiles;

const nextUntil = function (elem, selector, filter) {
Expand Down Expand Up @@ -216,9 +208,8 @@ const filter = function (elements, tagName) {
);
};

exports.profiles = profiles;
exports.buildJSONresult = buildJSONresult;
exports.processParams = buildProcessParamsFunction(profiles);
exports.processParams = buildProcessParamsFunction();
exports.nextUntil = nextUntil;
exports.filter = filter;
exports.next = next;
Expand Down
Loading

0 comments on commit e95ca88

Please sign in to comment.