Remove mutex that was needed by jest
This commit is contained in:
parent
c89f3645d8
commit
8a5235461d
1 changed files with 132 additions and 215 deletions
|
|
@ -16,10 +16,6 @@ if (!fs.existsSync('./test-radata')) {
|
|||
fs.mkdirSync('./test-radata')
|
||||
}
|
||||
|
||||
// start with true, have first test doesn't check, else all other test start to
|
||||
// run right away
|
||||
let isBusy = true
|
||||
|
||||
const instance = Gun({
|
||||
axe: false,
|
||||
multicast: false,
|
||||
|
|
@ -30,25 +26,6 @@ const user = instance.user()
|
|||
const alias = words()
|
||||
const pass = words()
|
||||
|
||||
const release = () => {
|
||||
isBusy = false
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
const whenReady = () =>
|
||||
new Promise(res => {
|
||||
setTimeout(() => {
|
||||
if (isBusy) {
|
||||
whenReady().then(res)
|
||||
} else {
|
||||
isBusy = true
|
||||
res()
|
||||
}
|
||||
}, 1000)
|
||||
})
|
||||
|
||||
/**
|
||||
* @param {number} ms
|
||||
*/
|
||||
|
|
@ -60,7 +37,6 @@ describe('gun smith', () => {
|
|||
})
|
||||
|
||||
it('puts a true and reads it with once()', done => {
|
||||
// await whenReady()
|
||||
logger.info('puts a true and reads it with once()')
|
||||
const a = words()
|
||||
const b = words()
|
||||
|
|
@ -76,7 +52,6 @@ describe('gun smith', () => {
|
|||
.once(val => {
|
||||
expect(val).toBe(true)
|
||||
done()
|
||||
release()
|
||||
})
|
||||
})
|
||||
|
||||
|
|
@ -84,7 +59,6 @@ describe('gun smith', () => {
|
|||
const a = words()
|
||||
const b = words()
|
||||
|
||||
whenReady().then(() => {
|
||||
instance
|
||||
.get(a)
|
||||
.get(b)
|
||||
|
|
@ -98,18 +72,15 @@ describe('gun smith', () => {
|
|||
.once(val => {
|
||||
expect(val).toBe(false)
|
||||
done()
|
||||
release()
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('puts numbers and reads them with once()', done => {
|
||||
const a = words()
|
||||
const b = words()
|
||||
|
||||
whenReady().then(() => {
|
||||
instance
|
||||
.get(a)
|
||||
.get(b)
|
||||
|
|
@ -121,8 +92,6 @@ describe('gun smith', () => {
|
|||
.once(val => {
|
||||
expect(val).toBe(5)
|
||||
done()
|
||||
release()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
|
@ -130,7 +99,6 @@ describe('gun smith', () => {
|
|||
const a = words()
|
||||
const b = words()
|
||||
const sentence = words({ exactly: 50 }).join(' ')
|
||||
whenReady().then(() => {
|
||||
instance
|
||||
.get(a)
|
||||
.get(b)
|
||||
|
|
@ -142,13 +110,10 @@ describe('gun smith', () => {
|
|||
.once(val => {
|
||||
expect(val).toBe(sentence)
|
||||
done()
|
||||
release()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('merges puts', async () => {
|
||||
await whenReady()
|
||||
const a = {
|
||||
a: 1
|
||||
}
|
||||
|
|
@ -168,12 +133,9 @@ describe('gun smith', () => {
|
|||
throw new Error('Data not an object')
|
||||
}
|
||||
expect(removeBuiltInGunProps(data)).toEqual(c)
|
||||
|
||||
release()
|
||||
})
|
||||
|
||||
it('writes primitive items into sets and correctly assigns the id to ._.get', done => {
|
||||
whenReady().then(() => {
|
||||
const node = instance.get(words()).get(words())
|
||||
const item = node.set('hello')
|
||||
|
||||
|
|
@ -182,15 +144,12 @@ describe('gun smith', () => {
|
|||
[item._.get]: 'hello'
|
||||
})
|
||||
done()
|
||||
release()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
// TODO: find out why this test fucks up the previous one if it runs before
|
||||
// that one
|
||||
it('maps over a primitive set', done => {
|
||||
whenReady().then(() => {
|
||||
const node = instance.get(words()).get(words())
|
||||
|
||||
const items = words({ exactly: 50 })
|
||||
|
|
@ -205,14 +164,11 @@ describe('gun smith', () => {
|
|||
checked++
|
||||
if (checked === 50) {
|
||||
done()
|
||||
release()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('maps over an object set', done => {
|
||||
whenReady().then(() => {
|
||||
const node = instance.get(words()).get(words())
|
||||
|
||||
const items = words({ exactly: 50 }).map(w => ({
|
||||
|
|
@ -229,14 +185,11 @@ describe('gun smith', () => {
|
|||
checked++
|
||||
if (checked === 50) {
|
||||
done()
|
||||
release()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('offs `on()`s', async () => {
|
||||
await whenReady()
|
||||
const node = instance.get(words()).get(words())
|
||||
|
||||
let called = false
|
||||
|
|
@ -250,12 +203,9 @@ describe('gun smith', () => {
|
|||
await node.pPut('return')
|
||||
await delay(500)
|
||||
expect(called).toBe(false)
|
||||
|
||||
release()
|
||||
})
|
||||
|
||||
it('offs `map().on()`s', async () => {
|
||||
await whenReady()
|
||||
const node = instance.get(words()).get(words())
|
||||
|
||||
let called = false
|
||||
|
|
@ -273,13 +223,9 @@ describe('gun smith', () => {
|
|||
await delay(500)
|
||||
|
||||
expect(called).toBe(false)
|
||||
|
||||
release()
|
||||
})
|
||||
|
||||
it('provides an user node with create(), auth() and leave()', async () => {
|
||||
await whenReady()
|
||||
|
||||
const ack = await new Promise(res => user.create(alias, pass, res))
|
||||
expect(ack.err).toBeUndefined()
|
||||
|
||||
|
|
@ -298,13 +244,9 @@ describe('gun smith', () => {
|
|||
expect(authAck.sea?.pub).toEqual(pub)
|
||||
expect(user.is?.pub).toEqual(pub)
|
||||
user.leave()
|
||||
|
||||
release()
|
||||
})
|
||||
|
||||
it('reliably provides authentication information across re-forges', async () => {
|
||||
await whenReady()
|
||||
|
||||
/** @type {GunT.AuthAck} */
|
||||
const authAck = await new Promise(res =>
|
||||
user.auth(alias, pass, ack => res(ack))
|
||||
|
|
@ -318,12 +260,9 @@ describe('gun smith', () => {
|
|||
expect(user.is?.pub).toEqual(pub)
|
||||
|
||||
user.leave()
|
||||
release()
|
||||
})
|
||||
|
||||
it('provides thenables for values', async () => {
|
||||
await whenReady()
|
||||
|
||||
const a = words()
|
||||
const b = words()
|
||||
const node = instance.get(a).get(b)
|
||||
|
|
@ -345,13 +284,9 @@ describe('gun smith', () => {
|
|||
.get(b)
|
||||
.then()
|
||||
expect(fetch).toEqual(value)
|
||||
|
||||
release()
|
||||
})
|
||||
|
||||
it('provides an special thenable put()', async () => {
|
||||
await whenReady()
|
||||
|
||||
const a = words()
|
||||
const b = words()
|
||||
const node = instance.get(a).get(b)
|
||||
|
|
@ -362,12 +297,9 @@ describe('gun smith', () => {
|
|||
const res = await node.then()
|
||||
|
||||
expect(res).toBe(value)
|
||||
|
||||
release()
|
||||
})
|
||||
|
||||
it('on()s and handles object>primitive>object transitions', done => {
|
||||
whenReady().then(() => {
|
||||
const a = {
|
||||
one: 1
|
||||
}
|
||||
|
|
@ -390,7 +322,6 @@ describe('gun smith', () => {
|
|||
} else if (checked === 3) {
|
||||
expect(removeBuiltInGunProps(data)).toEqual(c)
|
||||
done()
|
||||
release()
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -402,14 +333,12 @@ describe('gun smith', () => {
|
|||
node.put(c)
|
||||
}, 800)
|
||||
})
|
||||
})
|
||||
|
||||
// **************************************************************************
|
||||
// ** Long tests below
|
||||
// **************************************************************************
|
||||
|
||||
it('writes object items into sets and correctly populates item._.get with the newly created id', done => {
|
||||
whenReady().then(() => {
|
||||
const node = instance.get(words()).get(words())
|
||||
|
||||
const obj = {
|
||||
|
|
@ -422,13 +351,10 @@ describe('gun smith', () => {
|
|||
node.get(item._.get).once(data => {
|
||||
expect(removeBuiltInGunProps(data)).toEqual(obj)
|
||||
done()
|
||||
release()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('provides an special once() that restarts gun until a value is fetched', done => {
|
||||
whenReady().then(() => {
|
||||
const a = words()
|
||||
const b = words()
|
||||
const node = instance.get(a).get(b)
|
||||
|
|
@ -437,18 +363,14 @@ describe('gun smith', () => {
|
|||
node.specialOnce(data => {
|
||||
expect(data).toEqual(value)
|
||||
done()
|
||||
release()
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
node.put(value)
|
||||
}, 30000)
|
||||
})
|
||||
})
|
||||
|
||||
it('provides an special then() that restarts gun until a value is fetched', async () => {
|
||||
await whenReady()
|
||||
|
||||
const a = words()
|
||||
const b = words()
|
||||
const node = instance.get(a).get(b)
|
||||
|
|
@ -461,13 +383,10 @@ describe('gun smith', () => {
|
|||
const res = await node.specialThen()
|
||||
|
||||
expect(res).toBe(value)
|
||||
|
||||
release()
|
||||
})
|
||||
|
||||
it('provides an special on() that restarts gun when a value has not been obtained in a determinate amount of time', done => {
|
||||
// Kinda crappy test, this should be easier to test in real usage.
|
||||
whenReady().then(() => {
|
||||
const initialProcCounter = Gun._getProcCounter()
|
||||
|
||||
const node = instance.get(words()).get(words())
|
||||
|
|
@ -479,7 +398,6 @@ describe('gun smith', () => {
|
|||
if (data === secondValue) {
|
||||
expect(Gun._getProcCounter()).toEqual(initialProcCounter + 1)
|
||||
done()
|
||||
release()
|
||||
}
|
||||
})
|
||||
)
|
||||
|
|
@ -488,5 +406,4 @@ describe('gun smith', () => {
|
|||
node.put(secondValue)
|
||||
}, 32000)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue