Skip to content

Commit ee33fff

Browse files
fix(js-tests): fix test isolation bugs exposed by Jasmine 5 random ordering (#41616)
* fix(js-tests): fix test isolation bugs exposed by Jasmine 5 random ordering Jasmine 5 runs tests in random order by default, which exposed several pre-existing test isolation bugs where shared singleton state was left dirty between tests. Fixes: - fileactionsmenuSpec.js: call OC.hideMenus() in afterEach to clear OC._currentMenu before calling menu.remove(), preventing a stale reference from triggering a double slideUp in subsequent tests - files_sharing/appSpec.js: save and restore OCA.Files.fileActions in the 'file actions' describe's beforeEach/afterEach so that stale _onActionsUpdated handlers registered by OCA.Files.App (in files/appSpec.js) don't fire with fileList=null and cause infinite recursion - systemtagsinfoviewSpec.js: reset allTagsCollection (OC.SystemTags.collection singleton) in beforeEach and afterEach of the 'events' describe, so that model mutations (e.g. set('name', 'test1_renamed')) don't persist into subsequent test suites - systemtagsinputfieldSpec.js: call view.collection.reset() in both the 'as admin' and 'as user' initSelection beforeEach blocks so that stale models with matching ids from prior tests are cleared before adding fresh testTags (Backbone.add silently ignores duplicate-id models) All fixes verified with 25 consecutive successful karma runs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com> * chore(changelog): add entry for PR #41616 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com> --------- Signed-off-by: Thomas Müller <1005065+DeepDiver1975@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a0cc826 commit ee33fff

5 files changed

Lines changed: 21 additions & 0 deletions

File tree

apps/files/tests/js/fileactionsmenuSpec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ describe('OCA.Files.FileActionsMenu tests', function() {
9393
fileActions = null;
9494
fileList.destroy();
9595
fileList = undefined;
96+
OC.hideMenus();
9697
menu.remove();
9798
$('#dir, #permissions, #filestable').remove();
9899
});

apps/files_sharing/tests/js/appSpec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,18 @@ describe('OCA.Sharing.App tests', function() {
5858
});
5959
describe('file actions', function() {
6060
var oldLegacyFileActions;
61+
var oldFileActions;
6162

6263
beforeEach(function() {
6364
oldLegacyFileActions = window.FileActions;
6465
window.FileActions = new OCA.Files.FileActions();
66+
oldFileActions = OCA.Files.fileActions;
67+
OCA.Files.fileActions = new OCA.Files.FileActions();
6568
});
6669

6770
afterEach(function() {
6871
window.FileActions = oldLegacyFileActions;
72+
OCA.Files.fileActions = oldFileActions;
6973
});
7074
it('provides default file actions', function() {
7175
_.each([fileListIn, fileListOut], function(fileList) {

apps/systemtags/tests/js/systemtagsinfoviewSpec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ describe('OCA.SystemTags.SystemTagsInfoView tests', function() {
5353
var allTagsCollection;
5454
beforeEach(function() {
5555
allTagsCollection = view._inputView.collection;
56+
allTagsCollection.reset();
5657

5758
allTagsCollection.add([
5859
{id: '1', name: 'test1'},
@@ -68,6 +69,9 @@ describe('OCA.SystemTags.SystemTagsInfoView tests', function() {
6869
]);
6970
view.render();
7071
});
72+
afterEach(function() {
73+
allTagsCollection.reset();
74+
});
7175
it('add tag to list view', function() {
7276
view.selectedTagsCollection.add([{id: '4', name: 'test4'}]);
7377
expect(view.$el.find('.system-tag-list-item').length).toEqual(4);

changelog/unreleased/41616

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Bugfix: Fix JS test isolation bugs exposed by Jasmine 5 random test ordering
2+
3+
Several JS test specs left shared singleton state dirty between tests,
4+
causing intermittent failures when Jasmine 5 ran tests in random order.
5+
Fixed OC._currentMenu leak in fileactionsmenuSpec, stale OCA.Files.fileActions
6+
reference causing infinite recursion in files_sharing/appSpec, and stale
7+
models in the OC.SystemTags.collection singleton in systemtagsinfoviewSpec
8+
and systemtagsinputfieldSpec.
9+
10+
https://github.com/owncloud/core/pull/41616

core/js/tests/specs/systemtags/systemtagsinputfieldSpec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ describe('OC.SystemTags.SystemTagsInputField tests', function() {
339339
new OC.SystemTags.SystemTagModel({id: '3', name: 'test3', userAssignable: false, canAssign: false}),
340340
new OC.SystemTags.SystemTagModel({id: '4', name: 'test4', userAssignable: false, canAssign: true})
341341
];
342+
view.collection.reset();
342343
});
343344
afterEach(function() {
344345
fetchStub.restore();
@@ -522,6 +523,7 @@ describe('OC.SystemTags.SystemTagsInputField tests', function() {
522523
new OC.SystemTags.SystemTagModel({id: '3', name: 'test3', userAssignable: false, canAssign: false}),
523524
new OC.SystemTags.SystemTagModel({id: '4', name: 'test4', userAssignable: false, canAssign: true})
524525
];
526+
view.collection.reset();
525527
view.render();
526528
});
527529
afterEach(function() {

0 commit comments

Comments
 (0)