Skip to content

Commit

Permalink
Update dev dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
Pharb committed Mar 10, 2024
1 parent 1af409a commit 189c97a
Show file tree
Hide file tree
Showing 8 changed files with 3,069 additions and 3,861 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node-version: [12.x, 14.x, 16.x]
node-version: [18.x, 20.x]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

Expand All @@ -28,7 +28,7 @@ jobs:
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v2
- uses: actions/cache@v4
# Docs: https://github.com/actions/cache/blob/master/examples.md#node---yarn
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
Expand All @@ -49,6 +49,6 @@ jobs:

- name: Upload coverage to Codecov
# Docs: https://github.com/marketplace/actions/codecov
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true
27 changes: 12 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"description": "Gopass Bridge allows searching and inserting login credentials from the gopass password manager",
"main": "web-extension/gopassbridge.js",
"scripts": {
"test": "npm-run-all test:*",
"test": "npm run test:lint && npm run test:jest",
"test:lint": "npm run lint",
"test:jest": "jest",
"lint": "npm-run-all lint:*",
"lint": "npm run lint:eslint && npm run lint:webext && npm run lint:prettier",
"lint:eslint": "eslint --ext=.js,.json web-extension manifests tests",
"lint:webext": "web-ext -s firefox-release lint",
"lint:prettier": "prettier --end-of-line auto --check \"**/*\"",
Expand All @@ -30,19 +30,16 @@
"homepage": "https://github.com/gopasspw/gopassbridge#readme",
"dependencies": {},
"devDependencies": {
"codecov": "^3.6.5",
"eslint": "^8.9.0",
"eslint-plugin-json": "^2.1.2",
"eslint-plugin-mocha": "^6.3.0",
"eslint-plugin-promise": "^4.3.1",
"global": "^4.3.2",
"jest": "^24.5.1",
"jest-environment-jsdom": "^24.8.0",
"jest-environment-jsdom-global": "^3.0.0",
"eslint": "^8.57.0",
"eslint-plugin-json": "^3.1.0",
"eslint-plugin-mocha": "^10.4.1",
"eslint-plugin-promise": "^6.1.1",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-environment-jsdom-global": "^4.0.0",
"jest-plugin-unhandled-promise": "^2.9.0",
"jest-webextension-mock": "^3.3.0",
"npm-run-all": "^4.1.2",
"prettier": "^2.5.1",
"web-ext": "^6.7.0"
"jest-webextension-mock": "^3.8.9",
"prettier": "^3.2.5",
"web-ext": "^7.11.0"
}
}
14 changes: 8 additions & 6 deletions tests/unit/background.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ describe('background', () => {
global.i18n.getMessage.mockClear();
global.browser.tabs.sendMessage.mockClear();
global.executeOnSetting.mockClear();

jest.spyOn(global.console, 'warn');
});

afterEach(() => {
global.console.warn.mockReset();
});

