From 4526cbde264f531fb8316e5a77c141474b8b2359 Mon Sep 17 00:00:00 2001 From: 10Derozan Date: Fri, 16 Jun 2023 19:15:08 +0800 Subject: [PATCH] test(module-doc): add basic test case for module doc --- .../module-doc/tests/basic.test.ts | 60 +++++++++++++++++++ tests/integration/module-doc/tsconfig.json | 2 +- 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 tests/integration/module-doc/tests/basic.test.ts diff --git a/tests/integration/module-doc/tests/basic.test.ts b/tests/integration/module-doc/tests/basic.test.ts new file mode 100644 index 000000000000..552a08127a62 --- /dev/null +++ b/tests/integration/module-doc/tests/basic.test.ts @@ -0,0 +1,60 @@ +import { join } from 'path'; +import type { Page, Browser } from 'puppeteer'; +import puppeteer from 'puppeteer'; +import { + launchApp, + getPort, + killApp, + launchOptions, +} from '../../../utils/modernTestUtils'; + +describe('Check basic render in development', () => { + let app: any; + let page: Page; + let browser: Browser; + let appPort: number; + beforeAll(async () => { + const appDir = join(__dirname, '..'); + appPort = await getPort(); + app = await launchApp(appDir, appPort); + browser = await puppeteer.launch(launchOptions as any); + page = await browser.newPage(); + }); + + afterAll(async () => { + if (app) { + await killApp(app); + } + if (page) { + await page.close(); + } + if (browser) { + browser.close(); + } + }); + + it('Index page', async () => { + await page.goto(`http://localhost:${appPort}/en/`, { + waitUntil: ['networkidle0'], + }); + const h1 = await page.$('h1'); + const text = await page.evaluate(h1 => h1?.textContent, h1); + expect(text).toContain('Components Overview'); + // expect the .header-anchor to be rendered and take the correct href + const headerAnchor = await page.$('.header-anchor'); + const href = await page.evaluate( + headerAnchor => headerAnchor?.getAttribute('href'), + headerAnchor, + ); + expect(href).toBe('#components-overview'); + }); + + it('404 page', async () => { + await page.goto(`http://localhost:${appPort}/404`, { + waitUntil: ['networkidle0'], + }); + // find the 404 text in the page + const text = await page.evaluate(() => document.body.textContent); + expect(text).toContain('404'); + }); +}); diff --git a/tests/integration/module-doc/tsconfig.json b/tests/integration/module-doc/tsconfig.json index f4d8db55245e..f71ade587a03 100644 --- a/tests/integration/module-doc/tsconfig.json +++ b/tests/integration/module-doc/tsconfig.json @@ -7,5 +7,5 @@ "demo": ["."] } }, - "include": ["src"] + "include": ["src", "tests"] }