Skip to content

Commit

Permalink
other: Fix local launch
Browse files Browse the repository at this point in the history
  • Loading branch information
olexandr-mazepa committed Jul 27, 2023
1 parent 1d695d8 commit c8c1bb7
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 44 deletions.
22 changes: 12 additions & 10 deletions integration_tests/configs/globalSetup.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
// const { setup: setupDevServer } = require('jest-dev-server');
const { setup: setupDevServer } = require('jest-dev-server');
const setup = require('jest-environment-puppeteer/setup');
// const fs = require('fs');
// const path = require('path');
const fs = require('fs');
const path = require('path');

module.exports = async function globalSetup(globalConfig) {
// fs.copyFileSync(path.join(__dirname, '../../dist/mailgun.web.js'), path.join(__dirname, '../server/dist/mailgun.web.js'));
if (process.env.CI !== true) { // local machine
fs.copyFileSync(path.join(__dirname, '../../dist/mailgun.web.js'), path.join(__dirname, '../server/dist/mailgun.web.js'));

// // set up a web server to server pages
// globalThis.servers = await setupDevServer({
// command: 'http-server ./integration_tests/server -p 3000', // this goes to background
// launchTimeout: 20000,
// port: 3000
// });
// set up a web server to server pages
globalThis.servers = await setupDevServer({
command: 'http-server ./integration_tests/server -p 3000', // this goes to background
launchTimeout: 20000,
port: 3000
});
}

await setup(globalConfig);
console.log('globalSetup.js was invoked');
Expand Down
5 changes: 4 additions & 1 deletion integration_tests/configs/globalTeardown.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ const teardownPuppeteer = require('jest-environment-puppeteer/teardown');

module.exports = async function globalTeardown(globalConfig) {
// shut down the testing http server.
// await teardownDevServer(globalThis.servers);
if (process.env.CI !== true) { // local machine
await teardownDevServer(globalThis.servers);
}

await teardownPuppeteer(globalConfig);
console.log('globalTeardown.js was invoked');
};
9 changes: 8 additions & 1 deletion integration_tests/configs/setupMailgunClient.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* global page, beforeAll, afterAll */
/* eslint-disable no-console */
/* global page, beforeAll */
const { default: mockServer } = require('pptr-mock-server');
const BrowserClient = require('../helpers/BrowserClient');
const NodeClient = require('../helpers/NodeClient');
Expand All @@ -7,6 +8,12 @@ const launchType = process.env.LAUNCH_TYPE;
beforeAll(async function () {
global.MailgunClient = null;
if (typeof page !== 'undefined') { // browser environment
// add page listeners
page.on('console', (message) => console.debug(`Browser console -> ${message.type()} ${message.text()}`))
.on('pageerror', ({ message }) => console.error(`Browser page error -> ${message}`))
.on('response', (response) => console.log(`Browser got response -> ${response.status()} ${response.url()}`))
.on('requestfailed', (request) => console.log(`Browser request failed ->${request.failure().errorText} ${request.url()}`));

global.server_url = 'http://localhost:3000';
const mockRequest = await mockServer.init(page, {
// By default all requests matching baseAppUrl are continued.
Expand Down
11 changes: 0 additions & 11 deletions integration_tests/helpers/BrowserClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,10 @@ class BrowserClient {
if (this.client) {
return this.client;
}
page.on('console', (message) =>
console.log(`${message.type()} ${message.text()}`))
.on('pageerror', ({ message }) => console.log(message))
.on('response', (response) =>
console.log(`${response.status()} ${response.url()}`))
.on('requestfailed', (request) =>
console.log(`${request.failure().errorText} ${request.url()}`));

console.debug('start');
await page.goto(`${global.server_url}/pages/AMD.html`);
console.debug('page loaded');
await page.waitForFunction(function () { return typeof window.mailgunClient !== 'undefined'; });
console.debug('mailgunClient found');
client = await page.evaluate(() => window.mailgunClient);
console.debug('mailgunClient found');
this.client = client;
}
return this.client;
Expand Down
63 changes: 42 additions & 21 deletions integration_tests/server/dist/mailgun.web.js

Large diffs are not rendered by default.

0 comments on commit c8c1bb7

Please sign in to comment.