WIP: unverified Codex job pr-474-pkjviimq
このコミットが含まれているのは:
@@ -2,6 +2,7 @@ import { fireEvent, screen, waitFor } from '@testing-library/react'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import PostEmbed from '@/components/PostEmbed'
|
||||
import { setClientEmbedAutoLoadMode } from '@/lib/settings'
|
||||
import { buildPost } from '@/test/factories'
|
||||
import { renderWithProviders as render } from '@/test/render'
|
||||
|
||||
@@ -110,6 +111,75 @@ describe ('PostEmbed', () => {
|
||||
expect (screen.getByText ('YouTube:abc123')).toBeInTheDocument ()
|
||||
})
|
||||
|
||||
it.each ([
|
||||
'https://www.tiktok.com/@someone/video/7123456789012345678',
|
||||
'https://www.tiktok.com/@someone/video/7123456789012345678/',
|
||||
'https://www.tiktok.com/@someone/video/7123456789012345678?lang=ja',
|
||||
'https://m.tiktok.com/@someone/video/7123456789012345678']) (
|
||||
'embeds TikTok video URL %s with the official player', url => {
|
||||
render (<PostEmbed post={buildPost ({ url, title: 'TikTok video' })}/>)
|
||||
|
||||
const iframe = screen.getByTitle ('TikTok video')
|
||||
expect (iframe.tagName).toBe ('IFRAME')
|
||||
expect (iframe).toHaveAttribute (
|
||||
'src', 'https://www.tiktok.com/player/v1/7123456789012345678')
|
||||
expect (iframe).toHaveAttribute ('allowfullscreen')
|
||||
expect (dialogue.confirm).not.toHaveBeenCalled ()
|
||||
})
|
||||
|
||||
it ('uses the TikTok URL as the iframe title for an empty post title', () => {
|
||||
const url = 'https://www.tiktok.com/@someone/video/7123456789012345678'
|
||||
render (<PostEmbed post={buildPost ({ url, title: '' })}/>)
|
||||
|
||||
expect (screen.getByTitle (url)).toHaveAttribute (
|
||||
'src', 'https://www.tiktok.com/player/v1/7123456789012345678')
|
||||
})
|
||||
|
||||
it.each ([
|
||||
'https://vm.tiktok.com/ABCDE/',
|
||||
'https://vt.tiktok.com/ABCDE/',
|
||||
'https://www.tiktok.com/@someone',
|
||||
'https://www.tiktok.com/@someone/video/not-a-number',
|
||||
'https://www.tiktok.com/@someone/video/7123456789012345678/extra']) (
|
||||
'keeps unsupported TikTok URL %s behind external-page confirmation', url => {
|
||||
const { container } = render (<PostEmbed post={buildPost ({ url })}/>)
|
||||
|
||||
expect (container.querySelector ('iframe')).not.toBeInTheDocument ()
|
||||
expect (screen.getByRole ('link', { name: '外部ページを表示' }))
|
||||
.toBeInTheDocument ()
|
||||
expect (dialogue.confirm).not.toHaveBeenCalled ()
|
||||
})
|
||||
|
||||
it ('loads TikTok manually only after the load button is clicked', () => {
|
||||
setClientEmbedAutoLoadMode ('manual')
|
||||
const url = 'https://www.tiktok.com/@someone/video/7123456789012345678'
|
||||
const { container } = render (
|
||||
<PostEmbed post={buildPost ({ url, title: 'TikTok video' })}/>)
|
||||
|
||||
expect (container.querySelector ('iframe')).not.toBeInTheDocument ()
|
||||
expect (screen.getByRole ('link', { name: '外部ページを開く' }))
|
||||
.toHaveAttribute ('href', url)
|
||||
|
||||
fireEvent.click (screen.getByRole ('button', { name: '埋め込みを読込' }))
|
||||
|
||||
expect (screen.getByTitle ('TikTok video')).toHaveAttribute (
|
||||
'src', 'https://www.tiktok.com/player/v1/7123456789012345678')
|
||||
expect (dialogue.confirm).not.toHaveBeenCalled ()
|
||||
})
|
||||
|
||||
it ('offers only an external link when TikTok embedding is off', () => {
|
||||
setClientEmbedAutoLoadMode ('off')
|
||||
const url = 'https://www.tiktok.com/@someone/video/7123456789012345678'
|
||||
const { container } = render (<PostEmbed post={buildPost ({ url })}/>)
|
||||
|
||||
expect (container.querySelector ('iframe')).not.toBeInTheDocument ()
|
||||
expect (screen.queryByRole ('button', { name: '埋め込みを読込' }))
|
||||
.not.toBeInTheDocument ()
|
||||
const link = screen.getByRole ('link', { name: '外部ページを開く' })
|
||||
expect (link).toHaveAttribute ('href', url)
|
||||
expect (link).toHaveAttribute ('target', '_blank')
|
||||
})
|
||||
|
||||
it ('asks before framing unknown external pages', async () => {
|
||||
dialogue.confirm.mockResolvedValueOnce (true)
|
||||
render (
|
||||
|
||||
@@ -10,7 +10,8 @@ type Transform = (source: string, id: string) => Promise<{ code: string } | null
|
||||
|
||||
|
||||
export const transformMdx = async (source: string, suffix = '.mdx') => {
|
||||
const plugins = viteConfig.plugins?.flat () as { name: string; transform: Transform }[]
|
||||
const config = viteConfig ({ command: 'serve', mode: 'test' })
|
||||
const plugins = config.plugins?.flat () as { name: string; transform: Transform }[]
|
||||
const plugin = plugins.find (entry => entry.name === '@mdx-js/rollup')
|
||||
if (plugin == null)
|
||||
throw new Error ('The application MDX compiler is not registered')
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { resolveConfig, transformWithEsbuild } from 'vite'
|
||||
import { afterAll, afterEach, expect, it, vi } from 'vitest'
|
||||
|
||||
vi.hoisted (() => {
|
||||
vi.stubGlobal ('Uint8Array', Object.getPrototypeOf (new TextEncoder ().encode ('')).constructor)
|
||||
})
|
||||
afterAll (() => vi.unstubAllGlobals ())
|
||||
|
||||
afterEach (() => {
|
||||
vi.unstubAllEnvs ()
|
||||
})
|
||||
|
||||
it ('builds JSX for the production runtime under a development NODE_ENV', async () => {
|
||||
vi.stubEnv ('NODE_ENV', 'development')
|
||||
const config = await resolveConfig ({
|
||||
configFile: fileURLToPath (new URL ('./vite.config.ts', import.meta.url)) }, 'build')
|
||||
|
||||
expect (config.esbuild).not.toBe (false)
|
||||
if (config.esbuild === false)
|
||||
throw new Error ('esbuild is required for JSX transformation')
|
||||
|
||||
const result = await transformWithEsbuild (
|
||||
'export const element = <div />',
|
||||
'regression.tsx',
|
||||
{ jsx: 'automatic', jsxDev: config.esbuild.jsxDev })
|
||||
|
||||
expect (result.code).toContain ('"react/jsx-runtime"')
|
||||
expect (result.code).not.toContain ('jsxDEV')
|
||||
expect (result.code).not.toContain ('jsx-dev-runtime')
|
||||
})
|
||||
@@ -21,7 +21,8 @@ if (typeof originalTransform === 'function')
|
||||
}
|
||||
}
|
||||
|
||||
export default defineConfig ({
|
||||
export default defineConfig (({ command }) => ({
|
||||
esbuild: command === 'build' ? { jsxDev: false } : undefined,
|
||||
plugins: [{ name: 'request-render-context', enforce: 'pre',
|
||||
resolveId (id, _importer, options) {
|
||||
const contextPath = path.resolve (__dirname, './src/lib/renderContext')
|
||||
@@ -40,4 +41,4 @@ export default defineConfig ({
|
||||
rewrite: requestPath => requestPath.replace (/^\/api/, ''),
|
||||
secure: false } },
|
||||
watch: { usePolling: true,
|
||||
interval: 100 } } })
|
||||
interval: 100 } } }))
|
||||
|
||||
@@ -3,9 +3,9 @@ import { defineConfig, mergeConfig } from 'vitest/config'
|
||||
import viteConfig from './vite.config'
|
||||
|
||||
|
||||
export default mergeConfig (
|
||||
viteConfig,
|
||||
defineConfig ({
|
||||
export default defineConfig (environment => mergeConfig (
|
||||
viteConfig (environment),
|
||||
{
|
||||
test: { environment: 'jsdom',
|
||||
testTimeout: 30_000,
|
||||
exclude: ['**/node_modules/**', '**/dist/**', 'server.ssr.test.mjs'],
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする