style: format
This commit is contained in:
parent
daaa338854
commit
d477417ff6
26
src/index.ts
26
src/index.ts
|
@ -1,42 +1,42 @@
|
||||||
import * as path from 'path';
|
import * as path from "path";
|
||||||
import * as kernel from '@lumeweb/libkernel/kernel';
|
import * as kernel from "@lumeweb/libkernel/kernel";
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import StaticServer from 'static-server';
|
import StaticServer from "static-server";
|
||||||
import { Page } from 'puppeteer';
|
import { Page } from "puppeteer";
|
||||||
import { bufToHex, ed25519, ErrTuple } from '@lumeweb/libkernel';
|
import { bufToHex, ed25519, ErrTuple } from "@lumeweb/libkernel";
|
||||||
|
|
||||||
import * as url from 'url';
|
import * as url from "url";
|
||||||
|
|
||||||
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
|
||||||
|
|
||||||
export function generateSeedPhrase() {
|
export function generateSeedPhrase() {
|
||||||
return ed25519.utils.randomPrivateKey();
|
return ed25519.utils.randomPrivateKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function login(page: Page, seed = generateSeedPhrase()) {
|
export async function login(page: Page, seed = generateSeedPhrase()) {
|
||||||
await page.goto('http://kernel.lumeweb.com');
|
await page.goto("http://kernel.lumeweb.com");
|
||||||
|
|
||||||
let seedHex = bufToHex(seed);
|
let seedHex = bufToHex(seed);
|
||||||
|
|
||||||
await page.evaluate((seed: string) => {
|
await page.evaluate((seed: string) => {
|
||||||
window.localStorage.setItem('v1-key', seed);
|
window.localStorage.setItem("v1-key", seed);
|
||||||
}, seedHex);
|
}, seedHex);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function loadTester(page: Page, port = 8080) {
|
export async function loadTester(page: Page, port = 8080) {
|
||||||
const server = new StaticServer({
|
const server = new StaticServer({
|
||||||
rootPath: path.resolve(__dirname, '..', 'public'),
|
rootPath: path.resolve(__dirname, "..", "public"),
|
||||||
port,
|
port,
|
||||||
host: 'localhost',
|
host: "localhost",
|
||||||
});
|
});
|
||||||
await new Promise((resolve) => {
|
await new Promise((resolve) => {
|
||||||
server.start(resolve);
|
server.start(resolve);
|
||||||
});
|
});
|
||||||
const stop = () => server.stop();
|
const stop = () => server.stop();
|
||||||
|
|
||||||
process.on('SIGTERM', stop);
|
process.on("SIGTERM", stop);
|
||||||
page.browser().on('disconnected', stop);
|
page.browser().on("disconnected", stop);
|
||||||
|
|
||||||
await page.goto(`http://localhost:${port}/`);
|
await page.goto(`http://localhost:${port}/`);
|
||||||
await page.evaluate(() => {
|
await page.evaluate(() => {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import { loadTester, login } from '../build/index.js';
|
import { loadTester, login } from "../build/index.js";
|
||||||
|
|
||||||
import puppeteer, { Browser, Page, ProtocolError } from 'puppeteer';
|
import puppeteer, { Browser, Page, ProtocolError } from "puppeteer";
|
||||||
|
|
||||||
let browser: Browser;
|
let browser: Browser;
|
||||||
|
|
||||||
|
@ -14,10 +14,10 @@ let browser: Browser;
|
||||||
await loadTester(page);
|
await loadTester(page);
|
||||||
})();
|
})();
|
||||||
|
|
||||||
process.on('SIGTERM', async () => {
|
process.on("SIGTERM", async () => {
|
||||||
await browser.close();
|
await browser.close();
|
||||||
});
|
});
|
||||||
process.on('uncaughtException', (e) => {
|
process.on("uncaughtException", (e) => {
|
||||||
if (!(e instanceof ProtocolError)) {
|
if (!(e instanceof ProtocolError)) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import * as kernel from "@lumeweb/libkernel";
|
import * as kernel from "@lumeweb/libkernel/kernel";
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
window.kernel = kernel;
|
window.kernel = kernel;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue