Skip to content

Commit

Permalink
Deployment agnostic snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
crespocarlos committed Nov 19, 2024
1 parent a5df223 commit 86d2221
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 5 deletions.
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export function createServerlessTestConfig<T extends DeploymentAgnosticCommonSer
// services can be customized, but must extend DeploymentAgnosticCommonServices
...(options.services || services),
},
deploymentAgnosticSnapshots: true,
dockerServers: defineDockerServersConfig({
registry: {
enabled: !!dockerRegistryPort,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export function createStatefulTestConfig<T extends DeploymentAgnosticCommonServi
path.resolve(REPO_ROOT, STATEFUL_ROLES_ROOT_PATH, 'roles.yml'),
],
},

deploymentAgnosticSnapshots: true,
kbnTestServer: {
...xPackAPITestsConfig.get('kbnTestServer'),
serverArgs: [
Expand Down

0 comments on commit 86d2221

Please sign in to comment.