From 11cf48259a987ab2d48355f14b3f11d897d6c8fa Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Sun, 14 Mar 2021 21:33:23 -0700 Subject: test: separate tests from background.js, clean up and document a bit also makes the test more lenient (subset instead of equality for tab entries) --- extension/background.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'extension') diff --git a/extension/background.js b/extension/background.js index b0f937d..4caaaf0 100644 --- a/extension/background.js +++ b/extension/background.js @@ -82,7 +82,6 @@ async function detachDebugger(tabId) { })); } const TabManager = (function() { - if (TESTING) return; if (chrome.debugger) chrome.debugger.onEvent.addListener((source, method, params) => { console.log(source, method, params); if (method === "Page.frameStartedLoading") { @@ -614,17 +613,6 @@ for (let i = 10; i >= 0; i--) { // so you could patch more routes in at runtime, but I need to think // a bit about how to make that work with wildcards. } -if (TESTING) { // I wish I could color this section with... a pink background, or something. - const assert = require('assert'); - (async () => { - assert.deepEqual(await router['/tabs/by-id/*'].readdir(), { entries: ['.', '..', 'url.txt', 'title.txt', 'text.txt', 'window', 'control', 'debugger'] }); - assert.deepEqual(await router['/'].readdir(), { entries: ['.', '..', 'windows', 'extensions', 'tabs', 'runtime'] }); - assert.deepEqual(await router['/tabs'].readdir(), { entries: ['.', '..', 'create', 'by-id', 'by-title', 'last-focused'] }); - - assert.deepEqual(findRoute('/tabs/by-id/TABID/url.txt'), router['/tabs/by-id/*/url.txt']); - })() -} - // fill in default implementations of fs ops for (let key in router) { @@ -773,6 +761,12 @@ function tryConnect() { port.onDisconnect.addListener(p => {console.log('disconnect', p)}); } -if (!TESTING) { + +if (typeof process === 'object') { + // we're running in node (as part of a test) + // return everything they might want to test + module.exports = {router, findRoute}; + +} else { tryConnect(); } -- cgit v1.2.3