From fb1d2f7dbb0274424c04a8cbbe7225b0291e88c2 Mon Sep 17 00:00:00 2001 From: Lawrence Siden Date: Tue, 13 Feb 2018 11:01:17 -0500 Subject: [PATCH] fix: bug-705: cleanupPlugins() should not throw exception when no arguments are provided (#709) --- doc/API.md | 13 ++++++++++++- lib/core/public/cleanup-plugins.js | 5 ++++- test/core/public/cleanup-plugins.js | 24 ++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/doc/API.md b/doc/API.md index 3f514dd748..27fdefbcfb 100644 --- a/doc/API.md +++ b/doc/API.md @@ -617,7 +617,18 @@ Register a plugin with the aXe plugin system. See [implementing a plugin](plugin ### API Name: axe.cleanup -Call the plugin system's cleanup function. See [implementing a plugin](plugins.md). +Call each plugin's cleanup function. See [implementing a plugin](plugins.md). + +The signature is: + +``` + axe.cleanup(resolve, reject) +``` + +`resolve` and `reject` are functions that will be invoked on success or failure respectively. + +`resolve` takes no arguments and `reject` takes a single argument that must be a string or have a toString() method in its prototype. + ### API Name: axe.a11yCheck diff --git a/lib/core/public/cleanup-plugins.js b/lib/core/public/cleanup-plugins.js index b3e6a0e876..cd7d256b8d 100644 --- a/lib/core/public/cleanup-plugins.js +++ b/lib/core/public/cleanup-plugins.js @@ -1,6 +1,9 @@ function cleanupPlugins(resolve, reject) { - 'use strict'; + 'use strict'; + resolve = resolve || function() {}; + reject = reject || axe.log; + if (!axe._audit) { throw new Error('No audit configured'); } diff --git a/test/core/public/cleanup-plugins.js b/test/core/public/cleanup-plugins.js index 66d4d626d7..1f1ae28faf 100644 --- a/test/core/public/cleanup-plugins.js +++ b/test/core/public/cleanup-plugins.js @@ -59,6 +59,30 @@ describe('cleanupPlugins', function () { }); + it('should not throw exception if no arguments are provided', function(done) { + var cleaned = false; + axe._load({ + rules: [] + }); + axe.registerPlugin({ + id: 'p', + run: function () {}, + add: function (impl) { + this._registry[impl.id] = impl; + }, + commands: [] + }); + axe.plugins.p.cleanup = function (res) { + cleaned = true; + res(); + }; + assert.doesNotThrow(function () { + cleanupPlugins(); + done(); + }); + }); + + it('should send command to frames to cleanup', function (done) { createFrames(function () { axe._load({});