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

[APM] Migrate traces tests to deployment agnostic #200561

Merged
merged 7 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export const schema = Joi.object()

updateBaselines: Joi.boolean().default(false),
updateSnapshots: Joi.boolean().default(false),
deploymentAgnosticSnapshots: Joi.boolean().default(false),
browser: Joi.object()
.keys({
type: Joi.string().valid('chrome', 'firefox', 'msedge').default('chrome'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ export const loadTests = ({
updateBaselines,
};

decorateSnapshotUi({ lifecycle, updateSnapshots, isCi: !!process.env.CI });
decorateSnapshotUi({
lifecycle,
updateSnapshots,
isCi: !!process.env.CI,
deploymentAgnostic: config.get('deploymentAgnosticSnapshots'),
});

function loadTestFile(path: string) {
if (typeof path !== 'string' || !isAbsolute(path)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ const globalState: {
registered: boolean;
currentTest: Test | null;
snapshotStates: Record<string, ISnapshotState>;
deploymentAgnostic: boolean;
} = {
updateSnapshot: 'none',
registered: false,
currentTest: null,
snapshotStates: {},
deploymentAgnostic: false,
};

const modifyStackTracePrepareOnce = once(() => {
Expand Down Expand Up @@ -66,10 +68,12 @@ export function decorateSnapshotUi({
lifecycle,
updateSnapshots,
isCi,
deploymentAgnostic = false,
}: {
lifecycle: Lifecycle;
updateSnapshots: boolean;
isCi: boolean;
deploymentAgnostic?: boolean;
}) {
let rootSuite: Suite | undefined;

Expand All @@ -82,6 +86,7 @@ export function decorateSnapshotUi({
globalState.registered = true;
globalState.snapshotStates = {};
globalState.currentTest = null;
globalState.deploymentAgnostic = deploymentAgnostic;

if (isCi) {
// make sure snapshots that have not been committed
Expand Down Expand Up @@ -125,7 +130,9 @@ export function decorateSnapshotUi({
const snapshotState = globalState.snapshotStates[file];

if (snapshotState && !test.isPassed()) {
snapshotState.markSnapshotsAsCheckedForTest(test.fullTitle());
snapshotState.markSnapshotsAsCheckedForTest(
getTestTitle(test, globalState.deploymentAgnostic)
);
}
});

Expand Down Expand Up @@ -194,7 +201,7 @@ export function expectSnapshot(received: any) {

const context: SnapshotContext = {
snapshotState,
currentTestName: test.fullTitle(),
currentTestName: getTestTitle(test, globalState.deploymentAgnostic),
};

return {
Expand All @@ -204,6 +211,13 @@ export function expectSnapshot(received: any) {
};
}

function getTestTitle(test: Test, deploymentAgnostic: boolean = false) {
if (deploymentAgnostic) {
return ['Deployment-agnostic', ...test.titlePath().splice(1)].join(' ');
}
return test.fullTitle();
}

function expectToMatchSnapshot(snapshotContext: SnapshotContext, received: any) {
const matcher = toMatchSnapshot.bind(snapshotContext as any);
const result = matcher(received) as SyncExpectationResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default function apmApiIntegrationTests({
loadTestFile(require.resolve('./service_groups'));
loadTestFile(require.resolve('./diagnostics'));
loadTestFile(require.resolve('./service_nodes'));
loadTestFile(require.resolve('./traces'));
loadTestFile(require.resolve('./span_links'));
});
}
Loading