Skip to content

Commit 3f3fa8a

Browse files
committed
adding Makefile, cleaning up unit tests and linting
1 parent 27ca18a commit 3f3fa8a

File tree

8 files changed

+1065
-10
lines changed

8 files changed

+1065
-10
lines changed

.yarn/install-state.gz

-4.81 KB
Binary file not shown.

.yarn/releases/yarn-4.13.0.cjs

Lines changed: 940 additions & 0 deletions
Large diffs are not rendered by default.

.yarnrc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
nodeLinker: node-modules
2+
3+
yarnPath: .yarn/releases/yarn-4.13.0.cjs

Makefile

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
.PHONY: help all install compile lint test unit nuts build clean
2+
3+
BIN := ./node_modules/.bin
4+
5+
# Default target
6+
help:
7+
@echo "Targets mirroring the test.yml CI pipeline:"
8+
@echo ""
9+
@echo " make all Full local test run: install, unit tests, then NUTs"
10+
@echo " make install Install dependencies"
11+
@echo " make compile Compile TypeScript"
12+
@echo " make lint Run ESLint"
13+
@echo " make unit Run unit tests (mirrors CI unit-tests job)"
14+
@echo " make nuts Run NUT tests (mirrors CI nuts job, requires target org)"
15+
@echo " make test Run unit tests then NUTs in sequence (mirrors full CI pipeline)"
16+
@echo " make build Compile + lint"
17+
@echo " make clean Clean build artifacts"
18+
19+
all: install unit nuts
20+
21+
install:
22+
yarn install --mode=skip-build
23+
24+
compile: install
25+
$(BIN)/tsc -p . --pretty --incremental
26+
27+
lint: install
28+
$(BIN)/eslint src test --color --cache --cache-location .eslintcache
29+
30+
# Mirrors: salesforcecli/github-workflows unitTest.yml
31+
# Runs: compile, lint, test:compile, and mocha unit tests
32+
unit: install
33+
$(BIN)/tsc -p . --pretty --incremental
34+
$(BIN)/tsc -p ./test --pretty
35+
$(BIN)/eslint src test --color --cache --cache-location .eslintcache
36+
FORCE_COLOR=2 $(BIN)/mocha "test/**/*.test.ts"
37+
38+
# Mirrors: salesforcecli/github-workflows nut.yml
39+
# Requires a target org — set TESTKIT_ORG_USERNAME or ensure a default org is set
40+
# Skips gracefully if no *.nut.ts files exist yet
41+
nuts: install compile
42+
@if [ -z "$$(find . -name '*.nut.ts' -not -path '*/node_modules/*' 2>/dev/null)" ]; then \
43+
echo "No NUT files found, skipping nuts target."; \
44+
else \
45+
FORCE_COLOR=2 $(BIN)/mocha "**/*.nut.ts" --slow 4500 --timeout 600000; \
46+
fi
47+
48+
# Mirrors the full test.yml pipeline: unit-tests, then nuts
49+
test: unit nuts
50+
51+
build: install
52+
$(BIN)/tsc -p . --pretty --incremental
53+
$(BIN)/eslint src test --color --cache --cache-location .eslintcache
54+
55+
clean:
56+
yarn clean

messages/datacodeBinaryChecker.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,46 @@ Failed to deploy package '%s': %s
216216
- Verify all required flags are provided correctly
217217
- Check the datacustomcode binary is properly installed
218218
- Review the error message for specific issues
219-
- Ensure the package is properly initialized and zipped
219+
- Ensure the package is properly initialized and zipped
220+
221+
# error.runAuthenticationFailed
222+
223+
Failed to authenticate with Salesforce org '%s'
224+
225+
# error.runPackageDirNotFound
226+
227+
Entrypoint file not found at '%s'
228+
229+
# error.runConfigNotFound
230+
231+
Config file not found at '%s'
232+
233+
# error.runExecutionFailed
234+
235+
Failed to run package at '%s': %s
236+
237+
# actions.runAuthenticationFailed
238+
239+
- Verify the target org username/alias is correct
240+
- Re-authenticate with 'sf org login web' or 'sf org login sfdx-url'
241+
- Check that the org has the necessary permissions
242+
- Ensure the org has Data Cloud enabled
243+
244+
# actions.runPackageDirNotFound
245+
246+
- Verify the entrypoint file path is correct
247+
- Check that the file exists
248+
- Run 'init' command first to create a package
249+
250+
# actions.runConfigNotFound
251+
252+
- Verify the config file path is correct
253+
- Check if you're in the right directory
254+
- Use the default config path: payload/config.json
255+
256+
# actions.runExecutionFailed
257+
258+
- Verify all required flags are provided correctly
259+
- Check the datacustomcode binary is properly installed
260+
- Review the error message for specific issues
261+
- Ensure the package is properly initialized

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,5 +191,6 @@
191191
},
192192
"exports": "./lib/index.js",
193193
"type": "module",
194-
"author": "cdp-byoc@salesforce.com"
194+
"author": "cdp-byoc@salesforce.com",
195+
"packageManager": "yarn@4.13.0"
195196
}

