starting inline server inside tests

This commit is contained in:
Pavel Murygin
2022-02-17 20:46:45 +03:00
parent f7bc5bdc97
commit 7bb0900713
9 changed files with 3099 additions and 49 deletions

View File

@ -1,10 +1,37 @@
import { Page } from 'puppeteer';
import handler from 'serve-handler';
import http from 'http';
import path from 'path';
const port = 3000;
const uri = `http://localhost:${port}/`
const publicPath = path.join(__dirname, '../../build/');
console.log(publicPath);
const server = http.createServer((request, response) => {
return handler(request, response, {
public: publicPath
});
})
const startServer = async () => {
return new Promise((resolve: any) => {
server.listen(3000, resolve);
})
}
const stopServer = async () => {
return new Promise((resolve: any) => {
server.close(resolve);
})
}
const peerIdLength = '12D3KooWM2CYSHefG6KPKbYFAgsbPh8p6b8HYHc6VNkge2rPtYv5'.length;
const loadApp = async (page: Page) => {
console.log('opening page...');
await page.goto('http://localhost:3000/');
await page.goto(uri);
console.log('clicking connect button...');
await page.click('.btn');
@ -34,6 +61,10 @@ const waitForSelectorAndGetText = async (page: Page, selector: string) => {
};
describe('smoke test', () => {
beforeAll(startServer);
afterAll(stopServer);
it('should work', async () => {
const page1 = await browser.newPage();
const page2 = await browser.newPage();