Skip to content

Commit

Permalink
test: add NUT for web server
Browse files Browse the repository at this point in the history
  • Loading branch information
cristiand391 committed Mar 22, 2024
1 parent adbc25f commit 957126e
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 1 deletion.
39 changes: 39 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ on:
workflow_dispatch:

jobs:
determine-node-versions:
outputs:
nodeVersions: ${{ steps.determine-node-versions.outputs.nodeVersions }}
runs-on: ubuntu-latest
steps:
- uses: salesforcecli/github-workflows/.github/actions/determineNodeVersions@main
id: determine-node-versions
with:
nodeVersionOverride: ${{ vars.NODE_VERSION_OVERRIDE }} # default is 'lts/*' and 'lts/-1'
yarn-lockfile-check:
uses: salesforcecli/github-workflows/.github/workflows/lockFileCheck.yml@main
# Since the Windows unit tests take much longer, we run the linux unit tests first and then run the windows unit tests in parallel with NUTs
Expand All @@ -14,6 +23,36 @@ jobs:
windows-unit-tests:
needs: linux-unit-tests
uses: salesforcecli/github-workflows/.github/workflows/unitTestsWindows.yml@main
sfdx-core-nuts:
needs: linux-unit-tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ fromJSON(needs.determine-node-versions.outputs.nodeVersions) }}
cache: yarn
- uses: google/wireit@setup-github-actions-caching/v1
continue-on-error: true
- name: Cache node modules
id: cache-nodemodules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
path: '**/node_modules'
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}

- uses: salesforcecli/github-workflows/.github/actions/yarnInstallWithRetries@main
if: ${{ steps.cache-nodemodules.outputs.cache-hit != 'true' }}
- run: yarn build
- name: yarn test:nuts
uses: salesforcecli/github-workflows/.github/actions/retry@main
with:
command: yarn test:nuts
env:
SF_DISABLE_TELEMETRY: true

xNuts:
needs: linux-unit-tests
uses: salesforcecli/github-workflows/.github/workflows/externalNut.yml@main
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"prepack": "sf-prepack",
"prepare": "sf-install",
"test": "wireit",
"test:nuts": "nyc mocha test/**/*.nut.ts",
"test:only": "wireit",
"test:perf": "ts-node test/perf/logger/main.test.ts"
},
Expand Down
5 changes: 5 additions & 0 deletions src/webOAuthServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ export class WebOAuthServer extends AsyncCreatable<WebOAuthServer.Options> {
return this.authUrl;
}

public close(): void {
this.logger.debug('closing server connection');
this.webServer.close();
}

/**
* Executes the oauth request and creates a new AuthInfo when successful
*
Expand Down
43 changes: 43 additions & 0 deletions test/nut/webOauthServer.nut.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2024, salesforce.com, inc.
* All rights reserved.
* 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 { expect } from 'chai';
import { WebOAuthServer } from '../../src/webOAuthServer';
import { JwtOAuth2Config } from '../../src/org/authInfo';

describe('web Oauth server', () => {
const oauthConfig: JwtOAuth2Config = {
loginUrl: 'https://login.salesforce.com',
};

let oauthServer: WebOAuthServer;

before(async () => {
oauthServer = await WebOAuthServer.create({ oauthConfig });
await oauthServer.start();
await oauthServer.authorizeAndSave();
});

after(() => {
oauthServer.close();
});

it('handle preflight request', async () => {
const accessControlHeaders = new Headers({
'access-control-request-private-network': 'true',
'access-control-request-method': 'GET',
});

const res = await fetch('http://localhost:1717', {
method: 'OPTIONS',
headers: accessControlHeaders,
});

expect(res.status).to.equal(204);
expect(res.headers.get('Access-Control-Allow-Methods')).to.equal('GET');
expect(res.headers.get('Access-Control-Request-Headers')).to.equal('GET');
});
});
2 changes: 1 addition & 1 deletion test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "@salesforce/dev-config/tsconfig-test-strict",
"include": ["unit/**/*.ts", "perf/**/*.ts"],
"include": ["unit/**/*.ts", "nut/**/*.ts", "perf/**/*.ts"],
"compilerOptions": {
"noEmit": true,
"skipLibCheck": true,
Expand Down

4 comments on commit 957126e

@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: 957126e Previous: adbc25f Ratio
Child logger creation 481245 ops/sec (±1.15%) 470064 ops/sec (±2.33%) 0.98
Logging a string on root logger 867291 ops/sec (±7.71%) 814225 ops/sec (±7.51%) 0.94
Logging an object on root logger 634587 ops/sec (±7.51%) 646849 ops/sec (±6.66%) 1.02
Logging an object with a message on root logger 28376 ops/sec (±182.18%) 4901 ops/sec (±217.88%) 0.17
Logging an object with a redacted prop on root logger 476031 ops/sec (±9.00%) 461432 ops/sec (±7.36%) 0.97
Logging a nested 3-level object on root logger 28194 ops/sec (±181.85%) 391701 ops/sec (±8.24%) 13.89

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: 957126e Previous: adbc25f Ratio
Logging a nested 3-level object on root logger 28194 ops/sec (±181.85%) 391701 ops/sec (±8.24%) 13.89

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: 957126e Previous: adbc25f Ratio
Child logger creation 339301 ops/sec (±0.45%) 339507 ops/sec (±0.34%) 1.00
Logging a string on root logger 810289 ops/sec (±6.91%) 759702 ops/sec (±5.85%) 0.94
Logging an object on root logger 625189 ops/sec (±8.05%) 580922 ops/sec (±4.24%) 0.93
Logging an object with a message on root logger 5018 ops/sec (±211.61%) 10866 ops/sec (±189.68%) 2.17
Logging an object with a redacted prop on root logger 473631 ops/sec (±6.97%) 369307 ops/sec (±9.30%) 0.78
Logging a nested 3-level object on root logger 337499 ops/sec (±5.71%) 275550 ops/sec (±6.29%) 0.82

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: 957126e Previous: adbc25f Ratio
Logging an object with a message on root logger 5018 ops/sec (±211.61%) 10866 ops/sec (±189.68%) 2.17

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

Please sign in to comment.