Skip to content

Commit

Permalink
test: add a test for lazily loaded shiki languages
Browse files Browse the repository at this point in the history
This adds a test for ensuring highlighting happens when using a lazily
loaded language (typescript in this case).
  • Loading branch information
43081j committed Mar 30, 2024
1 parent dc3ebc1 commit a3e4c0a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
28 changes: 22 additions & 6 deletions packages/astro/test/astro-markdown-shiki.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,42 @@ describe('Astro Markdown Shiki', () => {
});
});

describe('Custom langs', () => {
describe('Languages', () => {
let fixture;
let $;

before(async () => {
fixture = await loadFixture({ root: './fixtures/astro-markdown-shiki/langs/' });
await fixture.build();
});

it('Markdown file', async () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
$ = cheerio.load(html);
});

const segments = $('.line').get(6).children;
it('custom language', async () => {
const lang = $('.astro-code').get(0);
const segments = $('.line', lang).get(6).children;
assert.equal(segments.length, 2);
assert.equal(segments[0].attribs.style, 'color:#79B8FF');
assert.equal(segments[1].attribs.style, 'color:#E1E4E8');
});

it('handles unknown languages', () => {
const unknownLang = $('.astro-code').get(1);
assert.ok(unknownLang.attribs.style.includes('background-color:#24292e;color:#e1e4e8;'));
});

it('handles lazy loaded languages', () => {
const lang = $('.astro-code').get(2);
const segments = $('.line', lang).get(0).children;
assert.equal(segments.length, 7);
assert.equal(segments[0].attribs.style, 'color:#F97583');
assert.equal(segments[1].attribs.style, 'color:#79B8FF');
assert.equal(segments[2].attribs.style, 'color:#F97583');
assert.equal(segments[3].attribs.style, 'color:#79B8FF');
assert.equal(segments[4].attribs.style, 'color:#F97583');
assert.equal(segments[5].attribs.style, 'color:#79B8FF');
assert.equal(segments[6].attribs.style, 'color:#E1E4E8');
});
});

describe('Wrapping behaviours', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ fin
```unknown
This language does not exist
```

```ts
const someTypeScript: number = 5;
```
2 changes: 1 addition & 1 deletion packages/create-astro/test/fixtures/not-empty/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"build": "astro build",
"preview": "astro preview"
}
}
}

0 comments on commit a3e4c0a

Please sign in to comment.