Skip to content

Commit

Permalink
refactor: module interop and test imports
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Oct 5, 2023
1 parent 72b016a commit 0f02b10
Show file tree
Hide file tree
Showing 20 changed files with 39 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/deviceOauthService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Transport from 'jsforce/lib/transport';
import { AsyncCreatable, Duration, parseJsonMap } from '@salesforce/kit';
import { HttpRequest, OAuth2Config } from 'jsforce';
import { ensureString, JsonMap, Nullable } from '@salesforce/ts-types';
import * as FormData from 'form-data';
import FormData from 'form-data';
import { Logger } from './logger/logger';
import { AuthInfo, DEFAULT_CONNECTED_APP_INFO, SFDX_HTTP_HEADERS } from './org';
import { SfError } from './sfError';
Expand Down
2 changes: 1 addition & 1 deletion src/org/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */

import { URL } from 'url';
import { AsyncResult, DeployOptions, DeployResultLocator } from 'jsforce/api/metadata';
import type { AsyncResult, DeployOptions, DeployResultLocator } from 'jsforce/lib/api/metadata';
import { Duration, env, maxBy } from '@salesforce/kit';
import { asString, ensure, isString, JsonMap, Optional } from '@salesforce/ts-types';
import {
Expand Down
2 changes: 1 addition & 1 deletion src/status/streamingClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */

import { resolve as resolveUrl } from 'url';
import { AsyncOptionalCreatable, Duration, Env, env, set } from '@salesforce/kit/lib';
import { AsyncOptionalCreatable, Duration, Env, env, set } from '@salesforce/kit';
import { AnyFunction, AnyJson, ensure, ensureString, JsonMap } from '@salesforce/ts-types/lib';
import * as Faye from 'faye';
import { Logger } from '../logger/logger';
Expand Down
2 changes: 1 addition & 1 deletion src/util/sfdc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const validatePathDoesNotContainInvalidChars = (value: string): boolean =
*/
export const findUpperCaseKeys = (data?: JsonMap, sectionBlocklist: string[] = []): Optional<string> => {
let key: Optional<string>;
findKey(data, (val: AnyJson, k: string) => {
findKey(data, (val: AnyJson | undefined, k: string) => {
if (/^[A-Z]/.test(k)) {
key = k;
} else if (isJsonMap(val)) {
Expand Down
2 changes: 1 addition & 1 deletion src/util/zipWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { Readable, Writable } from 'stream';
import * as JSZip from 'jszip';
import JSZip from 'jszip';
import { Logger } from '../logger/logger';
import { SfError } from '../sfError';
import { StructuredWriter } from './structuredWriter';
Expand Down
5 changes: 4 additions & 1 deletion test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"compilerOptions": {
"noEmit": true,
"skipLibCheck": true,
"resolveJsonModule": true
"resolveJsonModule": true,
"moduleResolution": "Node16",
"module": "Node16",
"esModuleInterop": true
}
}
2 changes: 1 addition & 1 deletion test/unit/config/configAggregatorTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-call */
import * as fs from 'fs';
import fs from 'fs';
import { assert, expect, config as chaiConfig } from 'chai';
import { Config, ConfigProperties, SFDX_ALLOWED_PROPERTIES, SfdxPropertyKeys } from '../../../src/config/config';
import { ConfigAggregator, ConfigInfo } from '../../../src/config/configAggregator';
Expand Down
12 changes: 6 additions & 6 deletions test/unit/config/configFileTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-call */

import * as Path from 'path';
import * as fs from 'fs';
import path from 'path';
import fs from 'fs';
import { expect } from 'chai';

import { assert } from '@salesforce/ts-types';
Expand Down Expand Up @@ -71,10 +71,10 @@ describe('Config', () => {
expect(config.getPath()).to.not.contain('.sf');
});
it('using local custom folder', () => {
const config = new TestConfig(TestConfig.getOptions('test', false, false, Path.join('my', 'path')));
const config = new TestConfig(TestConfig.getOptions('test', false, false, path.join('my', 'path')));
expect(config.getPath()).to.contain(TestConfig.getTestLocalPath());
expect(config.getPath()).to.not.contain('.sf');
expect(config.getPath()).to.contain(Path.join('my', 'path', 'test'));
expect(config.getPath()).to.contain(path.join('my', 'path', 'test'));
});
});
describe('creation', () => {
Expand Down Expand Up @@ -102,10 +102,10 @@ describe('Config', () => {
expect(config.getPath()).to.not.contain('.sf');
});
it('using local custom folder', async () => {
const config = await TestConfig.create(TestConfig.getOptions('test', false, false, Path.join('my', 'path')));
const config = await TestConfig.create(TestConfig.getOptions('test', false, false, path.join('my', 'path')));
expect(config.getPath()).to.contain(TestConfig.getTestLocalPath());
expect(config.getPath()).to.not.contain('.sf');
expect(config.getPath()).to.contain(Path.join('my', 'path', 'test'));
expect(config.getPath()).to.contain(path.join('my', 'path', 'test'));
});
});

Expand Down
8 changes: 4 additions & 4 deletions test/unit/crypto/cryptoKeyFailuresTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
*/
/* eslint-disable @typescript-eslint/no-unsafe-member-access */

import * as childProcess from 'child_process';
import * as _crypto from 'crypto';
import * as os from 'os';
import childProcess from 'child_process';
import crypto from 'crypto';
import os from 'os';
import { AnyJson } from '@salesforce/ts-types';
import { assert, expect } from 'chai';
import { Crypto } from '../../../src/crypto/crypto';
Expand Down Expand Up @@ -67,7 +67,7 @@ if (os.platform() === 'darwin') {
// Setup stubs so that the spawn process to the encryption program returns
// a fake to cause errors.
// @ts-expect-error - type mismatch
$$.SANDBOX.stub(_crypto, 'randomBytes').returns(buf);
$$.SANDBOX.stub(crypto, 'randomBytes').returns(buf);
const spawnStub = $$.SANDBOX.stub(childProcess, 'spawn');
// @ts-expect-error - number of arguments
spawnStub.withArgs(programArg, getOptionsArg).returns(spawnReturnFake);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/crypto/cryptoTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
/* eslint-disable @typescript-eslint/ban-types */

import * as os from 'os';
import os from 'os';
import { stubMethod } from '@salesforce/ts-sinon';
import { expect } from 'chai';
import { Crypto } from '../../../src/crypto/crypto';
Expand Down
2 changes: 1 addition & 1 deletion test/unit/crypto/keyChainImplTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/* eslint-disable no-underscore-dangle */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */

import * as fs from 'fs';
import fs from 'fs';
import { assert, expect } from 'chai';
import { KeychainAccess, keyChainImpl } from '../../../src/crypto/keyChainImpl';
import { shouldThrow, TestContext } from '../../../src/testSetup';
Expand Down
2 changes: 1 addition & 1 deletion test/unit/crypto/secureStringTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import * as crypto from 'crypto';
import crypto from 'crypto';
import { expect } from 'chai';
import { stub } from 'sinon';
import { SecureBuffer } from '../../../src/crypto/secureBuffer';
Expand Down
2 changes: 1 addition & 1 deletion test/unit/lifecycleEventsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
/* eslint-disable @typescript-eslint/no-unsafe-member-access */

import { Duration, sleep } from '@salesforce/kit/lib/duration';
import { Duration, sleep } from '@salesforce/kit';
import { spyMethod } from '@salesforce/ts-sinon';
import * as chai from 'chai';
import { Lifecycle } from '../../src/lifecycleEvents';
Expand Down
4 changes: 2 additions & 2 deletions test/unit/messagesTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
/* eslint-disable @typescript-eslint/no-unsafe-argument */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */

import * as fs from 'fs';
import * as path from 'path';
import fs from 'fs';
import path from 'path';
import { EOL } from 'os';
import { cloneJson } from '@salesforce/kit';
import { assert, expect } from 'chai';
Expand Down
8 changes: 4 additions & 4 deletions test/unit/org/authInfoTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
/* eslint-disable @typescript-eslint/ban-types */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */

import * as pathImport from 'path';
import * as dns from 'dns';
import * as jwt from 'jsonwebtoken';
import path from 'path';
import dns from 'dns';
import jwt from 'jsonwebtoken';
import { cloneJson, env, includes } from '@salesforce/kit';
import { spyMethod, stubMethod } from '@salesforce/ts-sinon';
import { AnyJson, getJsonMap, JsonMap, toJsonMap } from '@salesforce/ts-types';
Expand Down Expand Up @@ -1107,7 +1107,7 @@ describe('AuthInfo', () => {
});

it('should path.resolve jwtkeyfilepath', async () => {
const resolveSpy = $$.SANDBOX.spy(pathImport, 'resolve');
const resolveSpy = $$.SANDBOX.spy(path, 'resolve');

authInfoStubs.authJwt.restore();
stubMethod($$.SANDBOX, AuthInfo.prototype, 'authJwt').resolves({
Expand Down
2 changes: 1 addition & 1 deletion test/unit/org/orgTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { deepStrictEqual, fail } from 'assert';
import * as fs from 'fs';
import fs from 'fs';
import { constants as fsConstants } from 'fs';
import { join as pathJoin } from 'path';
import { Duration, set } from '@salesforce/kit';
Expand Down
2 changes: 1 addition & 1 deletion test/unit/status/myDomainResolverTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import * as dns from 'dns';
import dns from 'dns';
import { URL } from 'url';
import { Duration, Env } from '@salesforce/kit';
import { AnyFunction } from '@salesforce/ts-types';
Expand Down
8 changes: 3 additions & 5 deletions test/unit/util/directoryWriterTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import * as os from 'os';
import * as fs from 'fs';
import * as path from 'path';
import { Readable } from 'stream';
import * as chai from 'chai';
import * as chaiString from 'chai-string';
import { expect, use } from 'chai';
import chaiString from 'chai-string';
import { DirectoryWriter } from '../../../src/util/directoryWriter';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { expect } = chai;
chai.use(chaiString);
use(chaiString);

function validateFileContents(filePath: string, expectedContents: string): void {
const fileContents = fs.readFileSync(filePath, 'utf8');
Expand Down
2 changes: 1 addition & 1 deletion test/unit/util/zipWriterTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as fs from 'fs';
import * as path from 'path';
import { expect } from 'chai';
import * as sinon from 'sinon';
import * as JSZip from 'jszip';
import JSZip from 'jszip';
import { ZipWriter } from '../../../src/util/zipWriter';

describe('ZipWriter', () => {
Expand Down
3 changes: 3 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"outDir": "./lib",
"resolveJsonModule": true,
"rootDir": "./src",
"moduleResolution": "Node16",
"module": "Node16",
"esModuleInterop": true,
"plugins": [{ "transform": "./src/messageTransformer.ts" }]
},
"include": ["./src/**/*.ts"]
Expand Down

4 comments on commit 0f02b10

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

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

Logger Benchmarks - ubuntu-latest

Benchmark suite Current: 0f02b10 Previous: 0bf1680 Ratio
Child logger creation 499682 ops/sec (±0.72%) 467723 ops/sec (±1.28%) 0.94
Logging a string on root logger 599838 ops/sec (±12.97%) 457572 ops/sec (±10.23%) 0.76
Logging an object on root logger 387725 ops/sec (±10.77%) 292299 ops/sec (±12.07%) 0.75
Logging an object with a message on root logger 236216 ops/sec (±11.54%) 225815 ops/sec (±12.02%) 0.96
Logging an object with a redacted prop on root logger 6511 ops/sec (±204.23%) 211008 ops/sec (±16.26%) 32.41
Logging a nested 3-level object on root logger 214242 ops/sec (±10.10%) 4348 ops/sec (±202.34%) 0.020294806807255348

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Logger Benchmarks - ubuntu-latest'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 0f02b10 Previous: 0bf1680 Ratio
Logging an object with a redacted prop on root logger 6511 ops/sec (±204.23%) 211008 ops/sec (±16.26%) 32.41

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

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

Logger Benchmarks - windows-latest

Benchmark suite Current: 0f02b10 Previous: 0bf1680 Ratio
Child logger creation 420219 ops/sec (±16.94%) 385727 ops/sec (±3.69%) 0.92
Logging a string on root logger 636695 ops/sec (±12.10%) 494376 ops/sec (±9.07%) 0.78
Logging an object on root logger 471131 ops/sec (±14.14%) 334002 ops/sec (±15.86%) 0.71
Logging an object with a message on root logger 232691 ops/sec (±21.06%) 255001 ops/sec (±12.99%) 1.10
Logging an object with a redacted prop on root logger 6766 ops/sec (±205.44%) 234076 ops/sec (±18.85%) 34.60
Logging a nested 3-level object on root logger 269138 ops/sec (±14.79%) 5801 ops/sec (±189.68%) 0.02155399832056417

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Logger Benchmarks - windows-latest'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 0f02b10 Previous: 0bf1680 Ratio
Logging an object with a redacted prop on root logger 6766 ops/sec (±205.44%) 234076 ops/sec (±18.85%) 34.60

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.