Skip to content

Commit

Permalink
chore: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jan 14, 2025
1 parent 4efd5cf commit 2237c2e
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 124 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "module",
"version": "1.26.2",
"private": true,
"packageManager": "[email protected].3",
"packageManager": "[email protected].4",
"scripts": {
"lint": "eslint . --cache",
"release": "bumpp",
Expand Down
36 changes: 24 additions & 12 deletions packages/shiki/test/decorations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe('decorations errors', () => {
})

it('throws when decorations intersect', async () => {
expect(async () => {
await expect(async () => {
await codeToHtml(code, {
theme: 'vitesse-light',
lang: 'ts',
Expand All @@ -120,33 +120,39 @@ describe('decorations errors', () => {
{ start: 5, end: 15 },
],
})
}).rejects.toThrowErrorMatchingInlineSnapshot(`[ShikiError: Decorations {"line":0,"character":0,"offset":0} and {"line":1,"character":1,"offset":5} intersect.]`)
})
.rejects
.toThrowErrorMatchingInlineSnapshot(`[ShikiError: Decorations {"line":0,"character":0,"offset":0} and {"line":1,"character":1,"offset":5} intersect.]`)
})

it('throws when lines overflow', async () => {
expect(async () => {
await expect(async () => {
await codeToHtml(code, {
theme: 'vitesse-light',
lang: 'ts',
decorations: [
{ start: { line: 100, character: 0 }, end: { line: 100, character: 1 } },
],
})
}).rejects.toThrowErrorMatchingInlineSnapshot(`[ShikiError: Invalid decoration position {"line":100,"character":0}. Lines length: 12]`)
})
.rejects
.toThrowErrorMatchingInlineSnapshot(`[ShikiError: Invalid decoration position {"line":100,"character":0}. Lines length: 12]`)
})

it('throws when chars overflow', async () => {
expect(async () => {
await expect(async () => {
await codeToHtml(code, {
theme: 'vitesse-light',
lang: 'ts',
decorations: [
{ start: { line: 0, character: 0 }, end: { line: 0, character: 10 } },
],
})
}).rejects.toThrowErrorMatchingInlineSnapshot(`[ShikiError: Invalid decoration position {"line":0,"character":10}. Line 0 length: 4]`)
})
.rejects
.toThrowErrorMatchingInlineSnapshot(`[ShikiError: Invalid decoration position {"line":0,"character":10}. Line 0 length: 4]`)

expect(async () => {
await expect(async () => {
await codeToHtml(code, {
theme: 'vitesse-light',
lang: 'ts',
Expand All @@ -157,24 +163,30 @@ describe('decorations errors', () => {
},
],
})
}).rejects.toThrowErrorMatchingInlineSnapshot(`[ShikiError: Invalid decoration position {"line":1,"character":36}. Line 1 length: 33]`)
})
.rejects
.toThrowErrorMatchingInlineSnapshot(`[ShikiError: Invalid decoration position {"line":1,"character":36}. Line 1 length: 33]`)
})

it('throws when offset underflows/overflows', async () => {
expect(async () => {
await expect(async () => {
await codeToHtml(code, {
theme: 'vitesse-light',
lang: 'ts',
decorations: [{ start: 1, end: 1000 }],
})
}).rejects.toThrowErrorMatchingInlineSnapshot(`[ShikiError: Invalid decoration offset: 1000. Code length: 252]`)
})
.rejects
.toThrowErrorMatchingInlineSnapshot(`[ShikiError: Invalid decoration offset: 1000. Code length: 252]`)

expect(async () => {
await expect(async () => {
await codeToHtml(code, {
theme: 'vitesse-light',
lang: 'ts',
decorations: [{ start: -3, end: 5 }],
})
}).rejects.toThrowErrorMatchingInlineSnapshot(`[ShikiError: Invalid decoration offset: -3. Code length: 252]`)
})
.rejects
.toThrowErrorMatchingInlineSnapshot(`[ShikiError: Invalid decoration offset: -3. Code length: 252]`)
})
})
4 changes: 2 additions & 2 deletions packages/shiki/test/injections.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,13 @@ export class CartButtonComponent {
`

const before = highlighter.codeToHtml(code, { lang: 'ts', theme: 'vitesse-light' })
expect(before)
await expect(before)
.toMatchFileSnapshot('./out/injections-side-effects-angular-ts-before.html')

await highlighter.loadLanguage(angularTs)

const after = highlighter.codeToHtml(code, { lang: 'angular-ts', theme: 'vitesse-light' })
expect(after)
await expect(after)
.toMatchFileSnapshot('./out/injections-side-effects-angular-ts-after.html')

expect(before).not.toEqual(after)
Expand Down
10 changes: 5 additions & 5 deletions packages/shiki/test/themes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('codeToHtml', () => {
<button onclick="document.body.classList.toggle('dark')">Toggle theme</button>
`

expect(snippet + code)
await expect(snippet + code)
.toMatchFileSnapshot('./out/dual-themes.html')
})

Expand Down Expand Up @@ -117,7 +117,7 @@ function toggleTheme() {
<button onclick="toggleTheme()">Toggle theme</button>
`

expect(snippet + code)
await expect(snippet + code)
.toMatchFileSnapshot('./out/multiple-themes.html')
})

Expand Down Expand Up @@ -320,7 +320,7 @@ describe('codeToTokensWithThemes', () => {

describe('errors', () => {
it('throws on empty theme', async () => {
expect(() => codeToHtml('console.log("hello")', {
await expect(() => codeToHtml('console.log("hello")', {
lang: 'js',
themes: {},
}))
Expand All @@ -329,7 +329,7 @@ describe('errors', () => {
})

it('throws on missing default color', async () => {
expect(() => codeToHtml('console.log("hello")', {
await expect(() => codeToHtml('console.log("hello")', {
lang: 'js',
themes: {
dark: 'nord',
Expand All @@ -338,7 +338,7 @@ describe('errors', () => {
.rejects
.toThrowErrorMatchingInlineSnapshot(`[ShikiError: \`themes\` option must contain the defaultColor key \`light\`]`)

expect(() => codeToHtml('console.log("hello")', {
await expect(() => codeToHtml('console.log("hello")', {
lang: 'js',
themes: {
light: 'nord',
Expand Down
2 changes: 1 addition & 1 deletion packages/twoslash/test/target-multi-tokens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ it('should split tokens correctly', async () => {
],
})

expect(
await expect(
`<link rel="stylesheet" href="../../style-rich.css" />\n${html}`,
)
.toMatchFileSnapshot('./out/error-multi-tokens.html')
Expand Down
Loading

0 comments on commit 2237c2e

Please sign in to comment.