test('registers message processors on init', () => {
Expand Down Expand Up @@ -299,8 +305,6 @@ describe('background', () => {
test('opens auth popup but does not resolve auth request after URL mismatch', () => {
expect.assertions(6);

spyOn(global.console, 'warn');

const authRequiredPromise = onAuthRequiredCallback({ url: authUrl });

return windowCreatePromise.then(() => {
Expand All @@ -315,7 +319,7 @@ describe('background', () => {
expect(browser.windows.onRemoved.removeListener.mock.calls.length).toBe(0); // popup still open
expect(global.sendNativeAppMessage.mock.calls.length).toBe(1);
expect(global.showNotificationOnSetting.mock.calls.length).toEqual(0);
expect(global.console.warn.calls.allArgs()).toEqual([
expect(global.console.warn.mock.calls).toEqual([
[
'Could not resolve auth request due to URL mismatch',
validAuthPopupUrl,
Expand Down Expand Up @@ -382,8 +386,6 @@ describe('background', () => {
test('does not resolve auth request when no request is pending', () => {
expect.assertions(6);

spyOn(global.console, 'warn');

const url = validAuthPopupUrl;
const processMessagePromise = background.processMessageAndCatch(
{ type: 'LOGIN_TAB', entry: 'some/entry' },
Expand All @@ -396,7 +398,7 @@ describe('background', () => {
expect(browser.windows.onRemoved.removeListener.mock.calls.length).toBe(0);
expect(global.sendNativeAppMessage.mock.calls).toEqual([[{ type: 'getLogin', entry: 'some/entry' }]]);
expect(global.showNotificationOnSetting.mock.calls.length).toEqual(0);
expect(global.console.warn.calls.allArgs()).toEqual([
expect(global.console.warn.mock.calls).toEqual([
['Tried to resolve auth request, but no auth request is currently pending.', url],
]);
});
Expand Down
39 changes: 23 additions & 16 deletions tests/unit/content.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@ let widthMockReturn = 50;

global.getSyncStorage = () => null;

Object.defineProperties(global.HTMLElement.prototype, {
offsetHeight: {
get: () => {
return heightMockReturn;
function mockElementSize(htmlElementClass) {
Object.defineProperties(htmlElementClass.prototype, {
offsetHeight: {
get: () => {
return heightMockReturn;
},
},
},
offsetWidth: {
get: () => {
return widthMockReturn;
offsetWidth: {
get: () => {
return widthMockReturn;
},
},
},
});
});
}

mockElementSize(global.HTMLElement);

require('content.js');

Expand Down Expand Up @@ -238,20 +242,23 @@ describe('on sample login form with inputs in iframe', () => {
heightMockReturn = 10;
widthMockReturn = 50;
document.body.innerHTML =
"<html><body><iframe src='https://www.somedomain.com/iframe.html'></iframe></body></html>";
"<html><body><iframe src='https://www.somedomain.test/iframe.html'></iframe></body></html>";
const iframe = document.querySelectorAll('iframe')[0];
iframe.contentWindow.document.write(`
iframe.contentDocument.write(`
<form id='form' action='/session' method='post'>
<input id='login' type='text' class='test-login'>
<input id='login2' type='text' class='another-test-login'>
<input type='password' class='test-password'>
<input id='submit' type='submit'>
</form>`);
</form>
`);

mockElementSize(iframe.contentWindow.HTMLElement);
});

test('selects login and password', () => {
jsdom.reconfigure({
url: 'https://www.somedomain.com/',
url: 'https://www.somedomain.test/',
});
const iframe = document.querySelectorAll('iframe')[0];
content.processMessage({ type: 'MARK_LOGIN_FIELDS' });
Expand All @@ -260,7 +267,7 @@ describe('on sample login form with inputs in iframe', () => {

test('does not select login and password if iframe starts with different url', () => {
jsdom.reconfigure({
url: 'https://www.someotherdomain.com/',
url: 'https://www.someotherdomain.test/',
});
const iframe = document.querySelectorAll('iframe')[0];
content.processMessage({ type: 'MARK_LOGIN_FIELDS' });
Expand All @@ -269,7 +276,7 @@ describe('on sample login form with inputs in iframe', () => {

test('selects second textfield if focused', () => {
jsdom.reconfigure({
url: 'https://www.somedomain.com/',
url: 'https://www.somedomain.test/',
});
const iframe = document.querySelectorAll('iframe')[0];
const second = iframe.contentWindow.document.getElementsByClassName('another-test-login')[0];
Expand Down
9 changes: 2 additions & 7 deletions tests/unit/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ const create = window.tests.create;

describe('create', () => {
afterEach(() => {
global.armSpinnerTimeout.mockReset();
global.sendNativeAppMessage.mockReset();
global.searchHost.mockReset();
global.urlDomain.mockReset();
global.switchToSearch.mockReset();
global.logAndDisplayError.mockReset();
jest.clearAllMocks();
});

test('doAbort switches to search', () => {
Expand Down Expand Up @@ -185,7 +180,7 @@ describe('create', () => {
['create_docreate', 'create_doabort', 'create_generate'].forEach((id) => {
test(`registers eventhandler for ${id}`, () => {
const element = document.getElementById('create_docreate');
spyOn(element, 'addEventListener');
const mock = jest.spyOn(element, 'addEventListener');
create.initCreate();
expect(element.addEventListener).toHaveBeenCalledTimes(1);
});
Expand Down
1 change: 1 addition & 0 deletions tests/unit/popup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const fs = require('fs');
jest.useFakeTimers();
jest.spyOn(global, 'setTimeout');

global.logError = jest.fn();
global.getSettings = jest.fn();
Expand Down
12 changes: 7 additions & 5 deletions tests/unit/search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('search method', () => {
describe('initSearch', () => {
test('focuses input', () => {
const input = document.getElementById('search_input');
spyOn(input, 'focus');
jest.spyOn(input, 'focus');
search.initSearch();
expect(input.focus).toHaveBeenCalledTimes(0);
jest.runAllTimers();
Expand All @@ -73,9 +73,9 @@ describe('search method', () => {

test(`registers eventhandlers for input`, () => {
const input = document.getElementById('search_input');
spyOn(input, 'addEventListener');
jest.spyOn(input, 'addEventListener');
search.initSearch();
expect(input.addEventListener.calls.allArgs()).toEqual([
expect(input.addEventListener.mock.calls).toEqual([
['input', search._onSearchInputEvent],
['keypress', search._onSearchKeypressEvent],
]);
Expand Down Expand Up @@ -176,8 +176,10 @@ describe('search method', () => {

test('sends search message for host', () => {
expect.assertions(1);
return search.searchHost('muh.com').then(() => {
expect(global.sendNativeAppMessage.mock.calls).toEqual([[{ host: 'muh.com', type: 'queryHost' }]]);
return search.searchHost('something.test').then(() => {
expect(global.sendNativeAppMessage.mock.calls).toEqual([
[{ host: 'something.test', type: 'queryHost' }],
]);
});
});

Expand Down
Loading

0 comments on commit 189c97a

Please sign in to comment.