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

Wr/add missing local components #959

Closed
wants to merge 5 commits into from
Closed
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"test:nuts:retrieve": "nyc mocha \"test/nuts/retrieve/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:specialTypes": "nyc mocha \"test/nuts/specialTypes/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:specialTypes:translations": "mocha \"test/nuts/specialTypes/translation.nut.ts\" --slow 4500 --timeout 1200000 --retries 0 --jobs 20",
"test:nuts:static": "nyc mocha \"test/commands/**/*.nut.ts\" \"test/nuts/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:static": "nyc mocha \"test/nuts/metadata/**/*.nut.ts\" \"test/nuts/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:nuts:tracking": "nyc mocha \"test/nuts/tracking/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 20",
"test:only": "wireit",
"version": "oclif readme"
Expand Down
29 changes: 25 additions & 4 deletions src/formatters/deployResultFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
JUnitReporter,
TestResult,
} from '@salesforce/apex-node';
import { getState } from '@salesforce/source-deploy-retrieve/lib/src/client/deployMessages.js';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't do this kind of import. If we need this method it should be made public in SDR and exported.

import {
DeployResultJson,
isSdrFailure,
Expand All @@ -51,10 +52,10 @@ import {
import { TestResultsFormatter } from '../formatters/testResultsFormatter.js';

export class DeployResultFormatter extends TestResultsFormatter implements Formatter<DeployResultJson> {
private relativeFiles: FileResponse[];
private absoluteFiles: FileResponse[];
private coverageOptions: CoverageReporterOptions;
private resultsDir: string;
private readonly relativeFiles: FileResponse[];
private readonly absoluteFiles: FileResponse[];
private readonly coverageOptions: CoverageReporterOptions;
private readonly resultsDir: string;
private readonly junit: boolean | undefined;

public constructor(
Expand Down Expand Up @@ -285,6 +286,26 @@ export class DeployResultFormatter extends TestResultsFormatter implements Forma
private displaySuccesses(): void {
const successes = this.relativeFiles.filter(isSdrSuccess);

ensureArray(this.result.response.details.componentSuccesses)
.filter(
(fromServer) =>
// removes package.xml, other manifests
fromServer.componentType !== '' &&
// if we don't find the file in the response, it's because it doesn't exist locally, yet
!successes.find(
(fromLocal) => fromServer.fullName === fromLocal.fullName && fromServer.componentType === fromLocal.type
)
)
.map((s) =>
successes.push({
fullName: s.fullName,
// @ts-expect-error getState can return 'failed' which isn't applicable to FileSuccess
state: getState(s),
type: s.componentType ?? '',
filePath: 'Not found in project',
})
);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, SDR should do this. Other clients may have the same problem and need this code. I think SDR should report everything that happened, using the ComponentSet when possible to provide accurate file paths, but if not then use the file path from the response. That means updating MetadataApiDeploy.buildFileResponsesFromComponentSet(). @mshanemc - what are your thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that, but NUTs had errors, maybe there's a different method, or a new one, but I don't think getFileResponses is it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like your SDR solution better (made 1 comment there).

I think the NUT failures look to all be source-testkit related, here:
https://github.com/salesforcecli/source-testkit/blob/b5801a5ab89c044e94fd1ce14547ffe3dba9bf9f/src/assertions.ts#L120-L121

So maybe explore why that's hitting missing files?

if (!successes.length || this.result.response.status === RequestStatus.Failed) return;

const columns = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { strict as assert } from 'node:assert';
import { TestSession, execCmd } from '@salesforce/cli-plugins-testkit';
import { expect } from 'chai';
import { RequestStatus } from '@salesforce/source-deploy-retrieve';
import { DeployResultJson } from '../../../../src/utils/types.js';
import { CachedOptions } from '../../../../src/utils/deploy.js';
import { DeployResultJson } from '../../../src/utils/types.js';
import { CachedOptions } from '../../../src/utils/deploy.js';

function readDeployCache(sessionDir: string): Record<string, CachedOptions> {
const contents = fs.readFileSync(path.join(sessionDir, '.sf', 'deploy-cache.json'), 'utf-8');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import path from 'node:path';
import { SourceTestkit } from '@salesforce/source-testkit';
import { assert, config } from 'chai';
import { execCmd } from '@salesforce/cli-plugins-testkit';
import { DeployResultJson } from '../../../../src/utils/types.js';
import { DeployResultJson } from '../../../src/utils/types.js';

config.truncateThreshold = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { fileURLToPath } from 'node:url';
import { SourceTestkit } from '@salesforce/source-testkit';
import { assert, expect } from 'chai';
import { RequestStatus } from '@salesforce/source-deploy-retrieve';
import { DeployResultJson } from '../../../../src/utils/types.js';
import { DeployResultJson } from '../../../src/utils/types.js';

describe('[project deploy report] NUTs with metadata-dir', () => {
let testkit: SourceTestkit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { fileURLToPath } from 'node:url';
import { SourceTestkit } from '@salesforce/source-testkit';
import { assert, isObject } from '@salesforce/ts-types';
import { expect } from 'chai';
import { DeployResultJson } from '../../../../src/utils/types.js';
import { DeployResultJson } from '../../../src/utils/types.js';

describe('[project deploy report] NUTs with source-dir', () => {
let testkit: SourceTestkit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { strict as assert } from 'node:assert';
import { SourceTestkit } from '@salesforce/source-testkit';
import { expect } from 'chai';
import { RequestStatus } from '@salesforce/source-deploy-retrieve';
import { DeployResultJson } from '../../../../src/utils/types.js';
import { CachedOptions } from '../../../../src/utils/deploy.js';
import { DeployResultJson } from '../../../src/utils/types.js';
import { CachedOptions } from '../../../src/utils/deploy.js';

function readDeployCache(projectDir: string): Record<string, CachedOptions> {
// source-testkit doesn't expose the session, so we'll go up 1 level from the project to get to it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { SourceTestkit } from '@salesforce/source-testkit';
import { isObject } from '@salesforce/ts-types';
import { assert, expect } from 'chai';
import { execCmd } from '@salesforce/cli-plugins-testkit';
import { DeployResultJson } from '../../../../src/utils/types.js';
import { DeployResultJson } from '../../../src/utils/types.js';

describe('deploy metadata validate NUTs', () => {
let testkit: SourceTestkit;
Expand Down
2 changes: 1 addition & 1 deletion test/utils/deployResponses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ export const getDeployResult = (
const successes = response.details.componentSuccesses;
fileProps = ensureArray(successes);
return fileProps
.filter((p) => p.fileName !== 'package.xml')
.filter((p) => p.fileName !== 'package.xml' && p.fileName !== '')
.map((comp) => ({
fullName: comp.fullName,
filePath: comp.fileName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import * as path from 'node:path';
import { join } from 'node:path';
import { assert, expect, config } from 'chai';
import sinon from 'sinon';
import { DeployMessage, DeployResult, FileResponse } from '@salesforce/source-deploy-retrieve';
import { ux } from '@oclif/core';
import { ensureArray } from '@salesforce/kit';
import { getCoverageFormattersOptions } from '../../src/utils/coverage.js';
import { DeployResultFormatter } from '../../src/formatters/deployResultFormatter.js';
import { getDeployResult } from './deployResponses.js';
Expand All @@ -22,6 +24,45 @@ describe('deployResultFormatter', () => {
sandbox.restore();
});

describe('displaySuccesses', () => {
const deployResultSuccess = getDeployResult('successSync');
let tableStub: sinon.SinonStub;

beforeEach(() => {
tableStub = sandbox.stub(ux, 'table');
});

it('finds components in server response, and adds them if not in fileResponses', () => {
ensureArray(deployResultSuccess.response.details.componentSuccesses).push({
changed: 'false',
created: 'true',
createdDate: '123',
fullName: 'remoteClass',
componentType: 'ApexClass',
success: 'true',
deleted: 'false',
fileName: '',
});
const formatter = new DeployResultFormatter(deployResultSuccess, { verbose: true });
formatter.display();
expect(tableStub.callCount).to.equal(1);
expect(tableStub.firstCall.args[0]).to.deep.equal([
{
filePath: join('classes', 'ProductController.cls'),
fullName: 'ProductController',
state: 'Changed',
type: 'ApexClass',
},
{
filePath: 'Not found in project',
fullName: 'remoteClass',
state: 'Created',
type: 'ApexClass',
},
]);
});
});

describe('displayFailures', () => {
const deployResultFailure = getDeployResult('failed');
let tableStub: sinon.SinonStub;
Expand Down
Loading