From 7f979be63b0985827fd8b9714d65990470bc2082 Mon Sep 17 00:00:00 2001 From: SoonIter Date: Fri, 14 Feb 2025 22:39:16 +0800 Subject: [PATCH] fix: fix the e2e error --- e2e/tests/github-alert-mdxjs.test.ts | 65 ------------------- ...ert-mdxrs.test.ts => github-alert.test.ts} | 2 +- e2e/tests/mdx-rs.test.ts | 63 ------------------ e2e/tests/modern-js.test.ts | 45 ------------- e2e/tests/replace-rules.test.ts | 2 +- e2e/tests/title-number.test.ts | 2 +- 6 files changed, 3 insertions(+), 176 deletions(-) delete mode 100644 e2e/tests/github-alert-mdxjs.test.ts rename e2e/tests/{github-alert-mdxrs.test.ts => github-alert.test.ts} (96%) delete mode 100644 e2e/tests/mdx-rs.test.ts delete mode 100644 e2e/tests/modern-js.test.ts diff --git a/e2e/tests/github-alert-mdxjs.test.ts b/e2e/tests/github-alert-mdxjs.test.ts deleted file mode 100644 index 9efe8139d..000000000 --- a/e2e/tests/github-alert-mdxjs.test.ts +++ /dev/null @@ -1,65 +0,0 @@ -import path from 'node:path'; -import { expect, test } from '@playwright/test'; -import { getPort, killProcess, runDevCommand } from '../utils/runCommands'; - -const fixtureDir = path.resolve(__dirname, '../fixtures'); - -test.describe('github alert syntax in mdx-js', async () => { - let appPort; - let app; - test.beforeAll(async () => { - const appDir = path.join(fixtureDir, 'github-alert-mdxjs'); - appPort = await getPort(); - app = await runDevCommand(appDir, appPort); - }); - - test.afterAll(async () => { - if (app) { - await killProcess(app); - } - }); - - test('should transform github alert syntax to contain syntax', async ({ - page, - }) => { - await page.goto(`http://localhost:${appPort}`); - - const topLevelDirectives = await page.$$( - '.rspress-doc > [class^="rspress-directive"]', - ); - - expect(topLevelDirectives.length).toEqual(7); - - const listDirectives = await page.$$( - '.rspress-doc > * > li > [class^="rspress-directive"]', - ); - expect(listDirectives.length).toEqual(2); - - const stepsDirectives = await page.$$( - '.rspress-doc > .\\[counter-reset\\:step\\] * > li > [class^="rspress-directive"]', - ); - expect(stepsDirectives.length).toEqual(2); - - const containerTypes = await Promise.all( - [...topLevelDirectives, ...listDirectives, ...stepsDirectives].map( - async directive => { - const className = await directive.getAttribute('class'); - return className?.split(' ')[1]; - }, - ), - ); - expect(containerTypes).toEqual([ - 'tip', - 'note', - 'warning', - 'caution', - 'danger', - 'info', - 'details', - 'info', - 'warning', - 'info', - 'warning', - ]); - }); -}); diff --git a/e2e/tests/github-alert-mdxrs.test.ts b/e2e/tests/github-alert.test.ts similarity index 96% rename from e2e/tests/github-alert-mdxrs.test.ts rename to e2e/tests/github-alert.test.ts index e5c1c1b0c..fbfecfe18 100644 --- a/e2e/tests/github-alert-mdxrs.test.ts +++ b/e2e/tests/github-alert.test.ts @@ -8,7 +8,7 @@ test.describe('github alert syntax in mdx-rs', async () => { let appPort; let app; test.beforeAll(async () => { - const appDir = path.join(fixtureDir, 'github-alert-mdxrs'); + const appDir = path.join(fixtureDir, 'github-alert'); appPort = await getPort(); app = await runDevCommand(appDir, appPort); }); diff --git a/e2e/tests/mdx-rs.test.ts b/e2e/tests/mdx-rs.test.ts deleted file mode 100644 index f040ca108..000000000 --- a/e2e/tests/mdx-rs.test.ts +++ /dev/null @@ -1,63 +0,0 @@ -import path from 'node:path'; -import { expect, test } from '@playwright/test'; -import { getPort, killProcess, runDevCommand } from '../utils/runCommands'; - -const fixtureDir = path.resolve(__dirname, '../fixtures'); - -test.describe('i18n test', async () => { - let appPort; - let app; - test.beforeAll(async () => { - const appDir = path.join(fixtureDir, 'mdx-rs'); - appPort = await getPort(); - app = await runDevCommand(appDir, appPort); - }); - - test.afterAll(async () => { - if (app) { - await killProcess(app); - } - }); - - test('Add language prefix in route automatically when current language is not default language', async ({ - page, - }) => { - await page.goto(`http://localhost:${appPort}/en/guide/quick-start`, { - waitUntil: 'networkidle', - }); - // take the `click` button - let link = await page.getByRole('link', { - name: /absolute/, - }); - expect(link).toBeTruthy(); - // check the compile result of absolute link in doc content - expect(await link.getAttribute('href')).toBe('/en/guide/install.html'); - link = await page.getByRole('link', { - name: /relative/, - }); - - // check the compile result of relative link in doc content - expect(link).toBeTruthy(); - expect(await link.getAttribute('href')).toBe('/en/guide/install.html'); - }); - - test('Should not add language prefix when current language is default language', async ({ - page, - }) => { - await page.goto(`http://localhost:${appPort}/guide/quick-start`, { - waitUntil: 'networkidle', - }); - // check the compile result of absolute link in doc content - let link = await page.getByRole('link', { - name: /绝对路径/, - }); - expect(link).toBeTruthy(); - expect(await link.getAttribute('href')).toBe('/guide/install.html'); - // check the compile result of relative link in doc content - link = await page.getByRole('link', { - name: /相对路径/, - }); - expect(link).toBeTruthy(); - expect(await link.getAttribute('href')).toBe('/guide/install.html'); - }); -}); diff --git a/e2e/tests/modern-js.test.ts b/e2e/tests/modern-js.test.ts deleted file mode 100644 index 20aebccca..000000000 --- a/e2e/tests/modern-js.test.ts +++ /dev/null @@ -1,45 +0,0 @@ -import path from 'node:path'; -import { expect, test } from '@playwright/test'; -import { getPort, killProcess, runDevCommand } from '../utils/runCommands'; - -const fixtureDir = path.resolve(__dirname, '../fixtures'); - -test.describe('modern-js module doc test', async () => { - let appPort; - let app; - test.beforeAll(async () => { - const appDir = path.join(fixtureDir, 'modern-js'); - appPort = await getPort(); - app = await runDevCommand(appDir, appPort); - }); - - test.afterAll(async () => { - if (app) { - await killProcess(app); - } - }); - - test('Basic', async ({ page }) => { - await page.goto(`http://localhost:${appPort}/general/button`, { - waitUntil: 'networkidle', - }); - const h1 = await page.getByRole('heading', { - name: /Button/, - }); - expect(h1).toBeTruthy(); - }); - - test('preview iframe fixed should display', async ({ page }) => { - await page.goto(`http://localhost:${appPort}/general/button`, { - waitUntil: 'networkidle', - }); - - const iframe = await page.$('.fixed-device'); - const previewPadding = await iframe?.evaluate(el => { - return window - .getComputedStyle(el) - .getPropertyValue('--rp-preview-padding'); - }); - expect(previewPadding).toEqual('32px'); - }); -}); diff --git a/e2e/tests/replace-rules.test.ts b/e2e/tests/replace-rules.test.ts index b59fcaac8..1e628b65d 100644 --- a/e2e/tests/replace-rules.test.ts +++ b/e2e/tests/replace-rules.test.ts @@ -53,7 +53,7 @@ test.describe('replace-rules test', async () => { const textContent = await page.evaluate(text => text?.textContent, text); expect(titleContent).toEqual('bar-title'); - expect(h2Content).toEqual('bar-h2#'); + expect(h2Content).toEqual('#bar-h2'); expect(textContent).toEqual('bar-content'); }); }); diff --git a/e2e/tests/title-number.test.ts b/e2e/tests/title-number.test.ts index ccb717494..93418ee1d 100644 --- a/e2e/tests/title-number.test.ts +++ b/e2e/tests/title-number.test.ts @@ -24,7 +24,7 @@ test.describe('title-number test', async () => { const h3 = await page.$$('h3'); const textList = await page.evaluate(h3 => h3.map(h => h.textContent), h3); - expect(textList).toEqual(['-22222222#', '-1111111111#', '-1111111111#']); + expect(textList).toEqual(['#-22222222', '#-1111111111', '#-1111111111']); const h3A = await page.$$('h3 a'); const hrefList = await page.evaluate(