From 4deb0f6d59a46319863306c7668a0da1cab56729 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Tue, 11 Jun 2019 10:02:10 +0200 Subject: [PATCH] DEV: prevents post-cooked decorators to leak between tests (#7744) --- app/assets/javascripts/discourse/widgets/post-cooked.js.es6 | 6 +++++- test/javascripts/helpers/qunit-helpers.js.es6 | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/widgets/post-cooked.js.es6 b/app/assets/javascripts/discourse/widgets/post-cooked.js.es6 index 4daa4267745..d434012b4b9 100644 --- a/app/assets/javascripts/discourse/widgets/post-cooked.js.es6 +++ b/app/assets/javascripts/discourse/widgets/post-cooked.js.es6 @@ -4,13 +4,17 @@ import { isValidLink } from "discourse/lib/click-track"; import { number } from "discourse/lib/formatter"; import highlightText from "discourse/lib/highlight-text"; -const _decorators = []; +let _decorators = []; // Don't call this directly: use `plugin-api/decorateCooked` export function addDecorator(cb) { _decorators.push(cb); } +export function resetDecorators() { + _decorators = []; +} + export default class PostCooked { constructor(attrs, decoratorHelper, currentUser) { this.attrs = attrs; diff --git a/test/javascripts/helpers/qunit-helpers.js.es6 b/test/javascripts/helpers/qunit-helpers.js.es6 index 652d3d1da6e..759e64f7064 100644 --- a/test/javascripts/helpers/qunit-helpers.js.es6 +++ b/test/javascripts/helpers/qunit-helpers.js.es6 @@ -13,6 +13,7 @@ import { flushMap } from "discourse/models/store"; import { clearRewrites } from "discourse/lib/url"; import { initSearchData } from "discourse/widgets/search-menu"; import { resetDecorators } from "discourse/widgets/widget"; +import { resetDecorators as resetPostCookedDecorators } from "discourse/widgets/post-cooked"; import { resetCache as resetOneboxCache } from "pretty-text/oneboxer"; import { resetCustomPostMessageCallbacks } from "discourse/controllers/topic"; @@ -124,6 +125,7 @@ export function acceptance(name, options) { clearRewrites(); initSearchData(); resetDecorators(); + resetPostCookedDecorators(); resetOneboxCache(); resetCustomPostMessageCallbacks(); Discourse.reset();