Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/client/logic/slides.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { SlideRoute } from '@slidev/types'
import { slides } from '#slidev/slides'

Check failure on line 2 in packages/client/logic/slides.ts

View workflow job for this annotation

GitHub Actions / test (lts/*, ubuntu-latest)

test/utils.test.ts

Error: Cannot find module '#slidev/slides' imported from '/home/runner/work/slidev/slidev/packages/client/logic/slides.ts' ❯ packages/client/logic/slides.ts:2:24 ❯ test/utils.test.ts:4:1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { code: 'ERR_MODULE_NOT_FOUND' }

Check failure on line 2 in packages/client/logic/slides.ts

View workflow job for this annotation

GitHub Actions / test (lts/*, windows-latest)

test/utils.test.ts

Error: Cannot find module '#slidev/slides' imported from 'D:/a/slidev/slidev/packages/client/logic/slides.ts' ❯ packages/client/logic/slides.ts:2:24 ❯ test/utils.test.ts:4:1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { code: 'ERR_MODULE_NOT_FOUND' }

Check failure on line 2 in packages/client/logic/slides.ts

View workflow job for this annotation

GitHub Actions / test (lts/*, macos-latest)

test/utils.test.ts

Error: Cannot find module '#slidev/slides' imported from '/Users/runner/work/slidev/slidev/packages/client/logic/slides.ts' ❯ packages/client/logic/slides.ts:2:24 ❯ test/utils.test.ts:4:1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { code: 'ERR_MODULE_NOT_FOUND' }
import { computed, watch, watchEffect } from 'vue'
import { useNav } from '../composables/useNav'
import { useSlideContext } from '../context'
Expand All @@ -20,7 +20,9 @@
if (typeof route === 'number' || typeof route === 'string')
route = getSlide(route)!
const no = route.meta.slide?.frontmatter.routeAlias ?? route.no
return exporting ? `/export/${no}` : presenter ? `/presenter/${no}` : `/${no}`
const basePath = import.meta.env.BASE_URL.replace(/\/$/, '') ?? ''
const path = exporting ? `/export/${no}` : presenter ? `/presenter/${no}` : `/${no}`
return `${basePath}${path}`
}

export function useIsSlideActive() {
Expand Down
27 changes: 26 additions & 1 deletion test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ResolvedFontOptions, SlideInfo } from '@slidev/types'
import type { ResolvedFontOptions, SlideInfo, SlideRoute } from '@slidev/types'
import { relative, resolve } from 'node:path'
import { slash } from '@antfu/utils'
import { getSlidePath } from '@slidev/client/logic/slides'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in client environment that relies on virtual modules; we can't directly test it in this file like this. We might want to extract this logic to test spareately

import MarkdownIt from 'markdown-it'
import { describe, expect, it } from 'vitest'
import YAML from 'yaml'
Expand Down Expand Up @@ -145,4 +146,28 @@ describe('utils', () => {
"
`)
})

it('getSlidePath with base path', () => {
const originalBaseUrl = import.meta.env.BASE_URL

import.meta.env.BASE_URL = '/my_monorepo/my_prez/'

const mockRoute: SlideRoute = {
no: 2,
meta: {
slide: {
frontmatter: {},
},
},
}

expect(getSlidePath(mockRoute, false, false)).toBe('/my_monorepo/my_prez/2')
expect(getSlidePath(mockRoute, true, false)).toBe('/my_monorepo/my_prez/presenter/2')
expect(getSlidePath(mockRoute, false, true)).toBe('/my_monorepo/my_prez/export/2')

import.meta.env.BASE_URL = '/'
expect(getSlidePath(mockRoute, false, false)).toBe('/2')

import.meta.env.BASE_URL = originalBaseUrl
})
})
Loading