Skip to content

Commit

Permalink
Update formatting to new rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinhoefling committed Mar 22, 2022
1 parent 263f62a commit 1c744e3
Show file tree
Hide file tree
Showing 18 changed files with 76 additions and 80 deletions.
6 changes: 3 additions & 3 deletions tests/locales.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ describe('Locales', () => {
referenceKeys = Object.keys(reference).sort();
});

['de'].forEach(localeId => {
['de'].forEach((localeId) => {
test(`${localeId} have same keys as reference`, () => {
const locale = require(`${__dirname}/../web-extension/_locales/${localeId}/messages.json`);
const localeKeys = Object.keys(locale).sort();
expect(localeKeys).toEqual(referenceKeys);
});
});

['en', 'de'].forEach(localeId => {
['en', 'de'].forEach((localeId) => {
test(`${localeId} entries have message and description`, () => {
const locale = require(`${__dirname}/../web-extension/_locales/${localeId}/messages.json`);
const localeKeys = Object.keys(locale).sort();
localeKeys.forEach(key => {
localeKeys.forEach((key) => {
expect(locale[key].message);
expect(locale[key].description);
});
Expand Down
26 changes: 13 additions & 13 deletions tests/unit/background.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ global.browser.extension = {
};
global.urlDomain = jest.fn(() => 'some.url');
global.i18n = {
getMessage: jest.fn(key => `__i18n_${key}__`),
getMessage: jest.fn((key) => `__i18n_${key}__`),
};
global.browser.tabs.sendMessage = jest.fn();
global.browser.webRequest = { onAuthRequired: { addListener: jest.fn() } };
global.executeOnSetting = jest.fn();
global.isChrome = jest.fn();
global.openURL = jest.fn();
global.makeAbsolute = jest.fn(string => string);
global.makeAbsolute = jest.fn((string) => string);

require('background.js');

Expand Down Expand Up @@ -44,7 +44,7 @@ describe('background', () => {
test('raises on content script messages', () => {
expect.assertions(2);
const msg = 'Background script received unexpected message {} from content script or popup window.';
return background.processMessageAndCatch({}, { tab: 42 }).catch(error => {
return background.processMessageAndCatch({}, { tab: 42 }).catch((error) => {
expect(global.showNotificationOnSetting.mock.calls).toEqual([[msg]]);
expect(error.message).toBe(msg);
});
Expand All @@ -53,7 +53,7 @@ describe('background', () => {
test('raises on unknown message types', () => {
expect.assertions(2);
const msg = `Background script received unexpected message {"type":"UNKNOWN"} from extension`;
return background.processMessageAndCatch({ type: 'UNKNOWN' }, {}).catch(error => {
return background.processMessageAndCatch({ type: 'UNKNOWN' }, {}).catch((error) => {
expect(global.showNotificationOnSetting.mock.calls).toEqual([[msg]]);
expect(error.message).toBe(msg);
});
Expand All @@ -62,7 +62,7 @@ describe('background', () => {
test('do not show notification if popup is shown', () => {
expect.assertions(1);
global.browser.extension.getViews.mockReturnValueOnce({ length: 1 });
return background.processMessageAndCatch({ type: 'UNKNOWN' }, {}).catch(error => {
return background.processMessageAndCatch({ type: 'UNKNOWN' }, {}).catch((error) => {
expect(global.showNotificationOnSetting.mock.calls.length).toEqual(0);
});
});
Expand All @@ -81,7 +81,7 @@ describe('background', () => {
});
global.browser.tabs.sendMessage.mockResolvedValue();
global.browser.tabs.onUpdated = {
addListener: jest.fn(callback => callback(42, { status: 'complete' })),
addListener: jest.fn((callback) => callback(42, { status: 'complete' })),
removeListener: jest.fn(),
};
});
Expand All @@ -104,7 +104,7 @@ describe('background', () => {
global.sendNativeAppMessage.mockResolvedValue({});
expect.assertions(1);
global.openURL.mockResolvedValue({ id: 42, status: 'complete' });
return openTabMessage().catch(error => {
return openTabMessage().catch((error) => {
expect(error.message).toBe('__i18n_noURLInEntry__');
});
});
Expand All @@ -129,7 +129,7 @@ describe('background', () => {
expect.assertions(2);
global.openURL.mockResolvedValue({ id: 42, status: 'loading' });

const promise = openTabMessage().catch(error => {
const promise = openTabMessage().catch((error) => {
expect(global.browser.tabs.onUpdated.removeListener.mock.calls.length).toBe(1);
expect(error).toBe('Loading timed out');
});
Expand Down Expand Up @@ -159,15 +159,15 @@ describe('background', () => {
test('raises if native app message response contains error', () => {
global.sendNativeAppMessage.mockResolvedValue({ error: 'some native app error' });
expect.assertions(1);
return loginTabMessage().catch(error => {
return loginTabMessage().catch((error) => {
expect(error.message).toBe('some native app error');
});
});

test('raises if username is equal to the domain message response contains error', () => {
global.sendNativeAppMessage.mockResolvedValue({ username: 'some.url', password: 'waldfee' });
expect.assertions(1);
return loginTabMessage().catch(error => {
return loginTabMessage().catch((error) => {
expect(error.message).toBe('__i18n_couldNotDetermineUsernameMessage__');
});
});
Expand Down Expand Up @@ -252,7 +252,7 @@ describe('background', () => {
return windowCreatePromise.then(() => {
browser.windows.onRemoved.addListener.mock.calls[0][0](42);

return authRequiredPromise.then(authRequiredResult => {
return authRequiredPromise.then((authRequiredResult) => {
expect(browser.windows.create.mock.calls.length).toBe(1);
expect(browser.windows.onRemoved.addListener.mock.calls).toEqual(
browser.windows.onRemoved.removeListener.mock.calls
Expand All @@ -277,7 +277,7 @@ describe('background', () => {
{ tab: {}, url: validAuthPopupUrl }
);

return Promise.all([authRequiredPromise, processMessagePromise]).then(null, processMessageError => {
return Promise.all([authRequiredPromise, processMessagePromise]).then(null, (processMessageError) => {
expect(browser.windows.create.mock.calls.length).toBe(1);
expect(browser.windows.onRemoved.addListener.mock.calls.length).toBe(1);
expect(browser.windows.onRemoved.removeListener.mock.calls.length).toBe(0); // popup still open
Expand Down Expand Up @@ -337,7 +337,7 @@ describe('background', () => {

global.executeOnSetting = jest.fn((_, enabled, disabled) => disabled());

return onAuthRequiredCallback({ url: authUrl }).then(authRequiredResult => {
return onAuthRequiredCallback({ url: authUrl }).then((authRequiredResult) => {
expect(browser.windows.create.mock.calls.length).toBe(0);
expect(browser.windows.onRemoved.addListener.mock.calls.length).toBe(0);
expect(browser.windows.onRemoved.removeListener.mock.calls.length).toBe(0);
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/content.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ describe('on sample login form', () => {
}

beforeEach(() => {
global.window.requestAnimationFrame = fn => {
global.window.requestAnimationFrame = (fn) => {
fn();
};
const form = document.getElementById('form');
form.addEventListener('submit', e => {
form.addEventListener('submit', (e) => {
e.preventDefault();
});
});
Expand Down Expand Up @@ -334,7 +334,7 @@ for (const page in pages) {
let clickCallback;

function setupClickListener() {
const onClick = jest.fn(event => {
const onClick = jest.fn((event) => {
event.preventDefault();
});
document.addEventListener('click', onClick);
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ global.logAndDisplayError = jest.fn();
global.currentPageUrl = 'http://some.domain';
global.searchTerm = '';
global.i18n = {
getMessage: jest.fn(key => {
getMessage: jest.fn((key) => {
return `__MSG_${key}__`;
}),
};
Expand Down Expand Up @@ -182,7 +182,7 @@ describe('create', () => {
});

describe('initCreate', () => {
['create_docreate', 'create_doabort', 'create_generate'].forEach(id => {
['create_docreate', 'create_doabort', 'create_generate'].forEach((id) => {
test(`registers eventhandler for ${id}`, () => {
const element = document.getElementById('create_docreate');
spyOn(element, 'addEventListener');
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/details.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ global.currentTabId = 42;
global.currentPageUrl = 'http://other.domain';
global.re_weburl = new RegExp('https://.*');
global.logAndDisplayError = jest.fn();
global.openURLOnEvent = jest.fn(event => {
global.openURLOnEvent = jest.fn((event) => {
event.preventDefault();
});
global.getSettings = jest.fn();
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/generic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe('localStorage wrappers', () => {
test('get key', () => {
expect.assertions(1);
return generic.setLocalStorageKey('muh', 123).then(() => {
return generic.getLocalStorageKey('muh').then(value => {
return generic.getLocalStorageKey('muh').then((value) => {
expect(value).toBe(123);
});
});
Expand Down Expand Up @@ -216,7 +216,7 @@ describe('checkVersion', () => {
global.browser.runtime.sendNativeMessage.mockResolvedValue({ major: 1, minor: 8, patch: 4 });
return generic.checkVersion().then(
() => {},
error => {
(error) => {
expect(error.message).toBe('Please update gopass to version 1.8.5 or newer.');
}
);
Expand All @@ -225,15 +225,15 @@ describe('checkVersion', () => {
test('resolves with minimum version', () => {
expect.assertions(1);
global.browser.runtime.sendNativeMessage.mockResolvedValue({ major: 1, minor: 8, patch: 5 });
return generic.checkVersion().then(value => {
return generic.checkVersion().then((value) => {
expect(value).toBe(undefined);
});
});

test('resolves with larger version', () => {
expect.assertions(1);
global.browser.runtime.sendNativeMessage.mockResolvedValue({ major: 2, minor: 9, patch: 2 });
return generic.checkVersion().then(value => {
return generic.checkVersion().then((value) => {
expect(value).toBe(undefined);
});
});
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/gopassbridge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ describe('switchTab', () => {
describe('handles authUrl query parameter', () => {
beforeEach(() => {
global.getLocalStorageKey.mockResolvedValue(undefined);
global.urlDomain = jest.fn(url => url);
global.urlDomain = jest.fn((url) => url);
global.getPopupUrl = jest.fn(() => 'http://localhost/');
jsdom.reconfigure({ url: 'http://localhost/?authUrl=' + encodeURIComponent('https://example.com') });
document.body.innerHTML = documentHtml;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/popup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ global.urlDomain = jest.fn(() => 'some.domain');
global.currentPageUrl = 'http://some.domain';
global.openURLOnEvent = jest.fn();
global.i18n = {
getMessage: jest.fn(key => {
getMessage: jest.fn((key) => {
return `__MSG_${key}__`;
}),
};
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ global.setStatusText = jest.fn();
global.onEntryData = jest.fn();
global.copyToClipboard = jest.fn();
global.i18n = {
getMessage: jest.fn(messagekey => `__KEY_${messagekey}__`),
getMessage: jest.fn((messagekey) => `__KEY_${messagekey}__`),
};
global.spinnerTimeout = 24;
global.urlDomain = jest.fn(url => 'some.host');
global.urlDomain = jest.fn((url) => 'some.host');
global.createButtonWithCallback = jest.fn(() => document.createElement('div'));
global.switchToCreateNewDialog = jest.fn();
global.setLocalStorageKey = jest.fn();
Expand Down
12 changes: 6 additions & 6 deletions web-extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
let currentAuthRequest = null;

function _processLoginTabMessage(entry, tab) {
return sendNativeAppMessage({ type: 'getLogin', entry: entry }).then(response => {
return sendNativeAppMessage({ type: 'getLogin', entry: entry }).then((response) => {
if (response.error) {
throw new Error(response.error);
}
Expand Down Expand Up @@ -52,14 +52,14 @@ function _waitForTabLoaded(tab) {

function _openEntry(entry) {
return sendNativeAppMessage({ type: 'getData', entry })
.then(message => {
.then((message) => {
if (!message.url) {
throw new Error(i18n.getMessage('noURLInEntry'));
}
return openURL(message.url);
})
.then(_waitForTabLoaded)
.then(tab => _processLoginTabMessage(entry, tab));
.then((tab) => _processLoginTabMessage(entry, tab));
}

function _processMessage(message, sender, _) {
Expand Down Expand Up @@ -110,7 +110,7 @@ function _showNotificationIfNoPopup(message) {

function processMessageAndCatch(message, sender, sendResponse) {
try {
return _processMessage(message, sender, sendResponse).catch(error => {
return _processMessage(message, sender, sendResponse).catch((error) => {
_showNotificationIfNoPopup(error.message);
throw error;
});
Expand Down Expand Up @@ -163,7 +163,7 @@ function _openAuthRequestPopup(popupUrl, resolutionCallback) {
top: 280,
type: 'popup',
})
.then(popupWindow => {
.then((popupWindow) => {
console.log('Opened popup for auth request', popupWindow);

function onPopupClose(windowId) {
Expand All @@ -179,7 +179,7 @@ function _openAuthRequestPopup(popupUrl, resolutionCallback) {
}

function _tryToResolveCurrentAuthRequest(entry, senderUrl) {
return sendNativeAppMessage({ type: 'getLogin', entry: entry }).then(response => {
return sendNativeAppMessage({ type: 'getLogin', entry: entry }).then((response) => {
if (response.error) {
throw new Error(response.error);
}
Expand Down
18 changes: 9 additions & 9 deletions web-extension/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ const inputEventNames = ['click', 'focus', 'keypress', 'keydown', 'keyup', 'inpu
],
ignorePasswordIds = ['signup_minireg_password'],
loginInputTypes = ['email', 'text'],
loginInputTypesString = loginInputTypes.map(string => `input[type=${string}]`).join(',') + ',input:not([type])';
loginInputTypesString = loginInputTypes.map((string) => `input[type=${string}]`).join(',') + ',input:not([type])';

function exactMatch(property, string) {
const idstr = `[${property}=${string}]`;
return loginInputTypes.map(string => `input[type=${string}]${idstr}`).join(',') + `,input:not([type])${idstr}`;
return loginInputTypes.map((string) => `input[type=${string}]${idstr}`).join(',') + `,input:not([type])${idstr}`;
}

function partialMatch(property, string) {
const idstr = `[${property}*=${string}]`;
return (
loginInputTypes
.map(function(string) {
.map(function (string) {
return `input[type=${string}]${idstr}`;
})
.join(',') +
Expand Down Expand Up @@ -66,7 +66,7 @@ function selectFocusedElement(parent) {
parent.activeElement.tagName === 'FRAME'
) {
let focusedElement = null;
parent.querySelectorAll('iframe,frame').forEach(iframe => {
parent.querySelectorAll('iframe,frame').forEach((iframe) => {
if (iframe.src.startsWith(window.location.origin)) {
const focused = selectFocusedElement(iframe.contentWindow.document);
if (focused) {
Expand All @@ -83,15 +83,15 @@ function selectFocusedElement(parent) {
function selectVisibleElements(selector) {
const visibleElements = [];

document.querySelectorAll(selector).forEach(element => {
document.querySelectorAll(selector).forEach((element) => {
if (isVisible(element)) {
visibleElements.push(element);
}
});

document.querySelectorAll('iframe,frame').forEach(iframe => {
document.querySelectorAll('iframe,frame').forEach((iframe) => {
if (iframe.src.startsWith(window.location.origin)) {
iframe.contentWindow.document.body.querySelectorAll(selector).forEach(element => {
iframe.contentWindow.document.body.querySelectorAll(selector).forEach((element) => {
if (isVisible(element)) {
visibleElements.push(element);
}
Expand All @@ -105,7 +105,7 @@ function selectVisibleElements(selector) {
function selectFirstVisiblePasswordElement(selector) {
for (let element of selectVisibleElements(selector)) {
if (
ignorePasswordIds.every(ignore => {
ignorePasswordIds.every((ignore) => {
return element.id !== ignore;
})
) {
Expand Down Expand Up @@ -133,7 +133,7 @@ function updateElement(element, newValue) {
element.setAttribute('value', newValue);
element.value = newValue;

inputEventNames.forEach(name => {
inputEventNames.forEach((name) => {
element.dispatchEvent(new Event(name, { bubbles: true }));
// Some sites clear the fields on certain events, refill to make sure that values are in the field are set
element.setAttribute('value', newValue);
Expand Down
2 changes: 1 addition & 1 deletion web-extension/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function initCreate() {

function onDoCreate(event) {
event.preventDefault();
return getSettings().then(settings => {
return getSettings().then((settings) => {
let name = document.getElementById('create_name').value;
if (settings['appendlogintoname']) {
name = name + '/' + document.getElementById('create_login').value;
Expand Down
Loading

0 comments on commit 1c744e3

Please sign in to comment.