amtrack / sfdx-browserforce-plugin

sfdx plugin for browser automation
MIT License
109 stars 37 forks source link

Writing a new plugin, struggling with the e2e tests #560

Closed jonathankretzmer closed 1 year ago

jonathankretzmer commented 1 year ago

We need to be able to set the Org currency as the scratch org default, based on our hosting location, defaults to Ireland Euro. So I have created a plugin allowing changing fields on the Company Information section in Setup.

I am struggling with the last part of executing my e2e mocha tests.

When running the command npm run test:e2e -- --grep "CompanyInformation" it correctly finds and executes the tests in my file, but comes back with errors.

CompanyInformation
       should change currency to "English (Ireland) - EUR":
     TypeError: Cannot read properties of null (reading 'toString')
      at Context.<anonymous> (src\plugins\company-information\index.e2e-spec.ts:34:58)
      at processImmediate (node:internal/timers:476:21)

The .status and .output from the spawnSync are null.

Would appreciate pointing me in the right direction to finalise this.

Thanks.

amtrack commented 1 year ago

@jonathankretzmer Yes, I can have a look. Would you mind sharing your code?

jonathankretzmer commented 1 year ago

Not at all, here is my latest branch: https://github.com/jonathankretzmer/sfdx-browserforce-plugin/tree/dev/plugin-CompanyInformation/src/plugins/company-information

amtrack commented 1 year ago

@jonathankretzmer Looks good so far.

Here's what fixes the test:

On branch dev/plugin-CompanyInformation

    test: escape parentheses in RegEx

diff --git a/src/plugins/company-information/index.e2e-spec.ts b/src/plugins/company-information/index.e2e-spec.ts
index 20d2f12..efd5db5 100644
--- a/src/plugins/company-information/index.e2e-spec.ts
+++ b/src/plugins/company-information/index.e2e-spec.ts
@@ -18,7 +18,7 @@ describe(CompanyInformation.name, function () {
     ]);
     assert.deepStrictEqual(apply.status, 0, apply.output.toString());
     assert.ok(
-      /to '"English (South Africa) - ZAR"'/.test(apply.output.toString()),
+      /to '"English \(South Africa\) - ZAR"'/.test(apply.output.toString()),
       apply.output.toString()
     );
   });
@@ -32,7 +32,7 @@ describe(CompanyInformation.name, function () {
     ]);
     assert.deepStrictEqual(apply.status, 0, apply.output.toString());
     assert.ok(
-      /to '"English (Ireland) - EUR"'/.test(apply.output.toString()),
+      /to '"English \(Ireland\) - EUR"'/.test(apply.output.toString()),
       apply.output.toString()
     );
   });
jonathankretzmer commented 1 year ago

But of course that makes sense, hahah. Thanks :) Will submit a PR for this shortly.

jonathankretzmer commented 1 year ago

I found the root cause of my issue. It relates to the bin/run executable, on Windows I had to use bin/run.cmd.