Skip to content

Commit

Permalink
Merge pull request #153 from pusher/update-dependencies
Browse files Browse the repository at this point in the history
Update Dependencies and Modernise Codebase
  • Loading branch information
hnhv authored Jan 3, 2025
2 parents 13c861e + 88a8205 commit e6a70d7
Show file tree
Hide file tree
Showing 22 changed files with 7,794 additions and 19,631 deletions.
30 changes: 0 additions & 30 deletions .eslintrc.json

This file was deleted.

4 changes: 3 additions & 1 deletion .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14'
node-version: '22'
- uses: nanasess/setup-chromedriver@master
- name: "Install deps"
run: npm install
Expand All @@ -23,6 +23,8 @@ jobs:
run: npm run test:unit
- name: "Run end-to-end tests"
run: |
google-chrome --version
chromedriver --version
export DISPLAY=:99
chromedriver --url-base=/wd/hub &
sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 &
Expand Down
5 changes: 3 additions & 2 deletions end-to-end-tests/sdk-get-registration-state.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
NOTIFICATIONS_DEFAULT,
NOTIFICATIONS_GRANTED,
NOTIFICATIONS_DENIED,
unregisterServiceWorker
unregisterServiceWorker,
SCRIPT_TIMEOUT_MS
} from './test-utils';
import * as PusherPushNotifications from '../src/push-notifications';

Expand Down Expand Up @@ -39,7 +40,7 @@ test('.getState should return PERMISSION_GRANTED_REGISTERED_WITH_BEAMS if start
});

expect(state).toBe(PusherPushNotifications.RegistrationState.PERMISSION_GRANTED_REGISTERED_WITH_BEAMS);
});
}, SCRIPT_TIMEOUT_MS);

