Skip to content

Commit

Permalink
test(module-doc): add basic test case for module doc (#3998)
Browse files Browse the repository at this point in the history
  • Loading branch information
10Derozan committed Jun 20, 2023
1 parent 4fdd868 commit ae16058
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
60 changes: 60 additions & 0 deletions tests/integration/module-doc/tests/basic.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});
2 changes: 1 addition & 1 deletion tests/integration/module-doc/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"demo": ["."]
}
},
"include": ["src"]
"include": ["src", "tests"]
}

0 comments on commit ae16058

Please sign in to comment.