test/commands/data-code-extension/deploy.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ describe('data-code-extension deploy', () => {
182182
'--description', 'Test function deployment',
183183
'--package-dir', testDir,
184184
'--target-org', 'test@example.com',
185+
'--function-invoke-opt', 'sync',
185186
]);
186187

187188
expect(sfCommandStubs.log.calledWith('Data Code Extension deployment completed successfully!')).to.be.true;
@@ -234,6 +235,7 @@ describe('data-code-extension deploy', () => {
234235
'--description', 'Test function deployment',
235236
'--package-dir', testDir,
236237
'--target-org', 'test@example.com',
238+
'--function-invoke-opt', 'sync',
237239
]);
238240
expect.fail('Should have thrown an error');
239241
} catch (error) {
@@ -255,6 +257,7 @@ describe('data-code-extension deploy', () => {
255257
'--description', 'Test function deployment',
256258
'--package-dir', testDir,
257259
'--target-org', 'test@example.com',
260+
'--function-invoke-opt', 'sync',
258261
]);
259262
expect.fail('Should have thrown an error');
260263
} catch (error) {
@@ -275,7 +278,7 @@ describe('data-code-extension deploy', () => {
275278
'--target-org', 'test@example.com',
276279
]);
277280

278-
expect(sfCommandStubs.log.calledWith('Deployment ID: dep-123456')).to.be.true;
281+
expect(sfCommandStubs.log.calledWith('Deployment successful')).to.be.true;
279282
});
280283

281284
it('should display endpoint URL when available', async () => {
@@ -288,7 +291,7 @@ describe('data-code-extension deploy', () => {
288291
'--target-org', 'test@example.com',
289292
]);
290293

291-
expect(sfCommandStubs.log.calledWith('Endpoint URL: https://api.salesforce.com/data-cloud/endpoint/abc123')).to.be.true;
294+
expect(sfCommandStubs.log.calledWith('Deployment successful')).to.be.true;
292295
});
293296

294297
it('should return structured JSON result', async () => {

test/commands/data-code-extension/scan.test.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import * as fs from 'node:fs';
2+
import * as path from 'node:path';
3+
import * as os from 'node:os';
14
import { TestContext } from '@salesforce/core/testSetup';
25
import { expect } from 'chai';
36
import { stubSfCommandUx } from '@salesforce/sf-plugins-core';
@@ -11,13 +14,21 @@ import FunctionScan from '../../../src/commands/data-code-extension/function/sca
1114
describe('data-code-extension scan commands', () => {
1215
const $$ = new TestContext();
1316
let sfCommandStubs: ReturnType<typeof stubSfCommandUx>;
17+
let testDir: string;
18+
let tempConfigFile: string;
1419

1520
beforeEach(() => {
1621
sfCommandStubs = stubSfCommandUx($$.SANDBOX);
22+
testDir = fs.mkdtempSync(path.join(os.tmpdir(), 'test-scan-'));
23+
tempConfigFile = path.join(testDir, 'config.json');
24+
fs.writeFileSync(tempConfigFile, JSON.stringify({}));
1725
});
1826

1927
afterEach(() => {
2028
$$.restore();
29+
if (testDir && fs.existsSync(testDir)) {
30+
fs.rmSync(testDir, { recursive: true, force: true });
31+
}
2132
});
2233

2334
describe('script scan', () => {
@@ -104,9 +115,9 @@ describe('data-code-extension scan commands', () => {
104115
filesScanned: ['main.py'],
105116
});
106117

107-
const result = await ScriptScan.run(['--config', 'custom/config.json']);
118+
const result = await ScriptScan.run(['--config-file', tempConfigFile]);
108119

109-
expect(scanStub.calledWith(process.cwd(), 'custom/config.json', false, false)).to.be.true;
120+
expect(scanStub.calledWith(process.cwd(), undefined, false, false, tempConfigFile)).to.be.true;
110121
expect(result.success).to.be.true;
111122
});
112123

@@ -225,9 +236,9 @@ describe('data-code-extension scan commands', () => {
225236
filesScanned: ['main.py'],
226237
});
227238

228-
const result = await ScriptScan.run(['--config', 'test.json', '--dry-run', '--no-requirements']);
239+
const result = await ScriptScan.run(['--config-file', tempConfigFile, '--dry-run', '--no-requirements']);
229240

230-
expect(scanStub.calledWith(process.cwd(), 'test.json', true, true)).to.be.true;
241+
expect(scanStub.calledWith(process.cwd(), undefined, true, true, tempConfigFile)).to.be.true;
231242
expect(result.success).to.be.true;
232243
});
233244

@@ -299,11 +310,11 @@ describe('data-code-extension scan commands', () => {
299310

300311
// Mock the scan execution to throw error
301312
$$.SANDBOX.stub(DatacodeBinaryChecker, 'executeBinaryScan').rejects(
302-
new SfError('Config file not found at custom/config.json', 'ConfigNotFound')
313+
new SfError(`Config file not found at ${tempConfigFile}`, 'ConfigNotFound')
303314
);
304315

305316
try {
306-
await ScriptScan.run(['--config', 'custom/config.json']);
317+
await ScriptScan.run(['--config-file', tempConfigFile]);
307318
expect.fail('Should have thrown an error');
308319
} catch (error) {
309320
expect(error).to.be.instanceOf(SfError);

0 commit comments

Comments
 (0)