Skip to content

Commit

Permalink
Switch test to cheerio
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic committed Aug 9, 2024
1 parent 0cd8d41 commit 39f6fd3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
3 changes: 1 addition & 2 deletions packages/astro/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@
"http-cache-semantics": "^4.1.1",
"js-yaml": "^4.1.0",
"kleur": "^4.1.5",
"linkedom": "^0.18.4",
"magic-string": "^0.30.11",
"micromatch": "^4.0.7",
"mrmime": "^2.0.0",
Expand Down Expand Up @@ -240,4 +239,4 @@
"publishConfig": {
"provenance": true
}
}
}
27 changes: 14 additions & 13 deletions packages/astro/test/content-layer-markdoc.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import { parseHTML } from 'linkedom';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';

describe('Content layer markdoc', () => {
Expand Down Expand Up @@ -59,29 +59,30 @@ describe('Content layer markdoc', () => {

/** @param {string} html */
function renderComponentsChecks(html) {
const { document } = parseHTML(html);
const h2 = document.querySelector('h2');
assert.equal(h2.textContent, 'Post with components');
const $ = cheerio.load(html);
const h2 = $('h2');
assert.equal(h2.text(), 'Post with components');

// Renders custom shortcode component
const marquee = document.querySelector('marquee');
const marquee = $('marquee');
assert.notEqual(marquee, null);
assert.equal(marquee.hasAttribute('data-custom-marquee'), true);
assert.equal(marquee.attr('data-custom-marquee'), '');

// Renders Astro Code component
const pre = document.querySelector('pre');
const pre = $('pre');
assert.notEqual(pre, null);
assert.equal(pre.className, 'astro-code github-dark');
assert.ok(pre.hasClass('github-dark'));
assert.ok(pre.hasClass('astro-code'));
}

/** @param {string} html */
function renderComponentsInsidePartialsChecks(html) {
const { document } = parseHTML(html);
const $ = cheerio.load(html);
// renders Counter.tsx
const button = document.querySelector('#counter');
assert.equal(button.textContent, '1');
const button = $('#counter');
assert.equal(button.text(), '1');

// renders DeeplyNested.astro
const deeplyNested = document.querySelector('#deeply-nested');
assert.equal(deeplyNested.textContent, 'Deeply nested partial');
const deeplyNested = $('#deeply-nested');
assert.equal(deeplyNested.text(), 'Deeply nested partial');
}
8 changes: 0 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 39f6fd3

Please sign in to comment.