diff --git a/packages/markdown/remark/package.json b/packages/markdown/remark/package.json index ee081361df..6a398ee83b 100644 --- a/packages/markdown/remark/package.json +++ b/packages/markdown/remark/package.json @@ -31,7 +31,7 @@ "build:ci": "astro-scripts build \"src/**/*.ts\"", "postbuild": "astro-scripts copy \"src/**/*.js\"", "dev": "astro-scripts dev \"src/**/*.ts\"", - "test": "mocha --exit --timeout 20000" + "test": "astro-scripts test \"test/**/*.test.js\"" }, "dependencies": { "@astrojs/prism": "^3.0.0", diff --git a/packages/markdown/remark/test/autolinking.test.js b/packages/markdown/remark/test/autolinking.test.js index 79d3ea7679..76922e7c37 100644 --- a/packages/markdown/remark/test/autolinking.test.js +++ b/packages/markdown/remark/test/autolinking.test.js @@ -1,37 +1,43 @@ +import assert from 'node:assert/strict'; +import { describe, it, before } from 'node:test'; import { createMarkdownProcessor } from '../dist/index.js'; -import chai from 'chai'; describe('autolinking', () => { - describe('plain md', async () => { - const processor = await createMarkdownProcessor(); + describe('plain md', () => { + let processor; + + before(async () => { + processor = await createMarkdownProcessor(); + }); it('autolinks URLs starting with a protocol in plain text', async () => { - const { code } = await processor.render(`See https://example.com for more.`); + const markdown = `See https://example.com for more.`; + const { code } = await processor.render(markdown); - chai - .expect(code.replace(/\n/g, '')) - .to.equal(`

See https://example.com for more.

`); + assert.equal( + code.replace(/\n/g, ''), + `

See https://example.com for more.

` + ); }); it('autolinks URLs starting with "www." in plain text', async () => { - const { code } = await processor.render(`See www.example.com for more.`); + const markdown = `See www.example.com for more.`; + const { code } = await processor.render(markdown); - chai - .expect(code.trim()) - .to.equal(`

See www.example.com for more.

`); + assert.equal( + code.trim(), + `

See www.example.com for more.

` + ); }); it('does not autolink URLs in code blocks', async () => { - const { code } = await processor.render( - 'See `https://example.com` or `www.example.com` for more.' - ); + const markdown = `See \`https://example.com\` or \`www.example.com\` for more.`; + const { code } = await processor.render(markdown); - chai - .expect(code.trim()) - .to.equal( - `

See https://example.com or ` + - `www.example.com for more.

` - ); + assert.equal( + code.trim(), + `

See https://example.com or www.example.com for more.

` + ); }); }); }); diff --git a/packages/markdown/remark/test/browser.test.js b/packages/markdown/remark/test/browser.test.js index d78593fca1..c3831cca15 100644 --- a/packages/markdown/remark/test/browser.test.js +++ b/packages/markdown/remark/test/browser.test.js @@ -1,15 +1,20 @@ import esbuild from 'esbuild'; -import { expect } from 'chai'; +import assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; describe('Bundle for browsers', async () => { it('esbuild browser build should work', async () => { - const result = await esbuild.build({ - platform: 'browser', - entryPoints: ['@astrojs/markdown-remark'], - bundle: true, - write: false, - }); - // If some non-browser-safe stuff sneaks in, esbuild should error before reaching here - expect(result.outputFiles.length).to.be.greaterThan(0); + try { + const result = await esbuild.build({ + platform: 'browser', + entryPoints: ['@astrojs/markdown-remark'], + bundle: true, + write: false, + }); + assert.ok(result.outputFiles.length > 0); + } catch (error) { + // Capture any esbuild errors and fail the test + assert.fail(error.message); + } }); }); diff --git a/packages/markdown/remark/test/entities.test.js b/packages/markdown/remark/test/entities.test.js index b2dacb79f7..83d95f5a12 100644 --- a/packages/markdown/remark/test/entities.test.js +++ b/packages/markdown/remark/test/entities.test.js @@ -1,12 +1,18 @@ +import assert from 'node:assert/strict'; +import { describe, it, before } from 'node:test'; import { createMarkdownProcessor } from '../dist/index.js'; -import { expect } from 'chai'; describe('entities', async () => { - const processor = await createMarkdownProcessor(); + let processor; + + before(async () => { + processor = await createMarkdownProcessor(); + }); it('should not unescape entities in regular Markdown', async () => { - const { code } = await processor.render(`<i>This should NOT be italic</i>`); + const markdown = `<i>This should NOT be italic</i>`; + const { code } = await processor.render(markdown); - expect(code).to.equal(`

<i>This should NOT be italic</i>

`); + assert.equal(code, `

<i>This should NOT be italic</i>

`); }); }); diff --git a/packages/markdown/remark/test/plugins.test.js b/packages/markdown/remark/test/plugins.test.js index ce24010472..4afc364c87 100644 --- a/packages/markdown/remark/test/plugins.test.js +++ b/packages/markdown/remark/test/plugins.test.js @@ -1,20 +1,18 @@ +import assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import { createMarkdownProcessor } from '../dist/index.js'; -import chai from 'chai'; - import { fileURLToPath } from 'node:url'; describe('plugins', () => { - // https://github.com/withastro/astro/issues/3264 it('should be able to get file path when passing fileURL', async () => { let context; const processor = await createMarkdownProcessor({ remarkPlugins: [ - function () { + () => { const transformer = (tree, file) => { context = file; }; - return transformer; }, ], @@ -24,7 +22,7 @@ describe('plugins', () => { fileURL: new URL('virtual.md', import.meta.url), }); - chai.expect(typeof context).to.equal('object'); - chai.expect(context.path).to.equal(fileURLToPath(new URL('virtual.md', import.meta.url))); + assert.ok(typeof context === 'object'); + assert.equal(context.path, fileURLToPath(new URL('virtual.md', import.meta.url))); }); }); diff --git a/packages/markdown/remark/test/remark-collect-images.test.js b/packages/markdown/remark/test/remark-collect-images.test.js index 259bea96e3..77f474d944 100644 --- a/packages/markdown/remark/test/remark-collect-images.test.js +++ b/packages/markdown/remark/test/remark-collect-images.test.js @@ -1,39 +1,42 @@ +import assert from 'node:assert/strict'; +import { describe, it, before } from 'node:test'; import { createMarkdownProcessor } from '../dist/index.js'; -import chai from 'chai'; describe('collect images', async () => { - const processor = await createMarkdownProcessor(); + let processor; + + before(async () => { + processor = await createMarkdownProcessor(); + }); it('should collect inline image paths', async () => { + const markdown = `Hello ![inline image url](./img.png)`; + const fileURL = 'file.md'; + const { code, metadata: { imagePaths }, - } = await processor.render(`Hello ![inline image url](./img.png)`, { - fileURL: 'file.md', - }); + } = await processor.render(markdown, { fileURL }); - chai - .expect(code) - .to.equal( - '

Hello

' - ); + assert.equal( + code, + '

Hello

' + ); - chai.expect(Array.from(imagePaths)).to.deep.equal(['./img.png']); + assert.deepStrictEqual(Array.from(imagePaths), ['./img.png']); }); it('should add image paths from definition', async () => { - const { - code, - metadata: { imagePaths }, - } = await processor.render(`Hello ![image ref][img-ref]\n\n[img-ref]: ./img.webp`, { - fileURL: 'file.md', - }); + const markdown = `Hello ![image ref][img-ref]\n\n[img-ref]: ./img.webp`; + const fileURL = 'file.md'; - chai - .expect(code) - .to.equal( - '

Hello

' - ); - chai.expect(Array.from(imagePaths)).to.deep.equal(['./img.webp']); + const { code, metadata } = await processor.render(markdown, { fileURL }); + + assert.equal( + code, + '

Hello

' + ); + + assert.deepStrictEqual(Array.from(metadata.imagePaths), ['./img.webp']); }); }); diff --git a/packages/markdown/remark/test/shiki.test.js b/packages/markdown/remark/test/shiki.test.js index d6f3e89259..2fb40c217c 100644 --- a/packages/markdown/remark/test/shiki.test.js +++ b/packages/markdown/remark/test/shiki.test.js @@ -1,12 +1,13 @@ +import assert from 'node:assert/strict'; +import { describe, it } from 'node:test'; import { createMarkdownProcessor, createShikiHighlighter } from '../dist/index.js'; -import chai from 'chai'; describe('shiki syntax highlighting', () => { it('does not add is:raw to the output', async () => { const processor = await createMarkdownProcessor(); const { code } = await processor.render('```\ntest\n```'); - chai.expect(code).not.to.contain('is:raw'); + assert.ok(!code.includes('is:raw')); }); it('supports light/dark themes', async () => { @@ -21,11 +22,12 @@ describe('shiki syntax highlighting', () => { const { code } = await processor.render('```\ntest\n```'); // light theme is there: - chai.expect(code).to.contain('background-color:'); - chai.expect(code).to.contain('github-light'); + assert.match(code, /background-color:/); + assert.match(code, /github-light/); + // dark theme is there: - chai.expect(code).to.contain('--shiki-dark-bg:'); - chai.expect(code).to.contain('github-dark'); + assert.match(code, /--shiki-dark-bg:/); + assert.match(code, /github-dark/); }); it('createShikiHighlighter works', async () => { @@ -33,8 +35,8 @@ describe('shiki syntax highlighting', () => { const html = highlighter.highlight('const foo = "bar";', 'js'); - chai.expect(html).to.contain('astro-code github-dark'); - chai.expect(html).to.contain('background-color:#24292e;color:#e1e4e8;'); + assert.match(html, /astro-code github-dark/); + assert.match(html, /background-color:#24292e;color:#e1e4e8;/); }); it('diff +/- text has user-select: none', async () => { @@ -46,8 +48,9 @@ describe('shiki syntax highlighting', () => { + const foo = "world";`, 'diff' ); - chai.expect(html).to.contain('user-select: none'); - chai.expect(html).to.contain('>-'); - chai.expect(html).to.contain('>+'); + + assert.match(html, /user-select: none/); + assert.match(html, />-<\/span>/); + assert.match(html, />+<\/span>/); }); });