0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00

chore: Migrate astro-markdown-shiki.test.js to node:test (#10023)

This commit is contained in:
voxel!() 2024-02-08 02:13:54 -08:00 committed by GitHub
parent 7f0e5026e3
commit 15b9e5a8c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,4 +1,5 @@
import { expect } from 'chai'; import assert from 'node:assert/strict';
import { describe, before, it } from 'node:test';
import * as cheerio from 'cheerio'; import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js'; import { loadFixture } from './test-utils.js';
@ -16,11 +17,12 @@ describe('Astro Markdown Shiki', () => {
const $ = cheerio.load(html); const $ = cheerio.load(html);
// There should be no HTML from Prism // There should be no HTML from Prism
expect($('.token')).to.have.lengthOf(0); assert.strictEqual($('.token').length, 0);
expect($('pre')).to.have.lengthOf(2); assert.strictEqual($('pre').length, 2);
expect($('pre').hasClass('astro-code')).to.equal(true); assert.ok($('pre').hasClass('astro-code'));
expect($('pre').attr().style).to.equal( assert.strictEqual(
$('pre').attr().style,
'background-color:#24292e;color:#e1e4e8; overflow-x: auto;' 'background-color:#24292e;color:#e1e4e8; overflow-x: auto;'
); );
}); });
@ -29,8 +31,8 @@ describe('Astro Markdown Shiki', () => {
const html = await fixture.readFile('/index.html'); const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
const diffBlockHtml = $('pre').last().html(); const diffBlockHtml = $('pre').last().html();
expect(diffBlockHtml).to.contain(`<span style="user-select: none;">+</span>`); assert.ok(diffBlockHtml.includes(`<span style="user-select: none;">+</span>`));
expect(diffBlockHtml).to.contain(`<span style="user-select: none;">-</span>`); assert.ok(diffBlockHtml.includes(`<span style="user-select: none;">-</span>`));
}); });
}); });
@ -47,9 +49,10 @@ describe('Astro Markdown Shiki', () => {
const html = await fixture.readFile('/index.html'); const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('pre')).to.have.lengthOf(1); assert.strictEqual($('pre').length, 1);
expect($('pre').hasClass('astro-code')).to.equal(true); assert.ok($('pre').hasClass('astro-code'));
expect($('pre').attr().style).to.equal( assert.strictEqual(
$('pre').attr().style,
'background-color:#fff;color:#24292e; overflow-x: auto;' 'background-color:#fff;color:#24292e; overflow-x: auto;'
); );
}); });
@ -67,9 +70,10 @@ describe('Astro Markdown Shiki', () => {
const html = await fixture.readFile('/index.html'); const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('pre')).to.have.lengthOf(1); assert.strictEqual($('pre').length, 1);
expect($('pre').hasClass('astro-code')).to.equal(true); assert.ok($('pre').hasClass('astro-code'));
expect($('pre').attr().style).to.equal( assert.strictEqual(
$('pre').attr().style,
'background-color:#FDFDFE;color:#4E5377; overflow-x: auto;' 'background-color:#FDFDFE;color:#4E5377; overflow-x: auto;'
); );
}); });
@ -89,69 +93,63 @@ describe('Astro Markdown Shiki', () => {
const $ = cheerio.load(html); const $ = cheerio.load(html);
const segments = $('.line').get(6).children; const segments = $('.line').get(6).children;
expect(segments).to.have.lengthOf(2); assert.strictEqual(segments.length, 2);
expect(segments[0].attribs.style).to.be.equal('color:#79B8FF'); assert.strictEqual(segments[0].attribs.style, 'color:#79B8FF');
expect(segments[1].attribs.style).to.be.equal('color:#E1E4E8'); assert.strictEqual(segments[1].attribs.style, 'color:#E1E4E8');
const unknownLang = $('.astro-code').get(1); const unknownLang = $('.astro-code').get(1);
expect(unknownLang.attribs.style).to.contain('background-color:#24292e;color:#e1e4e8;'); assert.ok(unknownLang.attribs.style.includes('background-color:#24292e;color:#e1e4e8;'));
}); });
}); });
describe('Wrap', () => { describe('Wrapping behaviours', () => {
describe('wrap = true', () => { let fixtures = {
ifTrue: null,
ifFalse: null,
ifNull: null,
};
before(async () => {
fixtures.ifTrue = await loadFixture({
root: './fixtures/astro-markdown-shiki/wrap-true/',
});
fixtures.ifFalse = await loadFixture({
root: './fixtures/astro-markdown-shiki/wrap-false/',
});
fixtures.ifNull = await loadFixture({
root: './fixtures/astro-markdown-shiki/wrap-null/',
});
await fixtures.ifTrue.build();
await fixtures.ifFalse.build();
await fixtures.ifNull.build();
});
it('Markdown file with wrap = true', async () => {
const style = const style =
'background-color:#24292e;color:#e1e4e8; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;'; 'background-color:#24292e;color:#e1e4e8; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;';
let fixture; const html = await fixtures.ifTrue.readFile('/index.html');
before(async () => {
fixture = await loadFixture({ root: './fixtures/astro-markdown-shiki/wrap-true/' });
await fixture.build();
});
it('Markdown file', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('pre')).to.have.lengthOf(1); assert.strictEqual($('pre').length, 1);
expect($('pre').attr('style')).to.equal(style); assert.strictEqual($('pre').attr('style'), style);
});
});
}); });
describe('wrap = false', () => { it('Markdown file with wrap = false', async () => {
const style = 'background-color:#24292e;color:#e1e4e8; overflow-x: auto;'; const style = 'background-color:#24292e;color:#e1e4e8; overflow-x: auto;';
let fixture; const html = await fixtures.ifFalse.readFile('/index.html');
before(async () => {
fixture = await loadFixture({ root: './fixtures/astro-markdown-shiki/wrap-false/' });
await fixture.build();
});
it('Markdown file', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('pre')).to.have.lengthOf(1); assert.strictEqual($('pre').length, 1);
expect($('pre').attr('style')).to.equal(style); assert.strictEqual($('pre').attr('style'), style);
});
}); });
describe('wrap = null', () => { it('Markdown file with wrap = null', async () => {
const style = 'background-color:#24292e;color:#e1e4e8'; const style = 'background-color:#24292e;color:#e1e4e8';
let fixture; const html = await fixtures.ifNull.readFile('/index.html');
before(async () => {
fixture = await loadFixture({ root: './fixtures/astro-markdown-shiki/wrap-null/' });
await fixture.build();
});
it('Markdown file', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html); const $ = cheerio.load(html);
expect($('pre')).to.have.lengthOf(1); assert.strictEqual($('pre').length, 1);
expect($('pre').attr('style')).to.equal(style); assert.strictEqual($('pre').attr('style'), style);
}); });
}); });
}); });