Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/e2e testing promise optimisation #470

Open
wants to merge 21 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/pr_ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
xcode_version: [ '15.4.0' ]
platform: [iOS, tvOS]
platform: [iOS]
runs-on: macos-latest
name: Build for ${{ matrix.platform }} using XCode version ${{ matrix.xcode_version }}
steps:
Expand Down Expand Up @@ -63,12 +63,13 @@ jobs:
with:
model: ${{ matrix.platform == 'iOS' && 'iPhone 15' || 'Apple TV' }}
os: ${{ matrix.platform }}
os_version: '>=14.0'
os_version: '<17.4'

- name: Run e2e tests
working-directory: e2e
run: npm run test:e2e:${{ matrix.platform == 'iOS' && 'ios' || 'tvos' }}

- name: Summarize results
working-directory: e2e
if: always()
run: cat cavy_results.md >> $GITHUB_STEP_SUMMARY
40 changes: 35 additions & 5 deletions e2e/patches/cavy+4.0.2.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/node_modules/cavy/src/Reporter.js b/node_modules/cavy/src/Reporter.js
index 1cdeb38..f7e9e35 100644
index 1cdeb38..24ae1f7 100644
--- a/node_modules/cavy/src/Reporter.js
+++ b/node_modules/cavy/src/Reporter.js
@@ -9,7 +9,15 @@ export default class Reporter {
@@ -9,7 +9,31 @@ export default class Reporter {
// Internal: Creates a websocket connection to the cavy-cli server.
onStart() {
const url = 'ws://127.0.0.1:8082/';
Expand All @@ -14,11 +14,41 @@ index 1cdeb38..f7e9e35 100644
+ }
+ this.ws.onclose = () => {
+ console.debug('Closing websocket');
+ }
+
+ this.overrideConsole('log');
+ this.overrideConsole('debug');
+ this.overrideConsole('warn');
+ }
+
+ overrideConsole(fn) {
+ const original = console[fn];
+ console[fn] = (...args) => {
+ const timestamp = new Date().toISOString();
+ original(`[${timestamp}]`, ...args);
+ this.sendMessage({
+ "message": `${fn.toUpperCase()} ${new Date().toLocaleTimeString()} ${args.join(' ')}`,
+ "level": fn
+ });
+ }
}

// Internal: Send a single test result to cavy-cli over the websocket connection.
@@ -34,7 +42,6 @@ export default class Reporter {
@@ -20,6 +44,13 @@ export default class Reporter {
}
}

+ sendMessage(data) {
+ if (this.websocketReady()) {
+ testData = { event: 'message', data };
+ this.sendData(testData);
+ }
+ }
+
// Internal: Send report to cavy-cli over the websocket connection.
onFinish(report) {
if (this.websocketReady()) {
@@ -34,7 +65,6 @@ export default class Reporter {
console.log(message);
}
}
Expand All @@ -27,13 +57,13 @@ index 1cdeb38..f7e9e35 100644
websocketReady() {
// WebSocket.readyState 1 means the web socket connection is OPEN.
diff --git a/node_modules/cavy/src/TestRunner.js b/node_modules/cavy/src/TestRunner.js
index 40552bf..5b98f72 100644
index 40552bf..0af9639 100644
--- a/node_modules/cavy/src/TestRunner.js
+++ b/node_modules/cavy/src/TestRunner.js
@@ -148,7 +148,7 @@ export default class TestRunner {
const stop = new Date();
const time = (stop - start) / 1000;

- let fullErrorMessage = `${description} ❌\n ${e.message}`;
+ let fullErrorMessage = `${description} ❌\n ${JSON.stringify(e)}`;
console.warn(fullErrorMessage);
Expand Down
32 changes: 29 additions & 3 deletions e2e/patches/cavy-cli+3.0.0.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/node_modules/cavy-cli/server.js b/node_modules/cavy-cli/server.js
index 64faf22..b453ebb 100644
index 64faf22..633013b 100644
--- a/node_modules/cavy-cli/server.js
+++ b/node_modules/cavy-cli/server.js
@@ -2,6 +2,7 @@ const http = require('http');
Expand All @@ -10,15 +10,41 @@ index 64faf22..b453ebb 100644

// Initialize a server
const server = http.createServer();
@@ -80,6 +81,7 @@ function finishTesting(reportJson) {
@@ -24,6 +25,9 @@ wss.on('connection', socket => {
const json = JSON.parse(message);

switch(json.event) {
+ case 'message':
+ logMessage(json.data);
+ break;
case 'singleResult':
logTestResult(json.data);
break;
@@ -62,6 +66,15 @@ function logTestResult(testResultJson) {
}
};

+function logMessage(json) {
+ const { message, level } = json;
+ switch (level) {
+ case 'log': console.log(chalk.white(message)); break;
+ case 'debug': console.log(chalk.yellow(message)); break;
+ case 'warn': console.log(chalk.bgYellow(message)); break;
+ }
+}
+
// Internal: Accepts a json report object, console.logs the overall result of
// the test suite and quits the process with either exit code 1 or 0 depending
// on whether any tests failed.
@@ -80,6 +93,7 @@ function finishTesting(reportJson) {
if (server.locals.outputAsXml) {
constructXML(fullResults);
}
+ constructMarkdown(fullResults);

// If all tests pass, exit with code 0, else code 42.
// Code 42 chosen at random so that a test failure can be distinuguished from
@@ -98,4 +100,16 @@ function finishTesting(reportJson) {
@@ -98,4 +112,16 @@ function finishTesting(reportJson) {
console.log('--------------------');
};

Expand Down
7 changes: 7 additions & 0 deletions e2e/src/components/TestableTHEOplayerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { THEOplayer, THEOplayerView, THEOplayerViewProps } from 'react-native-th
import React, { useCallback } from 'react';

let testPlayer: THEOplayer | undefined = undefined;
let testPlayerId: number = 0;

/**
* Wait until the player is ready.
Expand All @@ -17,12 +18,15 @@ export const getTestPlayer = async (timeout = 5000, poll = 200): Promise<THEOpla
setTimeout(() => {
if (testPlayer) {
// Player is ready.
console.debug(`[checkPlayer] Success: player ${testPlayerId} ready.`);
resolve(testPlayer);
} else if (Date.now() - start > timeout) {
// Too late.
console.debug(`[checkPlayer] Failed: timeout reached for ${testPlayerId}.`);
reject('Player not ready');
} else {
// Wait & try again.
console.debug(`[checkPlayer] Player ${testPlayerId} not ready yet. Retrying...`);
checkPlayer();
}
}, poll);
Expand All @@ -34,11 +38,14 @@ export const getTestPlayer = async (timeout = 5000, poll = 200): Promise<THEOpla
export const TestableTHEOplayerView = (props: THEOplayerViewProps) => {
const generateTestHook = useCavy();
const onPlayerReady = useCallback((player: THEOplayer) => {
testPlayerId++;
testPlayer = player;
console.debug(`[onPlayerReady] id: ${testPlayerId}`);
props.onPlayerReady?.(player);
}, []);

const onPlayerDestroy = useCallback(() => {
console.debug(`[onPlayerDestroy] id: ${testPlayerId}`);
testPlayer = undefined;
}, []);

Expand Down
2 changes: 1 addition & 1 deletion e2e/src/res/ads.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"integration": "google-ima",
"sources": "https://cdn.theoplayer.com/demos/ads/vast/dfp-preroll-no-skip.xml"
"sources": "https://pubads.g.doubleclick.net/gampad/ads?iu=/21775744923/external/single_ad_samples&sz=640x480&cust_params=sample_ct%3Dlinear&ciu_szs=300x250%2C728x90&gdfp_req=1&output=vast&unviewed_position_start=1&env=vp&impl=s&correlator="
}
]
8 changes: 7 additions & 1 deletion e2e/src/tests/Ads.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TestScope } from 'cavy';
import { AdEventType, PlayerEventType, AdEvent } from 'react-native-theoplayer';
import { AdEvent, AdEventType, PlayerEventType } from 'react-native-theoplayer';
import { getTestPlayer } from '../components/TestableTHEOplayerView';
import { waitForPlayerEvents, waitForPlayerEventTypes } from '../utils/Actions';
import { TestSourceDescription, TestSources } from '../utils/SourceUtils';
Expand All @@ -14,10 +14,16 @@ export default function (spec: TestScope) {
const playEventsPromise = waitForPlayerEventTypes(player, [PlayerEventType.SOURCE_CHANGE, PlayerEventType.PLAY, PlayerEventType.PLAYING]);

const adEventsPromise = waitForPlayerEvents(player, [
{ type: PlayerEventType.AD_EVENT, subType: AdEventType.AD_LOADED } as AdEvent,
{ type: PlayerEventType.AD_EVENT, subType: AdEventType.AD_BREAK_BEGIN } as AdEvent,
{ type: PlayerEventType.AD_EVENT, subType: AdEventType.AD_BEGIN } as AdEvent,
]);

// TEMP
player.addEventListener(Object.values(PlayerEventType), (e) => {
console.log(`[PlayerEvent] received: ${JSON.stringify(e, null, 4)}`);
});

// Start autoplay
player.autoplay = true;
player.source = testSource.source;
Expand Down
Loading
Loading