tests: fix memory leaks (#2389)

This commit is contained in:
Mo
2023-08-06 15:23:31 -05:00
committed by GitHub
parent d59e1befff
commit 8655bdb5dd
76 changed files with 3904 additions and 3840 deletions

View File

@@ -13,11 +13,7 @@ describe('basic auth', function () {
}
let context
afterEach(async function () {
await context.deinit()
localStorage.clear()
})
let expectedItemCount
beforeEach(async function () {
localStorage.clear()
@@ -26,12 +22,23 @@ describe('basic auth', function () {
await context.launch()
this.expectedItemCount = BaseItemCounts.DefaultItemsWithAccount
expectedItemCount = BaseItemCounts.DefaultItemsWithAccount
})
afterEach(async function () {
await context.deinit()
localStorage.clear()
context = undefined
sinon.restore()
})
it('successfully register new account', async function () {
const response = await context.register()
expect(response).to.be.ok
expect(await context.application.encryption.getRootKey()).to.be.ok
})
@@ -58,7 +65,7 @@ describe('basic auth', function () {
expect(await context.application.encryption.getRootKey()).to.be.ok
context.application = await Factory.signOutApplicationAndReturnNew(context.application)
await context.signout()
expect(await context.application.encryption.getRootKey()).to.not.be.ok
expect(context.application.encryption.rootKeyManager.getKeyMode()).to.equal(KeyMode.RootKeyNone)
@@ -233,7 +240,7 @@ describe('basic auth', function () {
await specContext.launch()
await specContext.register()
await specContext.signout()
await specContext.deinit()
specContext = await Factory.createAppContextWithFakeCrypto(Math.random(), uppercase, password)
@@ -255,10 +262,11 @@ describe('basic auth', function () {
* with an uppercase email
*/
const password = UuidGenerator.GenerateUuid()
let specContext = await Factory.createAppContextWithFakeCrypto(Math.random(), nospace, password)
await specContext.launch()
await specContext.register()
await specContext.signout()
await specContext.deinit()
specContext = await Factory.createAppContextWithFakeCrypto(Math.random(), withspace, password)
await specContext.launch()
@@ -272,7 +280,8 @@ describe('basic auth', function () {
it('fails login with wrong password', async function () {
await context.register()
context.application = await Factory.signOutApplicationAndReturnNew(context.application)
await context.signout()
const response = await context.application.signIn(
context.email,
'wrongpassword',
@@ -299,7 +308,8 @@ describe('basic auth', function () {
expect(response.error).to.be.ok
/** Ensure we can still log in */
context.application = await Factory.signOutAndBackIn(context.application, context.email, context.password)
await context.signout()
await context.signIn()
}).timeout(20000)
it('registering for new account and completing first after download sync should not put us out of sync', async function () {
@@ -339,23 +349,23 @@ describe('basic auth', function () {
const noteCount = 5
await Factory.createManyMappedNotes(context.application, noteCount)
this.expectedItemCount += noteCount
expectedItemCount += noteCount
await context.sync()
expect(context.application.items.items.length).to.equal(this.expectedItemCount)
expect(context.application.items.items.length).to.equal(expectedItemCount)
const newPassword = 'newpassword'
const response = await context.application.changePassword(context.password, newPassword)
expect(response.error).to.not.be.ok
this.expectedItemCount += ['new items key'].length
expect(context.application.items.items.length).to.equal(this.expectedItemCount)
expectedItemCount += ['new items key'].length
expect(context.application.items.items.length).to.equal(expectedItemCount)
expect(context.application.payloads.invalidPayloads.length).to.equal(0)
await context.application.sync.markAllItemsAsNeedingSyncAndPersist()
await context.sync(syncOptions)
expect(context.application.items.items.length).to.equal(this.expectedItemCount)
expect(context.application.items.items.length).to.equal(expectedItemCount)
}).timeout(40000)
it('should sign into account after changing password', async function () {
@@ -365,7 +375,7 @@ describe('basic auth', function () {
const response = await context.application.changePassword(context.password, newPassword)
expect(response.error).to.not.be.ok
this.expectedItemCount += ['new items key'].length
expectedItemCount += ['new items key'].length
await context.signout()
@@ -382,7 +392,7 @@ describe('basic auth', function () {
expect(signinResponse.data.error).to.not.be.ok
expect(await context.application.encryption.getRootKey()).to.be.ok
expect(context.application.items.items.length).to.equal(this.expectedItemCount)
expect(context.application.items.items.length).to.equal(expectedItemCount)
expect(context.application.payloads.invalidPayloads.length).to.equal(0)
})
@@ -393,7 +403,7 @@ describe('basic auth', function () {
const noteCount = 3
await Factory.createManyMappedNotes(context.application, noteCount)
this.expectedItemCount += noteCount
expectedItemCount += noteCount
await context.sync()
@@ -401,9 +411,9 @@ describe('basic auth', function () {
const response = await context.application.changePassword(context.password, newPassword)
expect(response.error).to.not.be.ok
this.expectedItemCount += ['new items key'].length
expectedItemCount += ['new items key'].length
expect(context.application.items.items.length).to.equal(this.expectedItemCount)
expect(context.application.items.items.length).to.equal(expectedItemCount)
})
it('changes password many times', async function () {
@@ -411,7 +421,7 @@ describe('basic auth', function () {
const noteCount = 10
await Factory.createManyMappedNotes(context.application, noteCount)
this.expectedItemCount += noteCount
expectedItemCount += noteCount
await context.application.sync.sync(syncOptions)
const numTimesToChangePw = 3
@@ -422,12 +432,12 @@ describe('basic auth', function () {
await context.application.changePassword(currentPassword, newPassword)
/** New items key */
this.expectedItemCount++
expectedItemCount++
currentPassword = newPassword
newPassword = Factory.randomString()
expect(context.application.items.items.length).to.equal(this.expectedItemCount)
expect(context.application.items.items.length).to.equal(expectedItemCount)
expect(context.application.payloads.invalidPayloads.length).to.equal(0)
await context.application.sync.markAllItemsAsNeedingSyncAndPersist()
@@ -460,7 +470,7 @@ describe('basic auth', function () {
email: context.email,
password: context.password,
})
context.application = await Factory.signOutApplicationAndReturnNew(context.application)
await context.signout()
const performSignIn = sinon.spy(context.application.sessions, 'performSignIn')
await context.application.signIn(context.email, 'wrong password', undefined, undefined, undefined, true)
expect(performSignIn.callCount).to.equal(1)