Skip to content

Commit

Permalink
added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
HowardBraham committed Sep 4, 2024
1 parent 969f352 commit 4718657
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 26 deletions.
5 changes: 5 additions & 0 deletions app/scripts/lib/manifestFlags.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* Get the runtime flags that were placed in manifest.json by alterBuiltManifest.ts
*
* @returns flags if they exist, otherwise an empty object
*/
export function getManifestFlags() {
return chrome.runtime.getManifest()._flags || {};
}
10 changes: 10 additions & 0 deletions app/scripts/lib/setupSentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ function getClientOptions() {
};
}

/**
* Compute the tracesSampleRate depending on testing condition.
*
* @param {string} sentryTarget
* @returns tracesSampleRate to setup Sentry
*/
function getTracesSampleRate(sentryTarget) {
if (sentryTarget === SENTRY_DSN_FAKE) {
return 1.0;
Expand All @@ -120,6 +126,10 @@ function getTracesSampleRate(sentryTarget) {
return 0.01;
}

/**
* Get CircleCI tags passed from the test environment, through manifest.json,
* and give them to the Sentry client.
*/
function setCircleCiTags() {
const { circleci } = getManifestFlags();

Expand Down
1 change: 1 addition & 0 deletions app/scripts/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ async function start() {
window.document?.documentElement?.classList.add('controller-loaded');
}

// Add custom measurement to Sentry
Sentry.setMeasurement(
'ui.initialized',
performance.now(),
Expand Down
30 changes: 26 additions & 4 deletions test/e2e/alterBuiltManifest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
/**
* Before this file was created, there was no way to pass runtime flags from an E2E test to the built extension.
* (Well okay, more precisely, you could change certain things through Fixtures, and you could change certain things
* through Ganache parameters, but both of these didn't load until late in the app load. Sentry is one of the first
* things to load, and it needed a way to get runtime flags very early in the app load.)
*
* The way this works is a bit of a hack, but it's the only solution we could come up with that would load early enough:
*
* 1) A global beforeEach hook in the E2E tests backs up the manifest.json file
* 2) The helpers.withFixtures() function calls setManifestFlags(), which reads in the manifest file and parses it
* 3) We alter the manifest with CircleCI environment variables and custom flags, then write it back to manifest.json
* 4) The test runs, and the built extension can call getManifestFlags() to get the custom flags
* 5) A global afterEach hook restores the backup copy of the manifest, so that the next test gets the normal manifest
*/
import fs from 'fs';

const folder = `dist/${process.env.SELENIUM_BROWSER}`;

// Global beforeEach hook to backup the manifest.json file
if (typeof beforeEach === 'function') {
beforeEach(() => {
restoreBackupManifest();
Expand All @@ -12,24 +27,31 @@ if (typeof beforeEach === 'function') {
});
}

// Global afterEach hook to restore the backup manifest
if (typeof afterEach === 'function') {
afterEach(() => {
fs.cpSync(`${folder}/manifest.json`, `${folder}/manifest.altered.json`, {
preserveTimestamps: true,
});

restoreBackupManifest();
});
}

function restoreBackupManifest() {
fs.cpSync(`${folder}/manifest.json`, `${folder}/manifest.altered.json`, {
preserveTimestamps: true,
});

if (fs.existsSync(`${folder}/manifest.backup.json`)) {
fs.cpSync(`${folder}/manifest.backup.json`, `${folder}/manifest.json`, {
preserveTimestamps: true,
});
}
}

/**
* Alter the manifest with CircleCI environment variables and custom flags
*
* @param flags - Custom flags to set
* @param flags.circleci - This will usually come in as undefined, and be set in this function
*/
export function setManifestFlags(flags: { circleci?: object } = {}) {
if (process.env.CIRCLECI) {
flags.circleci = {
Expand Down
43 changes: 21 additions & 22 deletions test/e2e/run-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,34 @@ const getTestPathsForTestDir = async (testDir) => {
};

// Quality Gate Retries
// const RETRIES_FOR_NEW_OR_CHANGED_TESTS = 5;
const RETRIES_FOR_NEW_OR_CHANGED_TESTS = 5;

/**
* Runs the quality gate logic to filter and append changed or new tests if present.
*
* @param {string} fullTestList - List of test paths to be considered.
* @param {string[]} _changedOrNewTests - List of changed or new test paths.
* @param {string[]} changedOrNewTests - List of changed or new test paths.
* @returns {string} The updated full test list.
*/
async function applyQualityGate(fullTestList, _changedOrNewTests) {
return fullTestList;
// let qualityGatedList = fullTestList;

// if (changedOrNewTests.length > 0) {
// // Filter to include only the paths present in fullTestList
// const filteredTests = changedOrNewTests.filter((test) =>
// fullTestList.includes(test),
// );

// // If there are any filtered tests, append them to fullTestList
// if (filteredTests.length > 0) {
// const filteredTestsString = filteredTests.join('\n');
// for (let i = 0; i < RETRIES_FOR_NEW_OR_CHANGED_TESTS; i++) {
// qualityGatedList += `\n${filteredTestsString}`;
// }
// }
// }

// return qualityGatedList;
async function applyQualityGate(fullTestList, changedOrNewTests) {
let qualityGatedList = fullTestList;

if (changedOrNewTests.length > 0) {
// Filter to include only the paths present in fullTestList
const filteredTests = changedOrNewTests.filter((test) =>
fullTestList.includes(test),
);

// If there are any filtered tests, append them to fullTestList
if (filteredTests.length > 0) {
const filteredTestsString = filteredTests.join('\n');
for (let i = 0; i < RETRIES_FOR_NEW_OR_CHANGED_TESTS; i++) {
qualityGatedList += `\n${filteredTestsString}`;
}
}
}

return qualityGatedList;
}

// For running E2Es in parallel in CI
Expand Down

0 comments on commit 4718657

Please sign in to comment.