diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..5673b46 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,2 @@ +README.md +RELEASE.md \ No newline at end of file diff --git a/RELEASE.md b/RELEASE.md index ea728ea..c91f4a1 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,8 +1,13 @@ # Releases +## unrelased + +- FEATURE: Server-side fund() now live. +- Errors now more readable. + ## 0.1.0 -- FEAT: Custom syntax with `` tags. +- FEATURE: Custom syntax with `` tags. ## 0.0.5 diff --git a/jest.config.js b/jest.config.js index 4317c53..3ddbc13 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,5 +1,5 @@ module.exports = { - roots: ['/src'], + roots: ['/tests'], transform: { '^.+\\.tsx?$': 'ts-jest', }, diff --git a/src/fund/errors.ts b/src/fund/errors.ts index f7bbe84..41716f9 100644 --- a/src/fund/errors.ts +++ b/src/fund/errors.ts @@ -1,29 +1,39 @@ import { DEFAULT_WEIGHT } from './set-pointer-multiple' -export const defaultAddressNotFound = - 'Fundme.js: default address not found. Use setDefaultAddress(str: string) to set it first.' -export const invalidAddress = 'Fundme.js: Invalid Web Monetization pointer address is given.' -export const addressNotFound = 'Fundme.js: address not found.' -export const addressIsNotAString = 'Fundme.js: address must be a string.' -export const weightNotFound = 'Fundme.js: entries .weight not found.' +export function FundmeError(err: string): string { + return 'Fundme.js: ' + err +} + +export const defaultAddressNotFound = 'default address not found. Use setDefaultAddress(str: string) to set it first.' +export const invalidAddress = 'Invalid Web Monetization pointer address is given.' +export const addressNotFound = 'address not found.' +export const addressIsNotAString = 'address must be a string.' +export const getCurrentPointerAddressMustClientSide = "can't use getCurrentPointerAddress() server-side." +export const weightNotFound = 'entries .weight not found.' export function weightIsNotANumber(str: string) { - return `Fundme.js: ${str} has weight that is not a number. It has been set to ${DEFAULT_WEIGHT} (default).` + return `${str} has weight that is not a number. It has been set to ${DEFAULT_WEIGHT} (default).` } // about meta tag for Web Monetization API -export const metaTagNotFound = 'Fundme.js: web monetization meta tag is not found.' +export const metaTagNotFound = 'web monetization meta tag is not found.' export const metaTagMultipleIsFound = - 'Fundme.js: multiple found - Web Monetization API only support a single meta tag.' + 'multiple found - Web Monetization API only support a single meta tag.' // pointers template -export const noTemplateFound = 'Fundme.js: no monetization template is found.' -export const failParsingTemplate = 'Fundme.js: fails to parse address from .' +export const noTemplateFound = 'no monetization template is found.' +export const failParsingTemplate = 'fails to parse address from .' export const templateSinglePointerHasWeight = - 'Fundme.js: found single but has weight - only address will be parsed.' + 'found single but has weight - only address will be parsed.' // script json template -export const cannotParseScriptJson = - 'Fundme.js: cannot parse JSON from ` + forceFundmeOnBrowser() fund() expect(getCurrentPointerPool()).toEqual(pointers) document.body.innerHTML = '' diff --git a/src/fund/tests/string-syntax-unique.spec.ts b/tests/fund/client-side/string-syntax-unique.spec.ts similarity index 70% rename from src/fund/tests/string-syntax-unique.spec.ts rename to tests/fund/client-side/string-syntax-unique.spec.ts index 450fa1a..7107aba 100644 --- a/src/fund/tests/string-syntax-unique.spec.ts +++ b/tests/fund/client-side/string-syntax-unique.spec.ts @@ -1,8 +1,9 @@ -import { fund, getCurrentPointerPool } from '../main' -import { convertToPointer } from '../set-pointer-multiple' +import { fund, getCurrentPointerPool, forceFundmeOnBrowser } from '../../../src/fund/main' +import { convertToPointer } from '../../../src/fund/set-pointer-multiple' describe('Unique syntax on string', () => { test('will result correct weights', () => { + forceFundmeOnBrowser() fund(['$wallet.example.com/testing-1#33', '$wallet.example.com/testing-2#22']) const expectedPool = [ diff --git a/src/fund/tests/template-scrape-custom-syntax.spec.ts b/tests/fund/client-side/template-scrape-custom-syntax.spec.ts similarity index 87% rename from src/fund/tests/template-scrape-custom-syntax.spec.ts rename to tests/fund/client-side/template-scrape-custom-syntax.spec.ts index 7d9e257..8b6be5b 100644 --- a/src/fund/tests/template-scrape-custom-syntax.spec.ts +++ b/tests/fund/client-side/template-scrape-custom-syntax.spec.ts @@ -1,12 +1,13 @@ -import { fund, getCurrentPointerPool } from '../main' +import { fund, getCurrentPointerPool, forceFundmeOnBrowser } from '../../../src/fund/main' import { toBeInTheDocument, toHaveAttribute } from '@testing-library/jest-dom/matchers' -import { scriptFundmeIsNotApplicationJson } from '../errors' +import { scriptFundmeIsNotApplicationJson } from '../../../src/fund/errors' expect.extend({ toBeInTheDocument, toHaveAttribute }) describe('parsing custom syntax', () => { test('works with hash # weight modifier', () => { + forceFundmeOnBrowser() document.body.innerHTML = ` ` + forceFundmeOnBrowser() fund() const expectedPool = [ { diff --git a/src/fund/tests/template-scrape-from-script-json.spec.ts b/tests/fund/client-side/template-scrape-from-script-json.spec.ts similarity index 75% rename from src/fund/tests/template-scrape-from-script-json.spec.ts rename to tests/fund/client-side/template-scrape-from-script-json.spec.ts index 5f15b9e..9ad1db4 100644 --- a/src/fund/tests/template-scrape-from-script-json.spec.ts +++ b/tests/fund/client-side/template-scrape-from-script-json.spec.ts @@ -1,23 +1,24 @@ -import { fund, getCurrentPointerPool } from '../main' +import { fund, getCurrentPointerPool, forceFundmeOnBrowser } from '../../../src/fund/main' import { toBeInTheDocument, toHaveAttribute } from '@testing-library/jest-dom/matchers' -import { scriptFundmeIsNotApplicationJson } from '../errors' +import { scriptFundmeIsNotApplicationJson } from '../../../src/fund/errors' expect.extend({ toBeInTheDocument, toHaveAttribute }) describe('parsing fundme template from a JSON array', () => { test('fund() will scrape from + ` + forceFundmeOnBrowser() fund() const pool = getCurrentPointerPool() // @ts-ignore @@ -30,6 +31,7 @@ describe('parsing fundme template from a JSON array', () => { "$coil.xrptipbot.com/my-pointer" ` + forceFundmeOnBrowser() fund() const pool = getCurrentPointerPool() // @ts-ignore @@ -50,6 +52,7 @@ describe('parsing fundme template from a JSON array', () => { ] ` + forceFundmeOnBrowser() // @ts-ignore expect(() => fund()).toThrowError(scriptFundmeIsNotApplicationJson) document.body.innerHTML = '' diff --git a/src/fund/tests/template-scrape-weight.spec.ts b/tests/fund/client-side/template-scrape-weight.spec.ts similarity index 85% rename from src/fund/tests/template-scrape-weight.spec.ts rename to tests/fund/client-side/template-scrape-weight.spec.ts index 9bb7d67..8dd3e20 100644 --- a/src/fund/tests/template-scrape-weight.spec.ts +++ b/tests/fund/client-side/template-scrape-weight.spec.ts @@ -1,4 +1,4 @@ -import { fund, getCurrentPointerPool } from '../main' +import { fund, getCurrentPointerPool, forceFundmeOnBrowser } from '../../../src/fund/main' import { toBeInTheDocument, toHaveAttribute } from '@testing-library/jest-dom/matchers' @@ -6,6 +6,7 @@ expect.extend({ toBeInTheDocument, toHaveAttribute }) describe('get weight from