Skip to content

Commit

Permalink
fix(fjagejs): improving test robustness; testing on different browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
notthetup committed Jan 22, 2024
1 parent 0984049 commit cde0dd9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions gateways/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
],
"scripts": {
"build": "npx rimraf -rf dist/ && eslint src/*.js && rollup --silent -c rollup.config.js",
"pretest": "node test/spec/create-spec.cjs",
"test": "npx playwright install --with-deps && node test/run-tests.cjs",
"pretest": "npx playwright install-deps && node test/spec/create-spec.cjs",
"test": "node test/run-tests.cjs",
"docs": "documentation build src/fjage.js -f html --github --document-exported -o ../../docs/jsdoc",
"clean": "npx rimraf -rf dist/"
},
Expand Down
12 changes: 10 additions & 2 deletions gateways/js/test/run-tests.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const statik = require('node-static');
const Jasmine = require('jasmine');
const process = require('process');
const { chromium } = require('playwright');
const { chromium, webkit, firefox} = require('playwright');

const ip = 'localhost';
const port = 8000;
Expand All @@ -30,7 +30,15 @@ let server = require('http').createServer(function (request, response) {
// Execute Browser(MJS) test using puppteer
console.log('Launching playright..');
startTime = new Date();
const browser = await chromium.launch();
let browser = null;
// on MacOS use webkit instead of chromium
if (process.platform === 'darwin') {
browser = await webkit.launch();
} else if (process.platform === 'win32') {
browser = await chromium.launch();
} else {
browser = await firefox.launch();
}
const context = await browser.newContext();
const page = await context.newPage();
page.on('console', msg => {
Expand Down
12 changes: 7 additions & 5 deletions gateways/js/test/spec/fjage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe('A Gateway', function () {

it('should have a successfully opened the underlying connector', async function () {
const gw = new Gateway(gwOpts);
await delay(500);
await delay(700);
expect([1, 'open']).toContain(gw.connector.sock.readyState);
gw.close();
});
Expand Down Expand Up @@ -249,22 +249,23 @@ describe('A Gateway', function () {
console.warn('Error getting SendMsgRsp #'+type+' : ' + m);
}
}
expect(rxed).not.toContain(false);
expect(rxed.filter(r => !r).length).toBe(0)
});

it('should generate trigger connListener when the underlying transport is disconnected/reconnected', async function() {
const gw = new Gateway(gwOpts);
let spy = jasmine.createSpy('connListener');
gw.addConnListener(spy);
await delay(300);
spy.calls.reset();
gw.connector._reconnectTime = 300;
await delay(700);
expect([1, 'open']).toContain(gw.connector.sock.readyState);
spy.calls.reset();
if (isBrowser) gw.connector.sock.close();
else gw.connector.sock.destroy();
await delay(100);
expect(spy).toHaveBeenCalledWith(false);
spy.calls.reset();
await delay(500);
await delay(1000);
expect(spy).toHaveBeenCalledWith(true);
gw.connector._reconnectTime = 5000;
});
Expand Down Expand Up @@ -754,6 +755,7 @@ const autoReporter = {
}
if (params && params.get('send') == 'false') return;
}
// console.log("Jasmine Result : ", result);
await sendTestStatus(result.overallStatus == 'passed', trace, testType);
await delay(500);
}
Expand Down

0 comments on commit cde0dd9

Please sign in to comment.