Skip to content

Commit 92c86de

Browse files
committed
test(sync): cleanup Cypress tests
Signed-off-by: Jonas <[email protected]>
1 parent 339b5da commit 92c86de

File tree

2 files changed

+68
-61
lines changed

2 files changed

+68
-61
lines changed

cypress/e2e/api/SyncServiceProvider.spec.js

Lines changed: 7 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import { randUser } from '../../utils/index.js'
2424
import { SyncService } from '../../../src/services/SyncService.js'
2525
import createSyncServiceProvider from '../../../src/services/SyncServiceProvider.js'
26-
import { Doc, applyUpdate, encodeStateAsUpdate, encodeStateVector } from 'yjs'
26+
import { Doc } from 'yjs'
2727

2828
const user = randUser()
2929

@@ -74,29 +74,7 @@ describe('Sync service provider', function() {
7474
})
7575
}
7676

77-
it('syncs even when initial state was present', function() {
78-
const sourceMap = this.source.getMap()
79-
const targetMap = this.target.getMap()
80-
sourceMap.set('unrelated', 'value')
81-
cy.intercept({ method: 'POST', url: '**/apps/text/session/push' })
82-
.as('push')
83-
cy.intercept({ method: 'POST', url: '**/apps/text/session/sync' })
84-
.as('sync')
85-
cy.wait('@push')
86-
cy.then(() => {
87-
sourceMap.set('keyA', 'valueA')
88-
expect(targetMap.get('keyB')).to.be.eq(undefined)
89-
})
90-
cy.wait('@sync')
91-
cy.wait('@sync')
92-
// eslint-disable-next-line cypress/no-unnecessary-waiting
93-
cy.wait(1000)
94-
cy.then(() => {
95-
expect(targetMap.get('keyA')).to.be.eq('valueA')
96-
})
97-
})
98-
99-
it.only('recovers from a dropped message', function() {
77+
it('recovers from a dropped message', function() {
10078
const sourceMap = this.source.getMap()
10179
const targetMap = this.target.getMap()
10280
cy.intercept({ method: 'POST', url: '**/apps/text/session/push' })
@@ -158,7 +136,11 @@ describe('Sync service provider', function() {
158136
})
159137
})
160138

161-
it('is not too chatty', function() {
139+
/*
140+
* Counts the amount of push and sync requests in one minute.
141+
* Skipped per default, useful for comparison before/after changes to SyncProvider or PollingBackend.
142+
*/
143+
it.skip('is not too chatty', function() {
162144
const sourceMap = this.source.getMap()
163145
const targetMap = this.target.getMap()
164146
cy.intercept({ method: 'POST', url: '**/apps/text/session/push' })
@@ -180,40 +162,4 @@ describe('Sync service provider', function() {
180162
// 2 clients sync fast first and then every 5 seconds -> 2*12 = 24. Actual 32.
181163
cy.get('@sync.all').its('length').should('be.lessThan', 60)
182164
})
183-
184-
it.only('applies step in wrong order', function() {
185-
const source = new Doc()
186-
const target = new Doc()
187-
const sourceMap = source.getMap()
188-
const targetMap = target.getMap()
189-
190-
target.on('afterTransaction', (tr, doc) => {
191-
// console.log('afterTransaction', tr)
192-
})
193-
194-
// Add keyA to source and apply to target
195-
sourceMap.set('keyA', 'valueA')
196-
const update0A = encodeStateAsUpdate(source)
197-
const sourceVectorA = encodeStateVector(source)
198-
applyUpdate(target, update0A)
199-
expect(targetMap.get('keyA')).to.be.eq('valueA')
200-
201-
// Add keyB to source, don't apply to target yet
202-
sourceMap.set('keyB', 'valueB')
203-
const updateAB = encodeStateAsUpdate(source, sourceVectorA)
204-
const sourceVectorB = encodeStateVector(source)
205-
206-
// Add keyC to source, apply to target
207-
sourceMap.set('keyC', 'valueC')
208-
const updateBC = encodeStateAsUpdate(source, sourceVectorB)
209-
applyUpdate(target, updateBC)
210-
expect(targetMap.get('keyB')).to.be.eq(undefined)
211-
expect(targetMap.get('keyC')).to.be.eq(undefined)
212-
213-
// Apply keyB to target
214-
applyUpdate(target, updateAB)
215-
expect(targetMap.get('keyB')).to.be.eq('valueB')
216-
expect(targetMap.get('keyC')).to.be.eq('valueC')
217-
})
218-
219165
})

cypress/e2e/api/Yjs.spec.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* @copyright Copyright (c) 2023 Jonas <[email protected]>
3+
*
4+
* @author Jonas <[email protected]>
5+
*
6+
* @license AGPL-3.0-or-later
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
23+
import { applyUpdate, Doc, encodeStateAsUpdate, encodeStateVector } from 'yjs'
24+
25+
describe('Yjs', function() {
26+
// Only tests that Yjs allows to apply steps in wrong order
27+
it('applies step in wrong order', function() {
28+
const source = new Doc()
29+
const target = new Doc()
30+
const sourceMap = source.getMap()
31+
const targetMap = target.getMap()
32+
33+
target.on('afterTransaction', (tr, doc) => {
34+
// console.log('afterTransaction', tr)
35+
})
36+
37+
// Add keyA to source and apply to target
38+
sourceMap.set('keyA', 'valueA')
39+
const update0A = encodeStateAsUpdate(source)
40+
const sourceVectorA = encodeStateVector(source)
41+
applyUpdate(target, update0A)
42+
expect(targetMap.get('keyA')).to.be.eq('valueA')
43+
44+
// Add keyB to source, don't apply to target yet
45+
sourceMap.set('keyB', 'valueB')
46+
const updateAB = encodeStateAsUpdate(source, sourceVectorA)
47+
const sourceVectorB = encodeStateVector(source)
48+
49+
// Add keyC to source, apply to target
50+
sourceMap.set('keyC', 'valueC')
51+
const updateBC = encodeStateAsUpdate(source, sourceVectorB)
52+
applyUpdate(target, updateBC)
53+
expect(targetMap.get('keyB')).to.be.eq(undefined)
54+
expect(targetMap.get('keyC')).to.be.eq(undefined)
55+
56+
// Apply keyB to target
57+
applyUpdate(target, updateAB)
58+
expect(targetMap.get('keyB')).to.be.eq('valueB')
59+
expect(targetMap.get('keyC')).to.be.eq('valueC')
60+
})
61+
})

0 commit comments

Comments
 (0)