mirror of
https://github.com/withastro/astro.git
synced 2025-02-17 22:44:24 -05:00
chore: Migrate astro-markdown-plugins.test.js
to node:test
(#10020)
* migrate test * remove old test * Update packages/astro/test/astro-markdown-plugins.nodetest.js * Update packages/astro/test/astro-markdown-plugins.nodetest.js --------- Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
This commit is contained in:
parent
191fd39708
commit
b05e6ac26a
1 changed files with 14 additions and 12 deletions
|
@ -1,4 +1,6 @@
|
|||
import { expect } from 'chai';
|
||||
import assert from 'node:assert/strict';
|
||||
import { describe, before, it } from 'node:test';
|
||||
|
||||
import * as cheerio from 'cheerio';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
import addClasses from './fixtures/astro-markdown-plugins/add-classes.mjs';
|
||||
|
@ -44,21 +46,21 @@ describe('Astro Markdown plugins', () => {
|
|||
const $ = cheerio.load(html);
|
||||
|
||||
// test 1: Added a TOC
|
||||
expect($('.toc')).to.have.lengthOf(1);
|
||||
assert.strictEqual($('.toc').length, 1);
|
||||
|
||||
// test 2: Added .title to h1
|
||||
expect($('#hello-world').hasClass('title')).to.equal(true);
|
||||
assert.ok($('#hello-world').hasClass('title'));
|
||||
});
|
||||
|
||||
// Asserts Astro 1.0 behavior is removed. Test can be removed in Astro 3.0.
|
||||
it('Still applies default plugins when user plugins are provided', async () => {
|
||||
const gfmHtml = await fixture.readFile('/with-gfm/index.html');
|
||||
const $1 = cheerio.load(gfmHtml);
|
||||
expect($1('a[href="https://example.com"]')).to.have.lengthOf(1);
|
||||
assert.strictEqual($1('a[href="https://example.com"]').length, 1);
|
||||
|
||||
const smartypantsHtml = await fixture.readFile('/with-smartypants/index.html');
|
||||
const $2 = cheerio.load(smartypantsHtml);
|
||||
expect($2('p').html()).to.equal('“Smartypants” is — awesome');
|
||||
assert.strictEqual($2('p').html(), '“Smartypants” is — awesome');
|
||||
|
||||
testRemark(gfmHtml);
|
||||
testRehype(gfmHtml, '#github-flavored-markdown-test');
|
||||
|
@ -69,7 +71,7 @@ describe('Astro Markdown plugins', () => {
|
|||
const $ = cheerio.load(html);
|
||||
|
||||
// test 1: GFM autolink applied correctly
|
||||
expect($('a[href="https://example.com"]')).to.have.lengthOf(1);
|
||||
assert.strictEqual($('a[href="https://example.com"]').length, 1);
|
||||
|
||||
testRemark(html);
|
||||
testRehype(html, '#github-flavored-markdown-test');
|
||||
|
@ -80,7 +82,7 @@ describe('Astro Markdown plugins', () => {
|
|||
const $ = cheerio.load(html);
|
||||
|
||||
// test 1: smartypants applied correctly
|
||||
expect($('p').html()).to.equal('“Smartypants” is — awesome');
|
||||
assert.strictEqual($('p').html(), '“Smartypants” is — awesome');
|
||||
|
||||
testRemark(html);
|
||||
testRehype(html, '#smartypants-test');
|
||||
|
@ -97,7 +99,7 @@ describe('Astro Markdown plugins', () => {
|
|||
const html = await fixture.readFile('/with-gfm/index.html');
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
expect($('a[href="https://example.com"]')).to.have.lengthOf(0);
|
||||
assert.strictEqual($('a[href="https://example.com"]').length, 0);
|
||||
|
||||
testRemark(html);
|
||||
testRehype(html, '#github-flavored-markdown-test');
|
||||
|
@ -113,7 +115,7 @@ describe('Astro Markdown plugins', () => {
|
|||
const html = await fixture.readFile('/with-smartypants/index.html');
|
||||
const $ = cheerio.load(html);
|
||||
|
||||
expect($('p').html()).to.equal('"Smartypants" is -- awesome');
|
||||
assert.strictEqual($('p').html(), '"Smartypants" is -- awesome');
|
||||
|
||||
testRemark(html);
|
||||
testRehype(html, '#smartypants-test');
|
||||
|
@ -122,10 +124,10 @@ describe('Astro Markdown plugins', () => {
|
|||
|
||||
function testRehype(html, headingId) {
|
||||
const $ = cheerio.load(html);
|
||||
expect($(headingId)).to.have.lengthOf(1);
|
||||
expect($(headingId).hasClass('title')).to.equal(true);
|
||||
assert.strictEqual($(headingId).length, 1);
|
||||
assert.ok($(headingId).hasClass('title'));
|
||||
}
|
||||
|
||||
function testRemark(html) {
|
||||
expect(html).to.include('Remark plugin applied!');
|
||||
assert.ok(html.includes('Remark plugin applied!'));
|
||||
}
|
Loading…
Add table
Reference in a new issue