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

fix(snapshot): define resourceToPreview from resources changed. #1453

Merged
merged 6 commits into from
Mar 14, 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
16 changes: 8 additions & 8 deletions packages/cli-e2e/__tests__/__snapshots__/atomic.specs.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ HashedFolder {
HashedFolder {
"children": [
HashedFile {
"hash": "61GVF7l8bCVXW00H2rtInTKwoqY=",
"hash": "e5DQ3kRU03Vmp2BC+mjlSypQjKE=",
"name": "index.css",
},
],
"hash": "FQZ6fv/Z/8DhwZWuUbrLwgTt6r8=",
"hash": "IMDEBLQ/slaFFRst+lJYHMRm07E=",
"name": "style",
},
HashedFolder {
Expand All @@ -104,15 +104,15 @@ HashedFolder {
"name": "utils",
},
],
"hash": "pBlrdRw5yuMk/S0mFDAUBGrEvMs=",
"hash": "K9gD9O4uCLlQbxYAgmEW6K+5EAw=",
"name": "src",
},
HashedFile {
"hash": "9nyo2P7hCKS4uXz6KBbyR2tzRtY=",
"name": "tsconfig.json",
},
],
"hash": "MX8XJmhwXYKcItyHsBvb0tWTjlM=",
"hash": "TZXkS/G4E85OYZrwyJxf/QI7lJ8=",
"name": "normalizedDir",
}
`;
Expand Down Expand Up @@ -329,11 +329,11 @@ HashedFolder {
HashedFolder {
"children": [
HashedFile {
"hash": "/limo6D9Trxh05AOjVfMeecwXR8=",
"hash": "xbqB+xpmHNlBnQf+PCHR+rT3tfg=",
"name": "index.css",
},
],
"hash": "/ARqEzx1ZY/+YdpH3eOpUbZnjj8=",
"hash": "Z+bQXHQFJdpSE56ncUOv3fWRy6w=",
"name": "style",
},
HashedFolder {
Expand All @@ -347,15 +347,15 @@ HashedFolder {
"name": "utils",
},
],
"hash": "FJTdsvHKymcS4bWGsVDxdv5+xI0=",
"hash": "9IWPASf2gKXfg4rrJ+k4DSwv4c4=",
"name": "src",
},
HashedFile {
"hash": "9nyo2P7hCKS4uXz6KBbyR2tzRtY=",
"name": "tsconfig.json",
},
],
"hash": "fXSss5dlkGuizSP8OXlIF3OvP2Q=",
"hash": "20bLNlmkPR5jmaL2CitCTveWor8=",
"name": "normalizedDir",
}
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {DotFolder} from '../../project/dotFolder';
import {cwd} from 'process';
import {buildResourcesToExport} from '../pullModel/validation/model';
import {startSpinner, stopSpinner} from '@coveo/cli-commons/utils/ux';
import {SnapshotReporter} from '../snapshotReporter';

export class ExpandedPreviewer {
private static readonly previewDirectoryName = 'preview';
Expand All @@ -28,9 +29,8 @@ export class ExpandedPreviewer {
private readonly projectToPreview: Project,
private readonly shouldDelete: boolean
) {
this.resourcesToPreview = Object.keys(
report.resourceOperationResults
) as ResourceSnapshotType[];
const reporter = new SnapshotReporter(report);
this.resourcesToPreview = reporter.getAffectedResourceTypes();
}

private static get previewDirectory() {
Expand Down
24 changes: 24 additions & 0 deletions packages/cli/core/src/lib/snapshot/snapshotReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,30 @@ export class SnapshotReporter {
) > 0;
}

public getAffectedResourceTypes(): ResourceSnapshotType[] {
const isResourceTypeReportAffected = (
report: ResourceSnapshotsReportOperationModel
) => {
for (const operation of Object.values(report)) {
if (operation > 0) {
return true;
}
}
return false;
};
louis-bompart marked this conversation as resolved.
Show resolved Hide resolved
const changedResourcesTypes: ResourceSnapshotType[] = [];
for (const resourceType of Object.keys(this.report.resourceOperations)) {
if (
isResourceTypeReportAffected(
this.report.resourceOperations[resourceType]
)
) {
changedResourcesTypes.push(resourceType as ResourceSnapshotType);
}
}
return changedResourcesTypes;
}

public hasChangedResources() {
const totalUnchanges =
this.getOperationTypeTotalCount('resourcesUnchanged');
Expand Down
Loading