tests
This commit is contained in:
parent
126a55f3c4
commit
c36544f9a3
@ -5,7 +5,8 @@
|
|||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "yarn workspace @snort/nostr build && yarn workspace @snort/app build",
|
"build": "yarn workspace @snort/nostr build && yarn workspace @snort/app build",
|
||||||
"start": "yarn workspace @snort/nostr build && yarn workspace @snort/app start"
|
"start": "yarn workspace @snort/nostr build && yarn workspace @snort/app start",
|
||||||
|
"test": "yarn workspace @snort/app test"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tauri-apps/cli": "^1.2.3",
|
"@tauri-apps/cli": "^1.2.3",
|
||||||
|
7
packages/app/jest.config.js
Normal file
7
packages/app/jest.config.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
||||||
|
module.exports = {
|
||||||
|
bail: true,
|
||||||
|
preset: "ts-jest",
|
||||||
|
testEnvironment: "jsdom",
|
||||||
|
roots: ["./src/"],
|
||||||
|
};
|
@ -48,7 +48,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "webpack serve",
|
"start": "webpack serve",
|
||||||
"build": "webpack --node-env=production",
|
"build": "webpack --node-env=production",
|
||||||
"test": "",
|
"test": "jest",
|
||||||
"intl-extract": "formatjs extract 'src/**/*.ts*' --ignore='**/*.d.ts' --out-file src/lang.json --flatten true",
|
"intl-extract": "formatjs extract 'src/**/*.ts*' --ignore='**/*.d.ts' --out-file src/lang.json --flatten true",
|
||||||
"intl-compile": "formatjs compile src/lang.json --out-file src/translations/en.json",
|
"intl-compile": "formatjs compile src/lang.json --out-file src/translations/en.json",
|
||||||
"format": "prettier --write .",
|
"format": "prettier --write .",
|
||||||
@ -80,7 +80,7 @@
|
|||||||
"@babel/preset-react": "^7.18.6",
|
"@babel/preset-react": "^7.18.6",
|
||||||
"@formatjs/cli": "^6.0.1",
|
"@formatjs/cli": "^6.0.1",
|
||||||
"@formatjs/ts-transformer": "^3.13.1",
|
"@formatjs/ts-transformer": "^3.13.1",
|
||||||
"@types/jest": "^29.2.5",
|
"@types/jest": "^29.5.1",
|
||||||
"@types/node": "^18.11.18",
|
"@types/node": "^18.11.18",
|
||||||
"@types/react": "^18.0.26",
|
"@types/react": "^18.0.26",
|
||||||
"@types/react-dom": "^18.0.10",
|
"@types/react-dom": "^18.0.10",
|
||||||
@ -99,9 +99,12 @@
|
|||||||
"eslint-webpack-plugin": "^4.0.1",
|
"eslint-webpack-plugin": "^4.0.1",
|
||||||
"html-webpack-plugin": "^5.5.1",
|
"html-webpack-plugin": "^5.5.1",
|
||||||
"husky": ">=6",
|
"husky": ">=6",
|
||||||
|
"jest": "^29.5.0",
|
||||||
|
"jest-environment-jsdom": "^29.5.0",
|
||||||
"lint-staged": ">=10",
|
"lint-staged": ">=10",
|
||||||
"mini-css-extract-plugin": "^2.7.5",
|
"mini-css-extract-plugin": "^2.7.5",
|
||||||
"prettier": "2.8.3",
|
"prettier": "2.8.3",
|
||||||
|
"ts-jest": "^29.1.0",
|
||||||
"ts-loader": "^9.4.2",
|
"ts-loader": "^9.4.2",
|
||||||
"typescript": "^5.0.4",
|
"typescript": "^5.0.4",
|
||||||
"webpack": "^5.82.1",
|
"webpack": "^5.82.1",
|
||||||
|
@ -33,7 +33,7 @@ export const DefaultConnectTimeout = 2000;
|
|||||||
/**
|
/**
|
||||||
* How long profile cache should be considered valid for
|
* How long profile cache should be considered valid for
|
||||||
*/
|
*/
|
||||||
export const ProfileCacheExpire = 1_000 * 60 * 30;
|
export const ProfileCacheExpire = 1_000 * 60 * 60 * 6;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default bootstrap relays
|
* Default bootstrap relays
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { TaggedRawEvent } from "@snort/nostr";
|
import { TaggedRawEvent } from "@snort/nostr";
|
||||||
|
import { describe, expect } from "@jest/globals";
|
||||||
import { FlatNoteStore, ReplaceableNoteStore } from "./NoteCollection";
|
import { FlatNoteStore, ReplaceableNoteStore } from "./NoteCollection";
|
||||||
|
|
||||||
describe("NoteStore", () => {
|
describe("NoteStore", () => {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { Connection } from "@snort/nostr";
|
import { Connection } from "@snort/nostr";
|
||||||
|
import { describe, expect } from "@jest/globals";
|
||||||
import { Query } from "./Query";
|
import { Query } from "./Query";
|
||||||
import { getRandomValues } from "crypto";
|
import { getRandomValues } from "crypto";
|
||||||
import { FlatNoteStore } from "./NoteCollection";
|
import { FlatNoteStore } from "./NoteCollection";
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { RequestBuilder } from "./RequestBuilder";
|
import { RequestBuilder } from "./RequestBuilder";
|
||||||
|
import { describe, expect } from "@jest/globals";
|
||||||
|
|
||||||
describe("RequestBuilder", () => {
|
describe("RequestBuilder", () => {
|
||||||
describe("basic", () => {
|
describe("basic", () => {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { RawReqFilter } from "@snort/nostr";
|
import { RawReqFilter } from "@snort/nostr";
|
||||||
|
import { describe, expect } from "@jest/globals";
|
||||||
import { diffFilters } from "./RequestSplitter";
|
import { diffFilters } from "./RequestSplitter";
|
||||||
|
|
||||||
describe("RequestSplitter", () => {
|
describe("RequestSplitter", () => {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { splitByUrl, magnetURIDecode, getRelayName, validateNostrLink } from "./Util";
|
import { splitByUrl, magnetURIDecode, getRelayName, validateNostrLink } from "./Util";
|
||||||
|
import { describe, expect } from "@jest/globals";
|
||||||
|
|
||||||
describe("splitByUrl", () => {
|
describe("splitByUrl", () => {
|
||||||
it("should split a string by URLs", () => {
|
it("should split a string by URLs", () => {
|
||||||
@ -12,8 +13,8 @@ describe("splitByUrl", () => {
|
|||||||
" but I made a ",
|
" but I made a ",
|
||||||
"https://example.com",
|
"https://example.com",
|
||||||
"! simple example (",
|
"! simple example (",
|
||||||
"https://example.com",
|
"https://example.com)",
|
||||||
") of how ",
|
" of how ",
|
||||||
"https://example.com/yo-yo",
|
"https://example.com/yo-yo",
|
||||||
" ",
|
" ",
|
||||||
"https://example.example.com",
|
"https://example.example.com",
|
||||||
@ -92,22 +93,18 @@ describe("getRelayName", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("validateNostrLink", () => {
|
describe("validateNostrLink", () => {
|
||||||
it("should return true for valid nostr links", () => {
|
test.each([
|
||||||
[
|
"nostr:npub10elfcs4fr0l0r8af98jlmgdh9c8tcxjvz9qkw038js35mp4dma8qzvjptg",
|
||||||
"nostr:npub10elfcs4fr0l0r8af98jlmgdh9c8tcxjvz9qkw038js35mp4dma8qzvjptg",
|
"web+nostr:npub10elfcs4fr0l0r8af98jlmgdh9c8tcxjvz9qkw038js35mp4dma8qzvjptg",
|
||||||
"web+nostr:npub10elfcs4fr0l0r8af98jlmgdh9c8tcxjvz9qkw038js35mp4dma8qzvjptg",
|
"nostr:note15449edq4qa5wzgqvh8td0q0dp6hwtes4pknsrm7eygeenhlj99xsq94wu9",
|
||||||
"nostr:note15449edq4qa5wzgqvh8td0q0dp6hwtes4pknsrm7eygeenhlj99xsq94wu9",
|
"nostr:nprofile1qqsrhuxx8l9ex335q7he0f09aej04zpazpl0ne2cgukyawd24mayt8gpp4mhxue69uhhytnc9e3k7mgpz4mhxue69uhkg6nzv9ejuumpv34kytnrdaksjlyr9p",
|
||||||
"nostr:nprofile1qqsrhuxx8l9ex335q7he0f09aej04zpazpl0ne2cgukyawd24mayt8gpp4mhxue69uhhytnc9e3k7mgpz4mhxue69uhkg6nzv9ejuumpv34kytnrdaksjlyr9p",
|
"nostr:nevent1qqs226juks2sw68pyqxtn4khs8ksath9uc2smfcpalvjyvuemlezjngrd87dq",
|
||||||
"nostr:nevent1qqs226juks2sw68pyqxtn4khs8ksath9uc2smfcpalvjyvuemlezjngrd87dq",
|
"nostr:naddr1qqzkjurnw4ksz9thwden5te0wfjkccte9ehx7um5wghx7un8qgs2d90kkcq3nk2jry62dyf50k0h36rhpdtd594my40w9pkal876jxgrqsqqqa28pccpzu",
|
||||||
"nostr:naddr1qqzkjurnw4ksz9thwden5te0wfjkccte9ehx7um5wghx7un8qgs2d90kkcq3nk2jry62dyf50k0h36rhpdtd594my40w9pkal876jxgrqsqqqa28pccpzu",
|
])("should return true for valid nostr links", la => {
|
||||||
].forEach(link => {
|
expect(validateNostrLink(la)).toBe(true);
|
||||||
expect(validateNostrLink(link)).toBe(true);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return false for invalid nostr links", () => {
|
test.each(["nostr:npub", "web+nostr:npub", "nostr:nevent1xxx"])("should return false for invalid nostr links", lb => {
|
||||||
["nostr:npub", "web+nostr:npub", "nostr:nevent1xxx"].forEach(link => {
|
expect(validateNostrLink(lb)).toBe(false);
|
||||||
expect(validateNostrLink(link)).toBe(false);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -65,7 +65,7 @@ export function bech32ToHex(str: string) {
|
|||||||
const nKey = bech32.decode(str, 1_000);
|
const nKey = bech32.decode(str, 1_000);
|
||||||
const buff = bech32.fromWords(nKey.words);
|
const buff = bech32.fromWords(nKey.words);
|
||||||
return utils.bytesToHex(Uint8Array.from(buff));
|
return utils.bytesToHex(Uint8Array.from(buff));
|
||||||
} catch {
|
} catch (e) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -517,11 +517,9 @@ export interface NostrLink {
|
|||||||
export function validateNostrLink(link: string): boolean {
|
export function validateNostrLink(link: string): boolean {
|
||||||
try {
|
try {
|
||||||
const parsedLink = parseNostrLink(link);
|
const parsedLink = parseNostrLink(link);
|
||||||
|
|
||||||
if (!parsedLink) {
|
if (!parsedLink) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parsedLink.type === NostrPrefix.PublicKey || parsedLink.type === NostrPrefix.Note) {
|
if (parsedLink.type === NostrPrefix.PublicKey || parsedLink.type === NostrPrefix.Note) {
|
||||||
return parsedLink.id.length === 64;
|
return parsedLink.id.length === 64;
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ const config = {
|
|||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
{
|
{
|
||||||
test: /\.(ts|tsx)$/i,
|
test: /\.tsx?$/i,
|
||||||
use: [
|
use: [
|
||||||
"babel-loader",
|
"babel-loader",
|
||||||
{
|
{
|
||||||
|
@ -30,7 +30,7 @@ export interface Setup {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function setup(
|
export async function setup(
|
||||||
done: jest.DoneCallback,
|
done: (e?: unknown) => void,
|
||||||
test: (setup: Setup) => void | Promise<void>
|
test: (setup: Setup) => void | Promise<void>
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user