Skip to content

Commit 88165ed

Browse files
authored
test: add nuts (#34)
* feat: add nutcase * fix: add logging for json parsing errors * chore: rename Nutcase to NutButter * test: finish up sourcepath, metadata, and manifest deploy tests * test: still working on deploy nuts * test: getting nutty * test: NutButter -> Nutshell * test: finish deploy tests * test: split nuts * test: wip * test: improve flakiness * test(wip): retrieve nuts * test(wip): retrieve packagenames test * test(wip): add packagenames test * test: consolidate retrieve seeds * chore: code review * test: add convert seed * test: wip * test: improve test matrix * test: add another test for deploy.metadata * test(wip): stop relying on json * test(wip): stop relying on push json * test(wip): stop relying on convert json * test(wip): stop relying on retrieve json * test(wip): use SourceMembers for deploy assertions * test(wip): stop relying on pull json * test(wip): clean up * test(wip): more clean up * test: get dreamhouse-sfdx to pass * chore: code review * chore: use new mpd repo * test: add mpd tests * test: remove pointless tests * chore: fix spelling * chore: bump testkit * test: fix deploy.testlevel * test: add --ignoreerrors flag to quick deploy test
1 parent 2de3f21 commit 88165ed

35 files changed

+2928
-438
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ lib
2020
*unitcoverage
2121
.nyc_output
2222
coverage
23+
test_session*
2324

2425
# generated docs
2526
docs
@@ -38,3 +39,6 @@ node_modules
3839
# os specific files
3940
.DS_Store
4041
.idea
42+
43+
# ignore generated nut tests
44+
test/nuts/generated/

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# ignore generated nut tests
2+
test/nuts/generated/

package.json

+19-8
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,22 @@
1515
"devDependencies": {
1616
"@oclif/dev-cli": "^1",
1717
"@oclif/plugin-command-snapshot": "^2.0.0",
18-
"@salesforce/cli-plugins-testkit": "^0.0.8",
18+
"@salesforce/cli-plugins-testkit": "^0.0.15",
1919
"@salesforce/dev-config": "^2.1.0",
20-
"@salesforce/dev-scripts": "^0.7.0",
20+
"@salesforce/dev-scripts": "^0.9.1",
21+
"@salesforce/plugin-apex": "^0.1.18",
2122
"@salesforce/plugin-command-reference": "^1.3.0",
23+
"@salesforce/plugin-config": "^1.2.6",
2224
"@salesforce/prettier-config": "^0.0.2",
2325
"@salesforce/ts-sinon": "1.3.0",
26+
"@types/debug": "^4.1.5",
27+
"@types/shelljs": "^0.8.8",
2428
"@typescript-eslint/eslint-plugin": "^4.2.0",
2529
"@typescript-eslint/parser": "^4.2.0",
2630
"chai": "^4.2.0",
31+
"chai-each": "^0.0.1",
2732
"cz-conventional-changelog": "^3.3.0",
33+
"debug": "^4.3.1",
2834
"eslint": "^6.8.0",
2935
"eslint-config-prettier": "^6.11.0",
3036
"eslint-config-salesforce": "^0.1.0",
@@ -34,12 +40,14 @@
3440
"eslint-plugin-import": "^2.20.2",
3541
"eslint-plugin-jsdoc": "^27.0.3",
3642
"eslint-plugin-prettier": "^3.1.3",
43+
"fast-glob": "^3.2.5",
3744
"husky": "^4.2.5",
3845
"lint-staged": "^10.2.2",
39-
"mocha": "^7.2.0",
46+
"mocha": "^8.3.0",
4047
"nyc": "^15.1.0",
4148
"prettier": "^2.0.5",
4249
"pretty-quick": "^2.0.1",
50+
"shelljs": "^0.8.4",
4351
"shx": "0.3.3",
4452
"sinon": "^9.0.2",
4553
"ts-node": "^8.10.2",
@@ -71,9 +79,11 @@
7179
"commands": "./lib/commands",
7280
"bin": "sfdx",
7381
"devPlugins": [
74-
"@oclif/plugin-help",
7582
"@oclif/plugin-command-snapshot",
76-
"@salesforce/plugin-command-reference"
83+
"@oclif/plugin-help",
84+
"@salesforce/plugin-command-reference",
85+
"@salesforce/plugin-apex",
86+
"@salesforce/plugin-config"
7787
],
7888
"topics": {
7989
"force": {
@@ -90,21 +100,22 @@
90100
"scripts": {
91101
"build": "sf-build",
92102
"clean": "sf-clean",
93-
"clean-all": "-clean all",
103+
"clean-all": "sf-clean all",
94104
"clean:lib": "shx rm -rf lib && shx rm -rf coverage && shx rm -rf .nyc_output && shx rm -f oclif.manifest.json",
95105
"compile": "sf-compile",
96106
"docs": "sf-docs",
97107
"format": "sf-format",
98108
"lint": "sf-lint",
99109
"postpack": "shx rm -f oclif.manifest.json",
100110
"posttest": "yarn lint && yarn test:deprecation-policy && yarn test:command-reference",
101-
"prepack": "sf-build",
111+
"prepack": "sf-prepack",
102112
"prepare": "sf-install",
103113
"pretest": "sf-compile-test",
104114
"test": "sf-test",
105115
"test:command-reference": "./bin/run commandreference:generate --erroronwarnings",
106116
"test:deprecation-policy": "./bin/run snapshot:compare",
107-
"version": "oclif-dev readme && git add README.md"
117+
"test:nuts": "ts-node ./test/nuts/generateNuts.ts && nyc mocha \"**/*.nut.ts\" --slow 3000 --timeout 600000 --parallel --retries 1",
118+
"version": "oclif-dev readme"
108119
},
109120
"husky": {
110121
"hooks": {

src/commands/force/source/deploy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { SourceCommand } from '../../../sourceCommand';
1717
Messages.importMessagesDirectory(__dirname);
1818
const messages = Messages.loadMessages('@salesforce/plugin-source', 'deploy');
1919

20-
export class deploy extends SourceCommand {
20+
export class Deploy extends SourceCommand {
2121
public static readonly description = messages.getMessage('description');
2222
public static readonly examples = messages.getMessage('examples').split(os.EOL);
2323
public static readonly requiresProject = true;

test/commands/source/deploy.nut.ts

-81
This file was deleted.

test/commands/source/retrieve.nut.ts

-81
This file was deleted.

test/nuts/README.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# plugin-source NUTs
2+
3+
In testing the source commands, we have 2 significant problems that needs to be solved:
4+
5+
1. How do we test the commands across the old code (force-com-toolbelt) and the new code (plugin-source)?
6+
2. How do we test the commands across a variety of sfdx projects and metadata?
7+
8+
These problems are solved by generating `.nut.ts` files from `.seed.ts` files using the test matrix exported by `testMatrix.ts`
9+
10+
In practice this means that we generate a `.nut.ts` file for every executable and test repository combination based on the `.seed.ts`. For instance, if we have 5 seeds and if we have 3 test repositories defined in the test matrix, we will generate 30 nuts: 5 seeds * 3 repos * 2 executables (`sfdx` and `bin/run`)
11+
12+
By generating nuts we also maintain the ability the parallelize them since mocha parallelizes tests at the file level. So now we can run those 30 nuts in parallel instead of running them one at a time, which is a huge performance advantage.
13+
14+
However, since we're running the exact same tests on a variety of repositories with different metadata, we have to configure certain aspects so that the tests are meaningful. All the possible configuration is documented in `testMatrix.ts`.
15+
16+
It also means that we're relatively limited in what we can test. For example, it doesn't make sense to write complicated multiple package directory (MPD) tests for repositories that do not have multiple package directories. So that means that the seeds are best used as high-level smoke tests that simply run through the most common use cases and verify json output. **Because of this, we are not locked into to only writing seeds**. It is still entirely possible to write a new `.nut.ts` that lives outside of the test matrix framework.
17+
18+
## Environment Variable Reference
19+
| Name | Description | Default |
20+
|----------------------------|-----------------------------------------------------------|---------|
21+
| PLUGIN_SOURCE_SEED_FILTER | substring of seeds you want to generate | NA |
22+
| PLUGIN_SOURCE_TEST_BIN_RUN | set to true if you want to include the bin/run executable | false |
23+
| PLUGIN_SOURCE_TEST_SFDX | set to true if you want to include the sfdx executable | true |
24+

0 commit comments

Comments
 (0)