mirror of
https://github.com/logos-messaging/examples.waku.org.git
synced 2026-01-02 12:53:08 +00:00
add: eslint & lint all files
This commit is contained in:
parent
ad39ef04b4
commit
a274982457
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
. "$(dirname -- "$0")/_/husky.sh"
|
. "$(dirname -- "$0")/_/husky.sh"
|
||||||
|
|
||||||
npx lint-staged
|
pnpx lint-staged
|
||||||
|
|||||||
50
ci/deploy.js
50
ci/deploy.js
@ -1,39 +1,43 @@
|
|||||||
const { promisify } = require('util')
|
const { promisify } = require("util");
|
||||||
const { publish } = require('gh-pages')
|
const { publish } = require("gh-pages");
|
||||||
const ghpublish = promisify(publish)
|
const ghpublish = promisify(publish);
|
||||||
|
|
||||||
/* fix for "Unhandled promise rejections" */
|
/* fix for "Unhandled promise rejections" */
|
||||||
process.on('unhandledRejection', err => { throw err })
|
process.on("unhandledRejection", (err) => {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
|
||||||
const Args = process.argv.slice(2)
|
const Args = process.argv.slice(2);
|
||||||
const USE_HTTPS = Args[0] && Args[0].toUpperCase() === 'HTTPS'
|
const USE_HTTPS = Args[0] && Args[0].toUpperCase() === "HTTPS";
|
||||||
|
|
||||||
const branch = 'gh-pages'
|
const branch = "gh-pages";
|
||||||
const org = 'waku-org'
|
const org = "waku-org";
|
||||||
const repo = 'js-waku-examples'
|
const repo = "js-waku-examples";
|
||||||
/* use SSH auth by default */
|
/* use SSH auth by default */
|
||||||
let repoUrl = USE_HTTPS
|
let repoUrl = USE_HTTPS
|
||||||
? `https://github.com/${org}/${repo}.git`
|
? `https://github.com/${org}/${repo}.git`
|
||||||
: `git@github.com:${org}/${repo}.git`
|
: `git@github.com:${org}/${repo}.git`;
|
||||||
|
|
||||||
/* alternative auth using GitHub user and API token */
|
/* alternative auth using GitHub user and API token */
|
||||||
if (process.env.GH_USER != undefined) {
|
if (process.env.GH_USER != undefined) {
|
||||||
repoUrl = (
|
repoUrl =
|
||||||
'https://' + process.env.GH_USER +
|
"https://" +
|
||||||
':' + process.env.GH_TOKEN +
|
process.env.GH_USER +
|
||||||
'@' + `github.com/${org}/${repo}.git`
|
":" +
|
||||||
)
|
process.env.GH_TOKEN +
|
||||||
|
"@" +
|
||||||
|
`github.com/${org}/${repo}.git`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const main = async (url, branch)=> {
|
const main = async (url, branch) => {
|
||||||
console.log(`Pushing to: ${url}`)
|
console.log(`Pushing to: ${url}`);
|
||||||
console.log(`On branch: ${branch}`)
|
console.log(`On branch: ${branch}`);
|
||||||
await ghpublish('build/docs', {
|
await ghpublish("build/docs", {
|
||||||
repo: url,
|
repo: url,
|
||||||
branch: branch,
|
branch: branch,
|
||||||
dotfiles: true,
|
dotfiles: true,
|
||||||
silent: false
|
silent: false,
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
main(repoUrl, branch)
|
main(repoUrl, branch);
|
||||||
|
|||||||
@ -1,121 +1,129 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang='en'>
|
<html lang="en">
|
||||||
|
<head>
|
||||||
<head>
|
<meta charset="UTF-8" />
|
||||||
<meta charset='UTF-8'/>
|
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
|
||||||
<meta content='width=device-width, initial-scale=1.0' name='viewport'/>
|
|
||||||
<title>JS-Waku light node example</title>
|
<title>JS-Waku light node example</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
<div><h2>Status</h2></div>
|
||||||
|
<div id="status"></div>
|
||||||
|
|
||||||
<div><h2>Status</h2></div>
|
<div><h2>Local Peer Id</h2></div>
|
||||||
<div id='status'></div>
|
<div id="peer-id"></div>
|
||||||
|
|
||||||
<div><h2>Local Peer Id</h2></div>
|
<div><h2>Remote Peer Id</h2></div>
|
||||||
<div id='peer-id'></div>
|
<div id="remote-peer-id"></div>
|
||||||
|
|
||||||
<div><h2>Remote Peer Id</h2></div>
|
<label for="remote-multiaddr">Remote peer's multiaddr</label>
|
||||||
<div id='remote-peer-id'></div>
|
<input
|
||||||
|
id="remote-multiaddr"
|
||||||
|
type="text"
|
||||||
|
value="/dns4/node-01.ac-cn-hongkong-c.wakuv2.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAkvWiyFsgRhuJEb9JfjYxEkoHLgnUQmr1N5mKWnYjxYRVm"
|
||||||
|
/>
|
||||||
|
<button disabled id="dial" type="button">Dial</button>
|
||||||
|
<br />
|
||||||
|
<button disabled id="subscribe" type="button">Subscribe with Filter</button>
|
||||||
|
<button disabled id="unsubscribe" type="button">
|
||||||
|
Unsubscribe with Filter
|
||||||
|
</button>
|
||||||
|
<br />
|
||||||
|
<label for="textInput">Message text</label>
|
||||||
|
<input id="textInput" placeholder="Type your message here" type="text" />
|
||||||
|
<button disabled id="sendButton" type="button">
|
||||||
|
Send message using Light Push
|
||||||
|
</button>
|
||||||
|
<br />
|
||||||
|
<div id="messages"></div>
|
||||||
|
|
||||||
<label for='remote-multiaddr'>Remote peer's multiaddr</label>
|
<script type="module">
|
||||||
<input id='remote-multiaddr'
|
import * as utils from "https://unpkg.com/@waku/byte-utils@0.0.2/bundle/index.js";
|
||||||
type='text'
|
import { createLightNode } from "https://unpkg.com/@waku/create@0.0.4/bundle/index.js";
|
||||||
value="/dns4/node-01.ac-cn-hongkong-c.wakuv2.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAkvWiyFsgRhuJEb9JfjYxEkoHLgnUQmr1N5mKWnYjxYRVm">
|
import { waitForRemotePeer } from "https://unpkg.com/@waku/core@0.0.6/bundle/lib/wait_for_remote_peer.js";
|
||||||
<button disabled id='dial' type='button'>Dial</button>
|
import {
|
||||||
<br/>
|
EncoderV0,
|
||||||
<button disabled id='subscribe' type='button'>Subscribe with Filter</button>
|
DecoderV0,
|
||||||
<button disabled id='unsubscribe' type='button'>Unsubscribe with Filter</button>
|
} from "https://unpkg.com/@waku/core@0.0.6/bundle/lib/waku_message/version_0.js";
|
||||||
<br/>
|
|
||||||
<label for='textInput'>Message text</label>
|
|
||||||
<input id='textInput' placeholder='Type your message here' type='text'>
|
|
||||||
<button disabled id='sendButton' type='button'>Send message using Light Push</button>
|
|
||||||
<br/>
|
|
||||||
<div id="messages"></div>
|
|
||||||
|
|
||||||
<script type='module'>
|
const peerIdDiv = document.getElementById("peer-id");
|
||||||
import * as utils from 'https://unpkg.com/@waku/byte-utils@0.0.2/bundle/index.js';
|
const remotePeerIdDiv = document.getElementById("remote-peer-id");
|
||||||
import {createLightNode} from 'https://unpkg.com/@waku/create@0.0.4/bundle/index.js'
|
const statusDiv = document.getElementById("status");
|
||||||
import {waitForRemotePeer} from 'https://unpkg.com/@waku/core@0.0.6/bundle/lib/wait_for_remote_peer.js'
|
const remoteMultiAddrDiv = document.getElementById("remote-multiaddr");
|
||||||
import {EncoderV0, DecoderV0} from 'https://unpkg.com/@waku/core@0.0.6/bundle/lib/waku_message/version_0.js'
|
const dialButton = document.getElementById("dial");
|
||||||
|
const subscribeButton = document.getElementById("subscribe");
|
||||||
|
const unsubscribeButton = document.getElementById("unsubscribe");
|
||||||
|
const messagesDiv = document.getElementById("messages");
|
||||||
|
const textInput = document.getElementById("textInput");
|
||||||
|
const sendButton = document.getElementById("sendButton");
|
||||||
|
|
||||||
const peerIdDiv = document.getElementById('peer-id');
|
const ContentTopic = "/js-waku-examples/1/chat/utf8";
|
||||||
const remotePeerIdDiv = document.getElementById('remote-peer-id');
|
const decoder = new DecoderV0(ContentTopic);
|
||||||
const statusDiv = document.getElementById('status');
|
const encoder = new EncoderV0(ContentTopic);
|
||||||
const remoteMultiAddrDiv = document.getElementById('remote-multiaddr');
|
let messages = [];
|
||||||
const dialButton = document.getElementById('dial')
|
let unsubscribe;
|
||||||
const subscribeButton = document.getElementById('subscribe')
|
|
||||||
const unsubscribeButton = document.getElementById('unsubscribe')
|
|
||||||
const messagesDiv = document.getElementById('messages')
|
|
||||||
const textInput = document.getElementById('textInput');
|
|
||||||
const sendButton = document.getElementById('sendButton');
|
|
||||||
|
|
||||||
const ContentTopic = "/js-waku-examples/1/chat/utf8";
|
const updateMessages = (msgs, div) => {
|
||||||
const decoder = new DecoderV0(ContentTopic);
|
div.innerHTML = "<ul>";
|
||||||
const encoder = new EncoderV0(ContentTopic);
|
messages.forEach((msg) => (div.innerHTML += "<li>" + msg + "</li>"));
|
||||||
let messages = [];
|
div.innerHTML += "</ul>";
|
||||||
let unsubscribe;
|
};
|
||||||
|
|
||||||
const updateMessages = (msgs, div) => {
|
statusDiv.innerHTML = "<p>Creating Waku node.</p>";
|
||||||
div.innerHTML = "<ul>"
|
const node = await createLightNode();
|
||||||
messages.forEach(msg => div.innerHTML += "<li>" + msg + "</li>")
|
|
||||||
div.innerHTML += "</ul>"
|
|
||||||
}
|
|
||||||
|
|
||||||
statusDiv.innerHTML = '<p>Creating Waku node.</p>';
|
statusDiv.innerHTML = "<p>Starting Waku node.</p>";
|
||||||
const node = await createLightNode();
|
await node.start();
|
||||||
|
statusDiv.innerHTML = "<p>Waku node started.</p>";
|
||||||
|
peerIdDiv.innerHTML = "<p>" + node.libp2p.peerId.toString() + "</p>";
|
||||||
|
dialButton.disabled = false;
|
||||||
|
|
||||||
statusDiv.innerHTML = '<p>Starting Waku node.</p>';
|
dialButton.onclick = async () => {
|
||||||
await node.start();
|
const ma = remoteMultiAddrDiv.value;
|
||||||
statusDiv.innerHTML = '<p>Waku node started.</p>';
|
|
||||||
peerIdDiv.innerHTML = '<p>' + node.libp2p.peerId.toString() + '</p>'
|
|
||||||
dialButton.disabled = false;
|
|
||||||
|
|
||||||
dialButton.onclick = async () => {
|
|
||||||
const ma = remoteMultiAddrDiv.value
|
|
||||||
if (!ma) {
|
if (!ma) {
|
||||||
statusDiv.innerHTML = '<p>Error: No multiaddr provided.</p>';
|
statusDiv.innerHTML = "<p>Error: No multiaddr provided.</p>";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
statusDiv.innerHTML = '<p>Dialing peer.</p>';
|
statusDiv.innerHTML = "<p>Dialing peer.</p>";
|
||||||
await node.dial(ma, ["filter", "lightpush"])
|
await node.dial(ma, ["filter", "lightpush"]);
|
||||||
await waitForRemotePeer(node, ["filter", "lightpush"]);
|
await waitForRemotePeer(node, ["filter", "lightpush"]);
|
||||||
const peers = await node.libp2p.peerStore.all();
|
const peers = await node.libp2p.peerStore.all();
|
||||||
statusDiv.innerHTML = '<p>Peer dialed.</p>';
|
statusDiv.innerHTML = "<p>Peer dialed.</p>";
|
||||||
remotePeerIdDiv.innerHTML = '<p>' + peers[0].id.toString() + '</p>'
|
remotePeerIdDiv.innerHTML = "<p>" + peers[0].id.toString() + "</p>";
|
||||||
textInput.disabled = false;
|
textInput.disabled = false;
|
||||||
sendButton.disabled = false;
|
sendButton.disabled = false;
|
||||||
subscribeButton.disabled = false;
|
subscribeButton.disabled = false;
|
||||||
}
|
};
|
||||||
|
|
||||||
const callback = (wakuMessage) => {
|
const callback = (wakuMessage) => {
|
||||||
const text = utils.bytesToUtf8(wakuMessage.payload)
|
const text = utils.bytesToUtf8(wakuMessage.payload);
|
||||||
const timestamp = wakuMessage.timestamp.toString()
|
const timestamp = wakuMessage.timestamp.toString();
|
||||||
messages.push(text + " - " + timestamp)
|
messages.push(text + " - " + timestamp);
|
||||||
updateMessages(messages, messagesDiv)
|
updateMessages(messages, messagesDiv);
|
||||||
}
|
};
|
||||||
|
|
||||||
subscribeButton.onclick = async () => {
|
subscribeButton.onclick = async () => {
|
||||||
unsubscribe = await node.filter.subscribe([decoder], callback)
|
unsubscribe = await node.filter.subscribe([decoder], callback);
|
||||||
unsubscribeButton.disabled = false;
|
unsubscribeButton.disabled = false;
|
||||||
subscribeButton.disabled = true;
|
subscribeButton.disabled = true;
|
||||||
}
|
};
|
||||||
|
|
||||||
unsubscribeButton.onclick = async () => {
|
unsubscribeButton.onclick = async () => {
|
||||||
await unsubscribe();
|
await unsubscribe();
|
||||||
unsubscribe = undefined
|
unsubscribe = undefined;
|
||||||
unsubscribeButton.disabled = true;
|
unsubscribeButton.disabled = true;
|
||||||
subscribeButton.disabled = false;
|
subscribeButton.disabled = false;
|
||||||
}
|
};
|
||||||
|
|
||||||
sendButton.onclick = async () => {
|
sendButton.onclick = async () => {
|
||||||
const text = textInput.value;
|
const text = textInput.value;
|
||||||
|
|
||||||
await node.lightPush.push(encoder, {payload: utils.utf8ToBytes(text)});
|
await node.lightPush.push(encoder, {
|
||||||
console.log('Message sent!');
|
payload: utils.utf8ToBytes(text),
|
||||||
|
});
|
||||||
|
console.log("Message sent!");
|
||||||
textInput.value = null;
|
textInput.value = null;
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
"prepare": "husky install"
|
"prepare": "husky install"
|
||||||
},
|
},
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
"*.{js,css,md,html}": "prettier --write"
|
"*.{html,css,js,ts,jsx,tsx,json}": "prettier --write",
|
||||||
|
"*.{js,ts}": "eslint --fix"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,13 +21,8 @@
|
|||||||
"index": "src/index.html",
|
"index": "src/index.html",
|
||||||
"main": "src/main.ts",
|
"main": "src/main.ts",
|
||||||
"tsConfig": "tsconfig.app.json",
|
"tsConfig": "tsconfig.app.json",
|
||||||
"assets": [
|
"assets": ["src/favicon.ico", "src/assets"],
|
||||||
"src/favicon.ico",
|
"styles": ["src/styles.css"],
|
||||||
"src/assets"
|
|
||||||
],
|
|
||||||
"styles": [
|
|
||||||
"src/styles.css"
|
|
||||||
],
|
|
||||||
"scripts": []
|
"scripts": []
|
||||||
},
|
},
|
||||||
"configurations": {
|
"configurations": {
|
||||||
@ -87,13 +82,8 @@
|
|||||||
"main": "src/test.ts",
|
"main": "src/test.ts",
|
||||||
"tsConfig": "tsconfig.spec.json",
|
"tsConfig": "tsconfig.spec.json",
|
||||||
"karmaConfig": "karma.conf.js",
|
"karmaConfig": "karma.conf.js",
|
||||||
"assets": [
|
"assets": ["src/favicon.ico", "src/assets"],
|
||||||
"src/favicon.ico",
|
"styles": ["src/styles.css"],
|
||||||
"src/assets"
|
|
||||||
],
|
|
||||||
"styles": [
|
|
||||||
"src/styles.css"
|
|
||||||
],
|
|
||||||
"scripts": []
|
"scripts": []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,14 +3,14 @@
|
|||||||
|
|
||||||
module.exports = function (config) {
|
module.exports = function (config) {
|
||||||
config.set({
|
config.set({
|
||||||
basePath: '',
|
basePath: "",
|
||||||
frameworks: ['jasmine', '@angular-devkit/build-angular'],
|
frameworks: ["jasmine", "@angular-devkit/build-angular"],
|
||||||
plugins: [
|
plugins: [
|
||||||
require('karma-jasmine'),
|
require("karma-jasmine"),
|
||||||
require('karma-chrome-launcher'),
|
require("karma-chrome-launcher"),
|
||||||
require('karma-jasmine-html-reporter'),
|
require("karma-jasmine-html-reporter"),
|
||||||
require('karma-coverage'),
|
require("karma-coverage"),
|
||||||
require('@angular-devkit/build-angular/plugins/karma')
|
require("@angular-devkit/build-angular/plugins/karma"),
|
||||||
],
|
],
|
||||||
client: {
|
client: {
|
||||||
jasmine: {
|
jasmine: {
|
||||||
@ -19,26 +19,23 @@ module.exports = function (config) {
|
|||||||
// for example, you can disable the random execution with `random: false`
|
// for example, you can disable the random execution with `random: false`
|
||||||
// or set a specific seed with `seed: 4321`
|
// or set a specific seed with `seed: 4321`
|
||||||
},
|
},
|
||||||
clearContext: false // leave Jasmine Spec Runner output visible in browser
|
clearContext: false, // leave Jasmine Spec Runner output visible in browser
|
||||||
},
|
},
|
||||||
jasmineHtmlReporter: {
|
jasmineHtmlReporter: {
|
||||||
suppressAll: true // removes the duplicated traces
|
suppressAll: true, // removes the duplicated traces
|
||||||
},
|
},
|
||||||
coverageReporter: {
|
coverageReporter: {
|
||||||
dir: require('path').join(__dirname, './coverage/relay-angular-chat'),
|
dir: require("path").join(__dirname, "./coverage/relay-angular-chat"),
|
||||||
subdir: '.',
|
subdir: ".",
|
||||||
reporters: [
|
reporters: [{ type: "html" }, { type: "text-summary" }],
|
||||||
{ type: 'html' },
|
|
||||||
{ type: 'text-summary' }
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
reporters: ['progress', 'kjhtml'],
|
reporters: ["progress", "kjhtml"],
|
||||||
port: 9876,
|
port: 9876,
|
||||||
colors: true,
|
colors: true,
|
||||||
logLevel: config.LOG_INFO,
|
logLevel: config.LOG_INFO,
|
||||||
autoWatch: true,
|
autoWatch: true,
|
||||||
browsers: ['Chrome'],
|
browsers: ["Chrome"],
|
||||||
singleRun: false,
|
singleRun: false,
|
||||||
restartOnFileChange: true
|
restartOnFileChange: true,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
declare module 'protons';
|
declare module "protons";
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
declare module "time-cache" {
|
declare module "time-cache" {
|
||||||
|
|
||||||
interface ITimeCache {
|
interface ITimeCache {
|
||||||
put(key: string, value: any, validity: number): void;
|
put(key: string, value: any, validity: number): void;
|
||||||
get(key: string): any;
|
get(key: string): any;
|
||||||
has(key: string): boolean;
|
has(key: string): boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -11,5 +10,4 @@ declare module "time-cache" {
|
|||||||
function TimeCache(options: object): TimeCache;
|
function TimeCache(options: object): TimeCache;
|
||||||
|
|
||||||
export = TimeCache;
|
export = TimeCache;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,18 +1,15 @@
|
|||||||
import { TestBed } from '@angular/core/testing';
|
import { TestBed } from "@angular/core/testing";
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from "./app.component";
|
||||||
import { MessagesComponent } from './messages/messages.component';
|
import { MessagesComponent } from "./messages/messages.component";
|
||||||
|
|
||||||
describe('AppComponent', () => {
|
describe("AppComponent", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await TestBed.configureTestingModule({
|
await TestBed.configureTestingModule({
|
||||||
declarations: [
|
declarations: [AppComponent, MessagesComponent],
|
||||||
AppComponent,
|
|
||||||
MessagesComponent
|
|
||||||
],
|
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
});
|
});
|
||||||
|
|
||||||
xit('should create the app', () => {
|
xit("should create the app", () => {
|
||||||
const fixture = TestBed.createComponent(AppComponent);
|
const fixture = TestBed.createComponent(AppComponent);
|
||||||
const app = fixture.componentInstance;
|
const app = fixture.componentInstance;
|
||||||
expect(app).toBeTruthy();
|
expect(app).toBeTruthy();
|
||||||
@ -21,13 +18,15 @@ describe('AppComponent', () => {
|
|||||||
xit(`should have as title 'relay-angular-chat'`, () => {
|
xit(`should have as title 'relay-angular-chat'`, () => {
|
||||||
const fixture = TestBed.createComponent(AppComponent);
|
const fixture = TestBed.createComponent(AppComponent);
|
||||||
const app = fixture.componentInstance;
|
const app = fixture.componentInstance;
|
||||||
expect(app.title).toEqual('relay-angular-chat');
|
expect(app.title).toEqual("relay-angular-chat");
|
||||||
});
|
});
|
||||||
|
|
||||||
xit('should render title', () => {
|
xit("should render title", () => {
|
||||||
const fixture = TestBed.createComponent(AppComponent);
|
const fixture = TestBed.createComponent(AppComponent);
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
const compiled = fixture.nativeElement as HTMLElement;
|
const compiled = fixture.nativeElement as HTMLElement;
|
||||||
expect(compiled.querySelector('.h1')?.textContent).toContain('relay-angular-chat');
|
expect(compiled.querySelector(".h1")?.textContent).toContain(
|
||||||
|
"relay-angular-chat"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,22 +1,20 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component } from "@angular/core";
|
||||||
import { WakuService } from './waku.service';
|
import { WakuService } from "./waku.service";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: "app-root",
|
||||||
templateUrl: './app.component.html',
|
templateUrl: "./app.component.html",
|
||||||
styleUrls: ['./app.component.css']
|
styleUrls: ["./app.component.css"],
|
||||||
})
|
})
|
||||||
|
|
||||||
export class AppComponent {
|
export class AppComponent {
|
||||||
|
title: string = "relay-angular-chat";
|
||||||
title: string = 'relay-angular-chat';
|
|
||||||
wakuStatus!: string;
|
wakuStatus!: string;
|
||||||
|
|
||||||
constructor(private wakuService: WakuService) {}
|
constructor(private wakuService: WakuService) {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.wakuService.init();
|
this.wakuService.init();
|
||||||
this.wakuService.wakuStatus.subscribe(wakuStatus => {
|
this.wakuService.wakuStatus.subscribe((wakuStatus) => {
|
||||||
this.wakuStatus = wakuStatus;
|
this.wakuStatus = wakuStatus;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,17 +1,12 @@
|
|||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from "@angular/core";
|
||||||
import { BrowserModule } from '@angular/platform-browser';
|
import { BrowserModule } from "@angular/platform-browser";
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from "./app.component";
|
||||||
import { MessagesComponent } from './messages/messages.component';
|
import { MessagesComponent } from "./messages/messages.component";
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [AppComponent, MessagesComponent],
|
||||||
AppComponent,
|
imports: [BrowserModule],
|
||||||
MessagesComponent
|
|
||||||
],
|
|
||||||
imports: [
|
|
||||||
BrowserModule
|
|
||||||
],
|
|
||||||
providers: [],
|
providers: [],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent],
|
||||||
})
|
})
|
||||||
export class AppModule { }
|
export class AppModule {}
|
||||||
|
|||||||
@ -1,15 +1,14 @@
|
|||||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
import { ComponentFixture, TestBed } from "@angular/core/testing";
|
||||||
import { MessagesComponent } from './messages.component';
|
import { MessagesComponent } from "./messages.component";
|
||||||
|
|
||||||
describe('MessagesComponent', () => {
|
describe("MessagesComponent", () => {
|
||||||
let component: MessagesComponent;
|
let component: MessagesComponent;
|
||||||
let fixture: ComponentFixture<MessagesComponent>;
|
let fixture: ComponentFixture<MessagesComponent>;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await TestBed.configureTestingModule({
|
await TestBed.configureTestingModule({
|
||||||
declarations: [ MessagesComponent ]
|
declarations: [MessagesComponent],
|
||||||
})
|
}).compileComponents();
|
||||||
.compileComponents();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@ -18,7 +17,7 @@ describe('MessagesComponent', () => {
|
|||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
xit('should create', () => {
|
xit("should create", () => {
|
||||||
expect(component).toBeTruthy();
|
expect(component).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
import { TestBed } from '@angular/core/testing';
|
import { TestBed } from "@angular/core/testing";
|
||||||
|
|
||||||
import { WakuService } from './waku.service';
|
import { WakuService } from "./waku.service";
|
||||||
|
|
||||||
describe('WakuService', () => {
|
describe("WakuService", () => {
|
||||||
let service: WakuService;
|
let service: WakuService;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@ -10,7 +10,7 @@ describe('WakuService', () => {
|
|||||||
service = TestBed.inject(WakuService);
|
service = TestBed.inject(WakuService);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be created', () => {
|
it("should be created", () => {
|
||||||
expect(service).toBeTruthy();
|
expect(service).toBeTruthy();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
export const environment = {
|
export const environment = {
|
||||||
production: true
|
production: true,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
// The list of file replacements can be found in `angular.json`.
|
// The list of file replacements can be found in `angular.json`.
|
||||||
|
|
||||||
export const environment = {
|
export const environment = {
|
||||||
production: false
|
production: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -1,14 +1,18 @@
|
|||||||
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
||||||
|
|
||||||
import 'zone.js/testing';
|
import "zone.js/testing";
|
||||||
import { getTestBed } from '@angular/core/testing';
|
import { getTestBed } from "@angular/core/testing";
|
||||||
import {
|
import {
|
||||||
BrowserDynamicTestingModule,
|
BrowserDynamicTestingModule,
|
||||||
platformBrowserDynamicTesting
|
platformBrowserDynamicTesting,
|
||||||
} from '@angular/platform-browser-dynamic/testing';
|
} from "@angular/platform-browser-dynamic/testing";
|
||||||
|
|
||||||
declare const require: {
|
declare const require: {
|
||||||
context(path: string, deep?: boolean, filter?: RegExp): {
|
context(
|
||||||
|
path: string,
|
||||||
|
deep?: boolean,
|
||||||
|
filter?: RegExp
|
||||||
|
): {
|
||||||
<T>(id: string): T;
|
<T>(id: string): T;
|
||||||
keys(): string[];
|
keys(): string[];
|
||||||
};
|
};
|
||||||
@ -17,10 +21,10 @@ declare const require: {
|
|||||||
// First, initialize the Angular testing environment.
|
// First, initialize the Angular testing environment.
|
||||||
getTestBed().initTestEnvironment(
|
getTestBed().initTestEnvironment(
|
||||||
BrowserDynamicTestingModule,
|
BrowserDynamicTestingModule,
|
||||||
platformBrowserDynamicTesting(),
|
platformBrowserDynamicTesting()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Then we find all the tests.
|
// Then we find all the tests.
|
||||||
const context = require.context('./', true, /\.spec\.ts$/);
|
const context = require.context("./", true, /\.spec\.ts$/);
|
||||||
// And load the modules.
|
// And load the modules.
|
||||||
context.keys().map(context);
|
context.keys().map(context);
|
||||||
|
|||||||
@ -5,10 +5,6 @@
|
|||||||
"outDir": "./out-tsc/app",
|
"outDir": "./out-tsc/app",
|
||||||
"types": []
|
"types": []
|
||||||
},
|
},
|
||||||
"files": [
|
"files": ["src/main.ts"],
|
||||||
"src/main.ts",
|
"include": ["src/**/*.d.ts"]
|
||||||
],
|
|
||||||
"include": [
|
|
||||||
"src/**/*.d.ts"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,11 +18,8 @@
|
|||||||
"importHelpers": true,
|
"importHelpers": true,
|
||||||
"target": "es2020",
|
"target": "es2020",
|
||||||
"module": "es2020",
|
"module": "es2020",
|
||||||
"lib": [
|
"lib": ["es2020", "dom"],
|
||||||
"es2020",
|
"allowSyntheticDefaultImports": true
|
||||||
"dom"
|
|
||||||
],
|
|
||||||
"allowSyntheticDefaultImports": true,
|
|
||||||
},
|
},
|
||||||
"angularCompilerOptions": {
|
"angularCompilerOptions": {
|
||||||
"enableI18nLegacyMessageIdFormat": false,
|
"enableI18nLegacyMessageIdFormat": false,
|
||||||
|
|||||||
@ -3,15 +3,8 @@
|
|||||||
"extends": "./tsconfig.json",
|
"extends": "./tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"outDir": "./out-tsc/spec",
|
"outDir": "./out-tsc/spec",
|
||||||
"types": [
|
"types": ["jasmine"]
|
||||||
"jasmine"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"files": [
|
"files": ["src/test.ts"],
|
||||||
"src/test.ts",
|
"include": ["src/**/*.spec.ts", "src/**/*.d.ts"]
|
||||||
],
|
|
||||||
"include": [
|
|
||||||
"src/**/*.spec.ts",
|
|
||||||
"src/**/*.d.ts"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,26 +1,28 @@
|
|||||||
const {getLoaders, loaderByName} = require("@craco/craco");
|
const { getLoaders, loaderByName } = require("@craco/craco");
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
webpack: {
|
webpack: {
|
||||||
configure: (webpackConfig) => {
|
configure: (webpackConfig) => {
|
||||||
const {hasFoundAny, matches} = getLoaders(webpackConfig, loaderByName("babel-loader"));
|
const { hasFoundAny, matches } = getLoaders(
|
||||||
|
webpackConfig,
|
||||||
|
loaderByName("babel-loader")
|
||||||
|
);
|
||||||
|
|
||||||
if (hasFoundAny) {
|
if (hasFoundAny) {
|
||||||
matches.forEach(c => {
|
matches.forEach((c) => {
|
||||||
// Modify test to include cjs for @chainsafe/libp2p-gossipsub rpc module
|
// Modify test to include cjs for @chainsafe/libp2p-gossipsub rpc module
|
||||||
if (c.loader.test.toString().includes("mjs")) {
|
if (c.loader.test.toString().includes("mjs")) {
|
||||||
// If your project uses typescript then do not forget to include `ts`/`tsx`
|
// If your project uses typescript then do not forget to include `ts`/`tsx`
|
||||||
if (c.loader.test.toString().includes('jsx')) {
|
if (c.loader.test.toString().includes("jsx")) {
|
||||||
c.loader.test = /\.(js|cjs|mjs|jsx)$/
|
c.loader.test = /\.(js|cjs|mjs|jsx)$/;
|
||||||
} else {
|
} else {
|
||||||
c.loader.test = /\.(js|cjs|mjs)$/
|
c.loader.test = /\.(js|cjs|mjs)$/;
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return webpackConfig;
|
return webpackConfig;
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { render, screen } from '@testing-library/react';
|
import { render, screen } from "@testing-library/react";
|
||||||
import App from './App';
|
import App from "./App";
|
||||||
|
|
||||||
test('renders learn react link', () => {
|
test("renders learn react link", () => {
|
||||||
render(<App />);
|
render(<App />);
|
||||||
const linkElement = screen.getByText(/learn react/i);
|
const linkElement = screen.getByText(/learn react/i);
|
||||||
expect(linkElement).toBeInTheDocument();
|
expect(linkElement).toBeInTheDocument();
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
import React from 'react';
|
import React from "react";
|
||||||
import ReactDOM from 'react-dom/client';
|
import ReactDOM from "react-dom/client";
|
||||||
import './index.css';
|
import "./index.css";
|
||||||
import App from './App';
|
import App from "./App";
|
||||||
|
|
||||||
const root = ReactDOM.createRoot(document.getElementById('root'));
|
const root = ReactDOM.createRoot(document.getElementById("root"));
|
||||||
root.render(
|
root.render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
<App />
|
<App />
|
||||||
|
|||||||
@ -2,4 +2,4 @@
|
|||||||
// allows you to do things like:
|
// allows you to do things like:
|
||||||
// expect(element).toHaveTextContent(/react/i)
|
// expect(element).toHaveTextContent(/react/i)
|
||||||
// learn more: https://github.com/testing-library/jest-dom
|
// learn more: https://github.com/testing-library/jest-dom
|
||||||
import '@testing-library/jest-dom';
|
import "@testing-library/jest-dom";
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import protobuf from "protobufjs";
|
import protobuf from "protobufjs";
|
||||||
import {createLightNode} from "@waku/create";
|
import { createLightNode } from "@waku/create";
|
||||||
import {waitForRemotePeer} from "@waku/core/lib/wait_for_remote_peer";
|
import { waitForRemotePeer } from "@waku/core/lib/wait_for_remote_peer";
|
||||||
import {DecoderV0} from "@waku/core/lib/waku_message/version_0";
|
import { DecoderV0 } from "@waku/core/lib/waku_message/version_0";
|
||||||
import {bytesToUtf8} from "@waku/byte-utils"
|
import { bytesToUtf8 } from "@waku/byte-utils";
|
||||||
|
|
||||||
const ContentTopic = "/toy-chat/2/huilong/proto";
|
const ContentTopic = "/toy-chat/2/huilong/proto";
|
||||||
const Decoder = new DecoderV0(ContentTopic);
|
const Decoder = new DecoderV0(ContentTopic);
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { render, screen } from '@testing-library/react';
|
import { render, screen } from "@testing-library/react";
|
||||||
import App from './App';
|
import App from "./App";
|
||||||
|
|
||||||
test('renders learn react link', () => {
|
test("renders learn react link", () => {
|
||||||
render(<App />);
|
render(<App />);
|
||||||
const linkElement = screen.getByText(/learn react/i);
|
const linkElement = screen.getByText(/learn react/i);
|
||||||
expect(linkElement).toBeInTheDocument();
|
expect(linkElement).toBeInTheDocument();
|
||||||
|
|||||||
@ -2,4 +2,4 @@
|
|||||||
// allows you to do things like:
|
// allows you to do things like:
|
||||||
// expect(element).toHaveTextContent(/react/i)
|
// expect(element).toHaveTextContent(/react/i)
|
||||||
// learn more: https://github.com/testing-library/jest-dom
|
// learn more: https://github.com/testing-library/jest-dom
|
||||||
import '@testing-library/jest-dom';
|
import "@testing-library/jest-dom";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user