TabFS/test/test.js
Omar Rizwan be519afe5f extension,test: Start on simplifying routing.
Introduces a 'named variable' syntax so we can remove all the manual
indexing into path components / converting to int in individual fs
ops.

Also rewrites the route finding to use regex: all routes are compiled
to regexes, then the route finder just walks through them all until it
hits a match.

Doesn't fully work yet; JS test passes.
2021-03-21 15:35:01 -07:00

22 lines
797 B
JavaScript

const assert = require('assert');
// mock chrome namespace
global.chrome = {};
// run background.js
const {router, findRoute} = require('../extension/background');
(async () => {
const tabRoute = await router['/tabs/by-id/#TAB_ID'].readdir();
assert(['.', '..', 'url.txt', 'title.txt', 'text.txt']
.every(file => tabRoute.entries.includes(file)));
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/10/url.txt'),
router['/tabs/by-id/#TAB_ID/url.txt']);
})();