Dev.to WebDev 🛠 Dev 👁 0 📖 5 min read

58 pages that each answer one question, a 300 to 700 word band enforced by a test, and a forbidden character built from its code point

Candidates search things like "can you pause a Clevry test" and "did my SHL test submit" at the worst moment of their week. Our answer to each of those used to be one line inside a long page about something broader, whic

Candidates search things like "can you pause a Clevry test" and "did my SHL test submit" at the worst moment of their week. Our answer to each of those used to be one line inside a long page about something broader, which is useless to a search engine and worse to a person refreshing a tab at 11pm.

So CogniPrep has /answers: 58 pages, one question each, written across 24 provider files. The h1 is the question, the first paragraph is the answer, and the whole page fits in a few hundred words. What is interesting is not the pages, it is the twelve tests that decide what is allowed to become one.

The rules, as the type's own docblock states them

- Build a question only where a source gives a provider-specific answer,
  ideally the vendor's own candidate help centre. A page that would only say
  "not published" is not built.
- Do not rebuild a question an existing page already answers (a hub FAQ, a
  test page FAQ, a cheating guide, a blog post). Link to it instead.
- Search intent and advice only: no sourcing narration, no caveat paragraphs,
  no visible sources. `sources` is the record, never rendered.
- Test facts are sourced or not made. Third-party figures say "reported".
- British English, no em dashes, 300 to 700 words.

The first rule is the one that keeps the cluster from being spam. There is enormous long-tail demand for questions nobody can answer, and the honest page for those is no page. The second rule is the one that keeps it from cannibalising the rest of the site.

The sources field is the part people find surprising: every page carries the URLs its facts rest on, each one actually opened, and none of them is rendered. Across the 24 files there are 36 source URLs over 29 domains, mostly vendors' own candidate help centres, held as module-level constants and shared between that provider's pages. They exist so the next person can recheck a claim, not so the page can look diligent. A candidate who wants to know whether they can pause a test does not want a methodology section.

The word band is a test, not a guideline

const words = wordCount(entry);
expect(words, `${where} has ${words} words`).toBeGreaterThanOrEqual(300);
expect(words, `${where} has ${words} words`).toBeLessThanOrEqual(700);

wordCount assembles the question, the short answer, every section heading and paragraph, the next-steps prose and both halves of every FAQ, strips the inline link markup, then counts. Under 300 words the page is thin. Over 700 it has stopped answering the question and started being an article, at which point it competes with the article we already have.

The same test asserts the question ends with a ?, that there is at least one section, and that there are two to four FAQs, never one and never nine. 58 pages currently hold 173 FAQ entries between them.

The link checker, which is 15 lines and knows about route groups

Paragraphs may carry inline links written as [label](/site/path), site-relative only. One test gathers every link a page renders (inline, next-step buttons, related links) and asserts each one resolves to a real page:

/** True when a site path has a page.tsx, allowing for (group) folders at any level. */
function routeExists(href: string): boolean {
  const segments = href.split('#')[0].split('/').filter(Boolean);
  function walk(dir: string, rest: string[]): boolean {
    if (rest.length === 0) {
      if (existsSync(path.join(dir, 'page.tsx'))) return true;
    } else if (existsSync(path.join(dir, rest[0])) && walk(path.join(dir, rest[0]), rest.slice(1))) {
      return true;
    }
    if (!existsSync(dir)) return false;
    return readdirSync(dir, { withFileTypes: true }).some(
      (child) => child.isDirectory() && child.name.startsWith('(') && walk(path.join(dir, child.name), rest)
    );
  }
  return walk(APP, segments);
}

The recursion into (group) folders is the whole point. In Next's App Router a URL segment can be absent from the path on disk because a parenthesised folder sits in the way, so the naive existsSync(app + href + '/page.tsx') reports a perfectly good internal link as broken. Any repository with route groups and a link-integrity test needs this, and it is cheaper than crawling your own build output.

Two more that pair up: one test asserts a route folder exists for every registry entry, another asserts a registry entry exists for every route folder. A page file with no entry throws at build time by design, because requireAnswer throws rather than returning undefined. A folder you deleted the entry for would otherwise 500 quietly.

The detail I enjoyed most

// Built from its code point so this file contains no em dash itself.
const EM_DASH = String.fromCharCode(0x2014);

House style bans the em dash. The test that enforces the ban cannot contain one, or the next grep for stray em dashes finds its own policeman. One line, one comment, problem gone.

There is also a robots check that reads the real robots() export and asserts no plain Disallow prefix swallows /answers or any of its 58 paths. A page can be perfect and uncrawlable.

See it

  1. Open /answers. 24 providers, each with its questions under it, in registry order.
  2. Open can you pause a Clevry test. The h1 is the question and the answer is the paragraph under it.
  3. View source and look for the vendor's help centre URLs the facts came from. They are not there:
curl -s https://cogniprep.app/answers/can-you-pause-a-clevry-test > page.html
grep -o 'clevry\.com' page.html | wc -l      # 0
grep -o '"@type":"Question"' page.html | wc -l # 3

Zero source domains, and three marked-up questions for a page with three FAQs. The FAQs are structured data, the sources are not, which is the difference between what the page is for and what the repository needs to remember. Use grep -o | wc -l rather than grep -c on this site, by the way: the served HTML is two lines, so grep -c answers "how many lines matched" and tells you almost nothing.

All 58 pages hang off the provider hubs at cogniprep.app, where the practice tests themselves live.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.