test('.getState should return PERMISSION_PROMPT_REQUIRED if start has not been called and permissions are default', async () => {
await prepareServer(NOTIFICATIONS_DEFAULT)
Expand Down
81 changes: 37 additions & 44 deletions end-to-end-tests/sdk-set-user-id.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,48 @@ import {
launchServer,
createChromeWebDriver,
NOTIFICATIONS_GRANTED,
unregisterServiceWorker
unregisterServiceWorker,
SCRIPT_TIMEOUT_MS
} from './test-utils';

jest.setTimeout(SCRIPT_TIMEOUT_MS);

let killServer = null;
let chromeDriver = null;

beforeAll(() => {
return launchServer()
.then(killFunc => {
killServer = killFunc;
})
.then(() => createChromeWebDriver(NOTIFICATIONS_GRANTED))
.then(driver => {
chromeDriver = driver;
})
.then(async () => {
const errolClient = new ErrolTestClient(
'1b880590-6301-4bb5-b34f-45db1c5f5644'
);
const response = await errolClient.deleteUser('cucas');
expect(response.statusCode).toBe(200);
});
beforeAll(async () => {
killServer = await launchServer();
chromeDriver = await createChromeWebDriver(NOTIFICATIONS_GRANTED);
const errolClient = new ErrolTestClient(
'1b880590-6301-4bb5-b34f-45db1c5f5644'
);
const response = await errolClient.deleteUser('cucas');
expect(response.statusCode).toBe(200);
});

beforeEach(() => {
return (async () => {
await chromeDriver.get('http://localhost:3000');
await chromeDriver.wait(() => {
return chromeDriver.getTitle().then(title => title.includes('Test Page'));
}, 2000);

return chromeDriver.executeAsyncScript(() => {
const asyncScriptReturnCallback = arguments[arguments.length - 1];

let deleteDbRequest = window.indexedDB.deleteDatabase(
'beams-1b880590-6301-4bb5-b34f-45db1c5f5644'
);
deleteDbRequest.onsuccess = asyncScriptReturnCallback;
deleteDbRequest.onerror = asyncScriptReturnCallback;
});
beforeEach(async () => {
await chromeDriver.get('http://localhost:3000');

await chromeDriver.wait(async () => {
const title = await chromeDriver.getTitle();
return title.includes('Test Page');
},
2000
);

})();
await chromeDriver.executeAsyncScript(() => {
const callback = arguments[arguments.length - 1];
const req = window.indexedDB.deleteDatabase(
'beams-1b880590-6301-4bb5-b34f-45db1c5f5644'
);
req.onsuccess = callback;
req.onerror = callback;
});
});

afterEach(() => unregisterServiceWorker(chromeDriver));
afterEach(async () => {
await unregisterServiceWorker(chromeDriver);
});

test('SDK should set user id with errol', async () => {
await chromeDriver.get('http://localhost:3000');
Expand Down Expand Up @@ -81,8 +78,8 @@ test('SDK should set user id with errol', async () => {
if (userId !== 'cucas') {
throw new Error(
'Unexpected user ID ' +
userId +
', this token provider is hardcoded to "cucas"'
userId +
', this token provider is hardcoded to "cucas"'
);
} else {
return {
Expand Down Expand Up @@ -272,11 +269,7 @@ test('SDK should return an error if user ID is not a string', async () => {
expect(setUserIdError).toBe('User ID must be a string (was undefined)');
});

afterAll(() => {
if (killServer) {
killServer();
}
if (chromeDriver) {
chromeDriver.quit();
}
afterAll(async () => {
if (killServer) killServer();
if (chromeDriver) await chromeDriver.quit();
});
18 changes: 12 additions & 6 deletions end-to-end-tests/sdk-start.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {
launchServer,
createChromeWebDriver,
NOTIFICATIONS_GRANTED,
unregisterServiceWorker
unregisterServiceWorker,
SCRIPT_TIMEOUT_MS
} from './test-utils';

let killServer = null;
Expand All @@ -24,23 +25,28 @@ afterEach(() => unregisterServiceWorker(chromeDriver));
test('SDK should register a device with errol', async () => {
await chromeDriver.get('http://localhost:3000');
await chromeDriver.wait(() => {
return chromeDriver.getTitle().then(title => title.includes('Test Page'));
return chromeDriver.getTitle().then(title => {
return title.includes('Test Page');
});
}, 2000);

const initialDeviceId = await chromeDriver.executeAsyncScript(() => {
const asyncScriptReturnCallback = arguments[arguments.length - 1];

const instanceId = 'deadc0de-2ce6-46e3-ad9a-5c02d0ab119b';
const beamsClient = new PusherPushNotifications.Client({ instanceId });
beamsClient
.start()
.then(() => beamsClient.getDeviceId())
.then(deviceId => asyncScriptReturnCallback(deviceId))
.catch(e => asyncScriptReturnCallback(e.message));
.then(deviceId => {
asyncScriptReturnCallback(deviceId);
})
.catch(e => {
asyncScriptReturnCallback(e.message);
});
});

expect(initialDeviceId).toContain('web-');
});
}, SCRIPT_TIMEOUT_MS);

test('SDK should remember the device ID', async () => {
await chromeDriver.get('http://localhost:3000');
Expand Down
5 changes: 3 additions & 2 deletions end-to-end-tests/sdk-stop.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
launchServer,
createChromeWebDriver,
NOTIFICATIONS_GRANTED,
unregisterServiceWorker
unregisterServiceWorker,
SCRIPT_TIMEOUT_MS
} from './test-utils';

let killServer = null;
Expand Down Expand Up @@ -104,7 +105,7 @@ test('Calling .stop should clear SDK state', async () => {
// Assert that the device no longer exists on the server
const response = await errolClient.getWebDevice(deviceIdBeforeStop);
expect(response.statusCode).toBe(404);
});
}, SCRIPT_TIMEOUT_MS);

test('Calling .stop before .start should do nothing', async () => {
const errolClient = new ErrolTestClient(
Expand Down
6 changes: 1 addition & 5 deletions end-to-end-tests/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const path = require('path');
const chrome = require('selenium-webdriver/chrome');
const { Builder } = require('selenium-webdriver');

const SCRIPT_TIMEOUT_MS = 60000;
export const SCRIPT_TIMEOUT_MS = 60000;

const MAX_TEST_SERVER_CHECKS = 10;
const TEST_SERVER_CHECK_SLEEP_MS = 200;
Expand All @@ -23,10 +23,6 @@ export const NOTIFICATIONS_DEFAULT = 0
export const NOTIFICATIONS_GRANTED = 1
export const NOTIFICATIONS_DENIED = 2

beforeAll(() => {
jest.setTimeout(SCRIPT_TIMEOUT_MS);
});

/**
* Helper for launching a test application server
* @async
Expand Down
41 changes: 41 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import globals from "globals";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});

export default [...compat.extends("eslint:recommended", "prettier"), {
languageOptions: {
globals: {
...globals.browser,
...globals.jest,
...globals.node,
...globals.serviceworker,
},

ecmaVersion: 2018,
sourceType: "module",
},

rules: {
"no-unused-vars": ["error", {
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
}],

"no-console": 0,
indent: ["error", 2],
quotes: [2, "single"],
"linebreak-style": [2, "unix"],
semi: [2, "always"],
},
}];
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
automock: false,
setupFiles: ['./test-setup.js'],
testEnvironment: 'jsdom'
};
Loading

0 comments on commit e6a70d7

Please sign in to comment.