feat: modularisation (#244)

* chore: gitignore for lib directory

* build: packageing for webpack lib build

* build: webpack config

* feat: expose App component with beeApiUrl parameter

* build: tsconfig for library build

* build: main property of package json for tsc build

* refactor: rename beeUrl option to beeApiUrl

* refactor: manange config class instead of process.env calls

* build: babelrc config

* build: babel plugins and presets for webpack build

* chore: serve.js chmod

* build(refactor): webpack build

* refactor: number notation

* chore: webpack and package config change

* build: add babel preset-env

* chore: prepare script also builds component lib

* feat: typegen

* revert: set back prepare command

* build: assets loader config

* feat: beeDebugApiUrl

* refactor: move test files to the test folder because of typegen

* feat: locked api settings

* chore: depcheck ignores

* chore: types check script

* ci: check types

* ci: publish with library

* chore: add webpack as devDep

* chore: locked semver

* chore: remove debug logging

* style: webpack config

* chore: react and react-dom as dependency

* chore: package-lock

* fix: clean package-lock init

* refactor: fix versions in package.json
This commit is contained in:
nugaon
2021-12-09 11:12:45 +01:00
committed by GitHub
parent 1a3e58c89b
commit 2a13da1a6c
23 changed files with 7145 additions and 2049 deletions
+57
View File
@@ -0,0 +1,57 @@
import { detectIndexHtml } from './file'
describe('file utils', () => {
it('detectIndexHtml should find index.html', () => {
expect(
detectIndexHtml([
{ name: 'swarm.png', path: 'swarm.png' },
{ name: 'index.html', path: 'index.html' },
]),
).toBe('index.html')
})
it('detectIndexHtml should find index.htm', () => {
expect(
detectIndexHtml([
{ name: 'index.htm', path: 'index.htm' },
{ name: 'swarm.png', path: 'swarm.png' },
]),
).toBe('index.htm')
})
it('detectIndexHtml should find nested index.html', () => {
expect(
detectIndexHtml([
{ name: 'swarm.png', path: 'sample-folder/swarm.png' },
{ name: 'index.html', path: 'sample-folder/index.html' },
]),
).toBe('index.html')
})
it('detectIndexHtml should not find nested index.htm when ambigous', () => {
expect(
detectIndexHtml([
{ name: 'index.htm', path: 'sample-folder/index.htm' },
{ name: 'swarm.png', path: 'other-folder/swarm.png' },
]),
).toBe(false)
})
it('detectIndexHtml should not find deep index.html', () => {
expect(
detectIndexHtml([
{ name: 'index.html', path: 'sample-folder/index.html' },
{ name: 'swarm.png', path: 'swarm.png' },
]),
).toBe(false)
})
it('detectIndexHtml should return false when no matches appear', () => {
expect(
detectIndexHtml([
{ name: 'swarm.png', path: 'swarm.png' },
{ name: 'swarm.jpg', path: 'swarm.jpg' },
]),
).toBe(false)
})
})
+106
View File
@@ -0,0 +1,106 @@
import BigNumber from 'bignumber.js'
import { extractSwarmHash, isInteger, makeBigNumber } from './index'
describe('utils', () => {
describe('isInteger', () => {
const correctValues = [
BigInt(0),
BigInt(1),
BigInt(-1),
new BigNumber('1'),
new BigNumber('0'),
new BigNumber('-1'),
]
const wrongValues = ['1', new BigNumber('-0.1'), new BigNumber(NaN), new BigNumber(Infinity)]
correctValues.forEach(v => {
test(`testing ${v}`, () => {
expect(isInteger(v)).toBe(true)
})
})
wrongValues.forEach(v => {
test(`testing ${v}`, () => {
expect(isInteger(v)).toBe(false)
})
})
})
describe('makeBigNumber', () => {
const correctValues = [
BigInt(0),
BigInt(1),
BigInt(-1),
'1',
'0',
'-1',
'0.1',
new BigNumber('1'),
new BigNumber('0'),
new BigNumber('-1'),
0,
1,
-1,
]
const wrongValues = [new Function()] // eslint-disable-line no-new-func
correctValues.forEach(v => {
test(`testing ${v}`, () => {
expect(BigNumber.isBigNumber(makeBigNumber(v))).toBe(true)
})
})
wrongValues.forEach(v => {
test(`testing ${v}`, () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect(() => makeBigNumber(v as unknown as any)).toThrow()
})
})
})
describe('extractSwarmHash', () => {
test('should return 64 hash', () => {
expect(extractSwarmHash('7f0fe712cdd78bdea52d040369eb32b6af5ecd01fa5ae49b7506412abdd81ac3')).toBe(
'7f0fe712cdd78bdea52d040369eb32b6af5ecd01fa5ae49b7506412abdd81ac3',
)
})
test('should return 128 hash', () => {
expect(
extractSwarmHash(
'd1829242c4d08e9f914fedfb1f68aacd62826d75370a9a57a80c9e6e6a49983c767c013be9aa4319e34fd8323ef0f2a57426b30e66c87e219f6f6359e2595e7f',
),
).toBe(
'd1829242c4d08e9f914fedfb1f68aacd62826d75370a9a57a80c9e6e6a49983c767c013be9aa4319e34fd8323ef0f2a57426b30e66c87e219f6f6359e2595e7f',
)
})
test('should return 64 hash from url', () => {
expect(
extractSwarmHash('http://localhost:1633/bzz/7f0fe712cdd78bdea52d040369eb32b6af5ecd01fa5ae49b7506412abdd81ac3/'),
).toBe('7f0fe712cdd78bdea52d040369eb32b6af5ecd01fa5ae49b7506412abdd81ac3')
})
test('should return 128 hash from url', () => {
expect(
extractSwarmHash(
'http://localhost:1633/bzz/d1829242c4d08e9f914fedfb1f68aacd62826d75370a9a57a80c9e6e6a49983c767c013be9aa4319e34fd8323ef0f2a57426b30e66c87e219f6f6359e2595e7f/',
),
).toBe(
'd1829242c4d08e9f914fedfb1f68aacd62826d75370a9a57a80c9e6e6a49983c767c013be9aa4319e34fd8323ef0f2a57426b30e66c87e219f6f6359e2595e7f',
)
})
test('should return null when nothing is found', () => {
expect(extractSwarmHash('Bee Dashboard')).toBe(null)
})
test('should return null when length is incorrect', () => {
expect(extractSwarmHash('7f0fe712cdd78bdea52d040369eb32b6af5ecd01fa5ae49b7506412abdd81a')).toBe(null)
})
test('should return null when alphanumeric', () => {
expect(extractSwarmHash('gkQ6duo5iHJ099g908P0t17ZWFf8Ke2klrywLP5BGtLkcaEC5W0kLEfbe4wUnDI6')).toBe(null)
})
})
})