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

[8.17] [APM] Migrate traces tests to deployment agnostic (#200561) #203475

Merged
merged 3 commits into from
Dec 11, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ export const loadTests = ({
updateBaselines,
};

decorateSnapshotUi({ lifecycle, updateSnapshots, isCi: !!process.env.CI });
decorateSnapshotUi({
lifecycle,
updateSnapshots,
isCi: !!process.env.CI,
});

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 @@ -125,7 +127,7 @@ export function decorateSnapshotUi({
const snapshotState = globalState.snapshotStates[file];

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

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

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

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

function getTestTitle(test: Test) {
return (
test
.fullTitle()
// remove deployment type from test title so that a single snapshot can be used for all deployment types
.replace(
/^(Serverless|Stateful)\s+([^\-]+)\s*-?\s*Deployment-agnostic/g,
'Deployment-agnostic'
)
);
}

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 @@ -40,6 +40,7 @@ export default function apmApiIntegrationTests({
loadTestFile(require.resolve('./suggestions'));
loadTestFile(require.resolve('./throughput'));
loadTestFile(require.resolve('./time_range_metadata'));
loadTestFile(require.resolve('./traces'));
loadTestFile(require.resolve('./transactions'));
});
}
Loading
Loading