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

chore: revamp build setup + bump/prune deps #1369

Merged
merged 81 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
001cc82
chore: jsdoc stuff
cristiand391 Oct 2, 2023
8a359d6
docs(bulk v2): how to handle errors
cristiand391 Oct 3, 2023
e45e3d9
fix: bump inquirer
iowillhoit Oct 3, 2023
d833a48
chore: bump TS deps, improve type checking
cristiand391 Oct 6, 2023
8d9d4da
chore: code review
cristiand391 Oct 6, 2023
bf4ab8c
chore: fix jsdoc
cristiand391 Oct 6, 2023
ac5fff3
test: increase bulk2 timeout
cristiand391 Oct 6, 2023
0fc18d9
test: increase bulk timeout
cristiand391 Oct 6, 2023
51760f5
chore: update build setup
cristiand391 Oct 9, 2023
ddeb58d
chore: lint
cristiand391 Oct 9, 2023
fd8e280
ci: update test workflow
cristiand391 Oct 9, 2023
c011585
ci: update externalNut workflow
cristiand391 Oct 9, 2023
d2ca7c5
Merge pull request #1367 from jsforce/cd/jsdoc
shetzel Oct 9, 2023
a9b375f
ci: update publishDocs workflow
cristiand391 Oct 9, 2023
d96a720
ci: fix manualRelease workflow
cristiand391 Oct 9, 2023
7c8e6a1
chore(release): 2.0.0-beta.28 [skip ci]
svc-cli-bot Oct 9, 2023
c3ee120
fix: move tsconfig, use jest official types
cristiand391 Oct 9, 2023
f3b5a85
chore: use wireit
cristiand391 Oct 10, 2023
cbf7cdd
fix: use @types/jest
cristiand391 Oct 10, 2023
17b0931
chore: use wireit services
cristiand391 Oct 10, 2023
9523957
chore: remove `directories` property
cristiand391 Oct 10, 2023
ecc417b
chore: bump eslint
cristiand391 Oct 10, 2023
f0a3b46
fix: update babel config/deps
cristiand391 Oct 11, 2023
47a3905
chore: remove jest/globals pkg
cristiand391 Oct 11, 2023
7a4c6c9
fix: tests don't require node build
cristiand391 Oct 12, 2023
7108b88
fix: bump csv deps
cristiand391 Oct 12, 2023
670d697
Merge branch 'ew/bump-inquirer' into cd/revamp-build-scripts
cristiand391 Oct 12, 2023
4393f7b
fix: bump `xml2js`
cristiand391 Oct 12, 2023
003426c
fix: lint lint
cristiand391 Oct 12, 2023
9eeb895
fix: replace `querystring`
cristiand391 Oct 12, 2023
9981ee1
chore: bump types/node
cristiand391 Oct 12, 2023
eabbf9e
fix: search params
cristiand391 Oct 12, 2023
1c9112f
test: fix browser tests by avoiding barrel file
cristiand391 Oct 12, 2023
5698f46
Revert "fix: tests don't require node build"
cristiand391 Oct 12, 2023
3c3ede6
test: fix typo and test
cristiand391 Oct 12, 2023
3b3ec80
ci: add wireit cache
cristiand391 Oct 12, 2023
9f356a5
docs: add DEVELOPING.md
cristiand391 Oct 12, 2023
fbee7ff
Update DEVELOPING.md
cristiand391 Oct 17, 2023
04c0f29
Update README.md
cristiand391 Oct 17, 2023
f1c227f
test: allow org-setup script to use default hub
cristiand391 Oct 17, 2023
6b2e22a
chore: set version for release
cristiand391 Oct 18, 2023
fd0e66d
fix: TS type errors
cristiand391 Oct 18, 2023
cc16d22
fix: lint lint
cristiand391 Oct 18, 2023
7839619
fix: revert TS change
cristiand391 Oct 18, 2023
8894d13
test: fix org setup script on node v21
cristiand391 Oct 18, 2023
6668583
test: real fix
cristiand391 Oct 19, 2023
4a365d5
test: get visualforce completions instead of apex ones
cristiand391 Oct 19, 2023
5f5fbab
chore: remove console.log
cristiand391 Oct 19, 2023
779fa35
docs: publish to v3 branch
cristiand391 Nov 6, 2023
bc5ff6e
chore: update prerelease id
cristiand391 Nov 6, 2023
e72b5d8
chore: ts-expect-error
cristiand391 Nov 6, 2023
ea844c8
chore: update DEVELOPING.md
cristiand391 Nov 6, 2023
ec2e930
test: increase bulk2 poll timeout
cristiand391 Nov 8, 2023
79191b2
Merge branch '2.0' into cd/revamp-build-scripts
cristiand391 Nov 14, 2023
c41db7a
test: improve bulk v1 tests
cristiand391 Nov 15, 2023
28e2c0d
chore: lint tnil
cristiand391 Nov 15, 2023
03a5ca2
test: improve bulk v2 tests
cristiand391 Nov 16, 2023
31e7fd1
test: improve bulk v2 poll timeout in query tests
cristiand391 Nov 16, 2023
71f143b
test: separate test data for bulk tests
cristiand391 Nov 16, 2023
399de77
test: improve query tests
cristiand391 Nov 16, 2023
38a7d70
test: missed these 2 query tests
cristiand391 Nov 16, 2023
a07a680
test: update streaming test
cristiand391 Nov 16, 2023
f64beff
test: retry 3 times
cristiand391 Nov 16, 2023
34da5ae
test: idempotent bulk tests
cristiand391 Nov 17, 2023
c487aee
chore: reuse ensureBulk helper
cristiand391 Nov 17, 2023
29f4eef
test: retry browser tests
cristiand391 Nov 21, 2023
086ae69
test: use nick-fields/retry
cristiand391 Nov 21, 2023
23e869d
test: timeout/retry
cristiand391 Nov 21, 2023
d0a3e27
test: fix scripts
cristiand391 Nov 21, 2023
7d9169c
test: fix retry script
cristiand391 Nov 21, 2023
9d24010
chore: cleanup
cristiand391 Nov 22, 2023
8a774ec
chore: re-enable node/externalNUTs tests
cristiand391 Nov 22, 2023
f29fbd5
test(jest): log test retries
cristiand391 Nov 22, 2023
3b10446
test: improve search test
cristiand391 Nov 22, 2023
252db5e
test(sosl): increase delay
cristiand391 Nov 22, 2023
2bae833
test(mdapi): increase poll timeout
cristiand391 Nov 22, 2023
5e4c75c
chore: lint tnil
cristiand391 Nov 22, 2023
46e3b60
test(streaming): increase delay
cristiand391 Nov 22, 2023
361ca1c
test(streaming): cleanup after run
cristiand391 Nov 22, 2023
8a32aad
Merge pull request #1378 from jsforce/cd/fix-flaky-tests
mshanemc Nov 22, 2023
b5ba8e7
Update DEVELOPING.md
cristiand391 Nov 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/externalNut.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ jobs:
run: |
cd ./jsforce
npm install
## skip webpack, we are only interested in types and node build
npm run clean && npm run build:types && npm run build:lib
## skip webpack, we are only interested in the node build
npm run clean && npm run build:node:cjs
yarn link
- name: link jsforce into plugin
if: ${{ steps.cache-nodemodules.outputs.cache-hit != 'true' }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/manualRelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
docs:
needs: release
if: github.ref_name === '2.0'
if: github.ref_name === '3.0'
uses: ./.github/workflows/publishDocs.yml
cristiand391 marked this conversation as resolved.
Show resolved Hide resolved
release:
runs-on: ubuntu-latest
Expand All @@ -33,7 +33,7 @@ jobs:
output-file: false
pre-commit: ./scripts/build.js
pre-release: true
pre-release-identifier: 'beta'
pre-release-identifier: 'next'
# always do the release, even if there are no semantic commits
skip-on-empty: false
tag-prefix: ''
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/onRelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ jobs:
- name: Build
run: npm run clean && npm run build
- name: Publish
run: npm publish --tag beta
run: npm publish --tag next
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
11 changes: 5 additions & 6 deletions .github/workflows/publishDocs.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: publish-docs

on:
workflow_dispatch:
on: workflow_call

jobs:
publish:
Expand All @@ -26,14 +25,14 @@ jobs:
run: |
rm -rf docs
git worktree prune
git fetch origin v2-docs:v2-docs
git worktree add docs v2-docs
git fetch origin v3-docs:v3-docs
git worktree add docs v3-docs
npx typedoc --out docs/tmp
cp -r docs/tmp/* docs/tmp/..
rm -rf docs/tmp
- name: send to git
run: |
cd docs
git add .
git commit -m 'docs: publishing v2-docs [skip ci]' --no-verify
git push origin v2-docs --no-verify
git commit -m 'docs: publishing v3-docs [skip ci]' --no-verify
git push origin v3-docs --no-verify
35 changes: 26 additions & 9 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: lts/*

- uses: google/wireit@setup-github-actions-caching/v1
- name: Install dependencies
run: npm install

Expand All @@ -36,18 +36,30 @@ jobs:
run: |
npx zx scripts/org-setup.mjs

- name: Run browser tests
- name: Run browser tests with 3 attempts
uses: nick-fields/retry@943e742917ac94714d2f408a0e8320f2d1fcafcd
with:
max_attempts: 3
timeout_minutes: 30
retry_wait_seconds: 60
command: |
SF_USERNAME=$(sf org display user --target-org jsforce-test-org --json | jq -r '.result.username') \
SF_PASSWORD=$(sf org display user --target-org jsforce-test-org --json | jq -r '.result.password') \
SF_LOGIN_URL=$(sf org display user --target-org jsforce-test-org --json | jq -r '.result.instanceUrl') \
DISPLAY=:99 CHROME_BIN=$(which chrome) \
npm run test:browser-ci
new_command_on_retry: |
SF_USERNAME=$(sf org display user --target-org jsforce-test-org --json | jq -r '.result.username') \
SF_PASSWORD=$(sf org display user --target-org jsforce-test-org --json | jq -r '.result.password') \
SF_LOGIN_URL=$(sf org display user --target-org jsforce-test-org --json | jq -r '.result.instanceUrl') \
DISPLAY=:99 CHROME_BIN=$(which chrome) \
npm run test:browser-ci:retry
retry_on: error
env:
SF_OAUTH2_CLIENT_ID: ${{ secrets.SF_OAUTH2_CLIENT_ID }}
SF_OAUTH2_CLIENT_SECRET: ${{ secrets.SF_OAUTH2_CLIENT_SECRET }}
SF_OAUTH2_REDIRECT_URI: ${{ secrets.SF_OAUTH2_REDIRECT_URI }}
SF_AJAX_PROXY_URL: ${{ vars.SF_AJAX_PROXY_URL }}
run: |
SF_USERNAME=$(sf org display user --target-org jsforce-test-org --json | jq -r '.result.username') \
SF_PASSWORD=$(sf org display user --target-org jsforce-test-org --json | jq -r '.result.password') \
SF_LOGIN_URL=$(sf org display user --target-org jsforce-test-org --json | jq -r '.result.instanceUrl') \
DISPLAY=:99 CHROME_BIN=$(which chrome) \
npm run test:browser-ci

lint-and-typecheck:
runs-on: ubuntu-latest
Expand All @@ -57,6 +69,8 @@ jobs:
with:
node-version: lts/*

- uses: google/wireit@setup-github-actions-caching/v1

- name: Lockfile lint
run: |
npm install -g lockfile-lint
Expand All @@ -69,7 +83,8 @@ jobs:
- name: Lint and Type Check
run: |
npm run lint
npm run build:types
# TODO: typecheck fails if there is no build, see if tests are importing from lib
npm run build:node:cjs
cristiand391 marked this conversation as resolved.
Show resolved Hide resolved
npm run typecheck

test-node-linux:
Expand All @@ -84,6 +99,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node_version }}
- uses: google/wireit@setup-github-actions-caching/v1

- name: Install dependencies
run: npm install
Expand Down Expand Up @@ -151,6 +167,7 @@ jobs:
# - uses: actions/setup-node@v3
# with:
# node-version: ${{ matrix.node_version }}
# - uses: google/wireit@setup-github-actions-caching/v1
#
# - name: Install dependencies
# run: npm install
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ module
.env
.env*

.wireit
*.tsbuildinfo
.eslintcache


# Dependency directories
node_modules
Expand Down
66 changes: 66 additions & 0 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Getting started

Clone the project and `cd` into it:
```
git clone git@github.com:jsforce/jsforce.git
cd jsforce
iowillhoit marked this conversation as resolved.
Show resolved Hide resolved
```

then install dependencies and build:
```
npm install
npm run build
```

`npm run build` will generate all the distributions for node and browsers:
* Node CJS build (dir: `lib`)
* Browser ESM build (dir: `browser`)
* Browser bundles (dir: `dist`)

# Type-checking

Babel doesn't perform type-checking when transpiling TS to JS, run `npm run typecheck` to validate the code and tests with the TypeScript compiler.

# Linting
Run `npm run lint` to lint the project with ESLint.

# Tests
jsforce has mostly E2E tests, written in TS (file name ends with `test.ts`, use `.ts` for test utils) and are located under the `test` folder.
Keep in mind these tests are executed in a browser and node env, so you have to be careful not to use browser/node-specific code or they will fail, or write node-only tests like this:
https://github.com/jsforce/jsforce/blob/7c8e6a130a149cc7f310e6628f786f94a98c91b9/test/bulk2.test.ts#L136

We run them on latest Chrome and Node (`Current`, `LTS` and `Maintenance` releases) on CI.

## Scratch org setup for testing

> [!NOTE]
> The Salesforce CLI is required for this, install instructions:
>
> https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_install_cli.htm

E2E tests need an org to run tests against, if you have a dev hub and the `sf` CLI you can create a scratch org for testing with the `org-setup` script:

1) Set a default dev hub globally: `sf config set target-dev-hub <hub-username> --global`.
2) Run `npx zx scripts/org-setup.mjs`, if it finishes successfully you'll see the following output:
```
Run tests using this scratch org by appending SF_LOGIN_URL=<login-url> SF_USERNAME=<username> SF_PASSWORD=<password>
```

Set these 3 env vars in you current shell session, tests will use them to establish a connection to the org.

## Running tests on the browser
Due to the Same-origin policy we can't make API requests to Salesforce without a proxy server (REST API supports CORS but jsforce also uses the SOAP API which doesn't), to start the proxy server and run the tests:

1) Set the proxy URL env var: `SF_AJAX_PROXY_URL="http://localhost:3123/proxy"`. If you want to use a different port, use the `PORT` env var and update the URL.
2) Run `npm run test:browser-ci`

This will start a proxy server ([`jsforce-ajax-proxy`](https://github.com/jsforce/jsforce-ajax-proxy)), wait until it is ready and then run `karma start` to launch Chrome and run the tests.
If you host your own proxy server or want to use a 3rd party one set it via `SF_AJAX_PROXY_URL` and run `npm run test:browser` (will only run `karma start`).

We use [`karma`](https://karma-runner.github.io/latest/index.html) as the test runner and [`jasmine`](https://github.com/jasmine/jasmine/) for testing.
`karma` is set up to use `webpack` + `babel` ([`babel-loader`](https://github.com/babel/babel-loader)) to transpile and load TS tests in the browser.

## Running tests on node
Run all tests by running the `npm run test:node` script or pass it a file path if you want to run a specific one, e.g. `npm run test:node -- test/cache.test.ts`.

[`jest`](https://jestjs.io/) is used both as the test runner and testing framework.
21 changes: 2 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

Salesforce API Library for JavaScript applications (both on web browser and Node.js)

[![CircleCI](https://circleci.com/gh/jsforce/jsforce.svg?style=svg)](https://circleci.com/gh/jsforce/jsforce)

## Overview

JSforce (f.k.a. Node-Salesforce) is an isomorphic JavaScript Library utilizing Salesforce's API: It works both in the browser and with Node.js.
Expand Down Expand Up @@ -44,23 +42,8 @@ See [license](LICENSE) (MIT License).

If you have any questions first file it on [issues](https://github.com/jsforce/jsforce/issues) before contacting authors via e-mail.

## Tests

In order to run tests you will need a [Salesforce Developer Org](https://developer.salesforce.com/signup)

You will also need to install the JsforceTestSuite package, which can be done by running:

SF_USERNAME=myusername SF_PASSWORD=password+securityToken ./test/bin/org-setup

You may need to run this more then once if you encounter timeouts or dropped connections/

Finally, to run the tests simply do:

SF_USERNAME=myusername SF_PASSWORD=password+securityToken npm run test:node

SF_USERNAME=myusername SF_PASSWORD=password+securityToken npm run test:browser

Alternatively, if you are using `sfdx` and have a default DevHub set up, you can create a scratch org with all the test setup ready by running `./test/bin/org-setup-sfdx.sh` (it's a bash script and probably won't help most windows users)
## How to build/run tests:
See [DEVELOPING.md](./DEVELOPING.md)

## Contributions

Expand Down
33 changes: 9 additions & 24 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,44 @@ module.exports = {
[
'@babel/preset-env',
{
useBuiltIns: 'usage',
corejs: 3,
targets: { node: '8' },
targets: { node: 18 },
},
],
'@babel/preset-typescript',
],
plugins: [
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-nullish-coalescing-operator',
'@babel/plugin-proposal-class-properties',
cristiand391 marked this conversation as resolved.
Show resolved Hide resolved
[
'@babel/plugin-transform-runtime',
{
corejs: 3,
corejs: "3",
},
],
],
env: {
module: {
presets: [
[
'@babel/preset-env',
{
modules: false,
useBuiltIns: 'usage',
corejs: 3,
targets: { node: '8' },
},
],
'@babel/preset-typescript',
],
},
Copy link
Member Author

Choose a reason for hiding this comment

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

this is the babel config for the node ESM build done by the (now deleted) build:module script:
cross-env BABEL_ENV=module npm run build:src -- -d module

deleted since this was added a few years before package exports so it doesn't work well with newer node, logged W-14321367 to re-enable node ESM builds once Shane finishes his dual-publish work.

browser: {
presets: [
[
'@babel/preset-env',
{
modules: false,
useBuiltIns: 'usage',
corejs: 3,
targets: { browsers: 'last 2 versions, ie 11, not dead' },
corejs: "3.33",
targets: { browsers: 'last 2 versions, not dead, > 0.2%' },
cristiand391 marked this conversation as resolved.
Show resolved Hide resolved
},
],
'@babel/preset-typescript',
],
},
// This env config is used by jest for TS:
// https://jestjs.io/docs/getting-started#using-babel
//
// for type-check run `tsc` before running tests.
Copy link
Member Author

Choose a reason for hiding this comment

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

this is covered in wireit scripts using dependencies.

test: {
presets: [
[
'@babel/preset-env',
{
targets: { node: '8' },
targets: { node: 18 },
iowillhoit marked this conversation as resolved.
Show resolved Hide resolved
},
],
'@babel/preset-typescript',
Expand Down
1 change: 1 addition & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/* global jest */
jest.setTimeout(120000);
jest.retryTimes(3, {logErrorsBeforeRetry: true})
34 changes: 33 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
// Karma configuration

const { readFileSync } = require('fs');
const webpackConfig = require('./webpack.config.test');

// Set BABEL_ENV to use proper preset config
process.env.NODE_ENV = 'test';
process.env.BABEL_ENV = 'test';

module.exports = function (config) {

let specsToRetry;
if (config.retryFailed) {
// Loads names of failed specs and prepares them for use in a regex.
specsToRetry = readFileSync(
'test/karma/karma-failed-tests.txt',
'utf-8'
)
.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')
.replace(/-/g, '\\x2d')
.split('\n')
.join('|');
}

config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',

plugins: [
'karma-webpack',
'karma-jasmine',
'karma-sourcemap-loader',
'karma-jasmine-html-reporter',
'karma-chrome-launcher',
require('./test/karma/karma-failed-tests-reporter.js'),
],

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],
Expand All @@ -30,7 +54,11 @@ module.exports = function (config) {
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['kjhtml', 'progress'],
reporters: ['kjhtml', 'progress','failed-tests'],

failedTestsReporter: {
outputFile: 'test/karma/karma-failed-tests.txt',
},

// web server port
port: 9876,
Expand Down Expand Up @@ -62,6 +90,10 @@ module.exports = function (config) {

// Jasmine Setting
client: {
args: [
specsToRetry && '--grep',
specsToRetry && `/${specsToRetry}/`,
].filter(Boolean),
jasmine: {
random: false,
timeoutInterval: 120000,
Expand Down