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

Log errors thrown when filling a form #217

Merged
merged 8 commits into from
May 8, 2023

Conversation

KicaRonaldOkello
Copy link

This PR ensures that errors thrown during filling a form a displayed in the terminal in a readable format.

@KicaRonaldOkello KicaRonaldOkello marked this pull request as ready for review March 31, 2023 14:53
@KicaRonaldOkello KicaRonaldOkello force-pushed the log-errors-when-filling-form branch 2 times, most recently from 8878a88 to fa490f4 Compare April 6, 2023 15:04
Copy link
Member

@kennsippell kennsippell left a comment

Choose a reason for hiding this comment

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

great start here! nice work

src/harness.js Show resolved Hide resolved
@@ -9,6 +9,7 @@ on:
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 30
Copy link
Member

Choose a reason for hiding this comment

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

nice

Copy link
Member

@kennsippell kennsippell left a comment

Choose a reason for hiding this comment

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

one more minor tweak it seems

@@ -276,4 +276,11 @@ describe('forms that have caused bugs', () => {
const bikramDate = await harness.page.evaluate(() => window.$$('[data-itext-id="/pregnancy/summary/r_pregnancy_details:label"]').text());
expect(bikramDate).to.include('महिनावारी भएको अन्तिम मिति : १५ कारà¥');
});
it('should log error thrown during filling an app form', async () => {
try {
await harness.fillForm('mother_name', ['Jane"s']);
Copy link
Member

Choose a reason for hiding this comment

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

this test will pass even if an error is not thrown

Copy link
Member

Choose a reason for hiding this comment

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

@@ -188,4 +188,11 @@ describe('contact forms', () => {
reported_date: now.valueOf()
});
});
it('should log error thrown during filling a contact form', async () => {
try {
await harness.fillContactCreateForm('household', ['Peter"s']);
Copy link
Member

Choose a reason for hiding this comment

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

same as above

@@ -188,4 +188,11 @@ describe('contact forms', () => {
reported_date: now.valueOf()
});
});
it('should log error thrown during filling a contact form', async () => {
try {
await harness.fillContactCreateForm('household', ['Peter"s']);
Copy link
Member

Choose a reason for hiding this comment

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

i like that you re-used an existing form here. is that not possible for the app-forms test? less to maintain if we don't add a new form

Copy link
Author

Choose a reason for hiding this comment

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

It is not possible for 2 reasons.

  • When attempting to use the same form for the app-forms test, an error occurs because it is located in the contact forms folder rather than the app forms folder.
  • Currently, none of the existing app forms are suitable for testing this particular scenario.
    @kennsippell

Copy link
Member

@kennsippell kennsippell left a comment

Choose a reason for hiding this comment

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

Nice progress.

package.json Outdated
@@ -12,6 +12,7 @@
"travis": "npm run build && npm run eslint && npm test"
},
"dependencies": {
"chai-as-promised": "^7.1.1",
Copy link
Member

Choose a reason for hiding this comment

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

this should be a devDependency not a dependency since it is not required
https://docs.npmjs.com/specifying-dependencies-and-devdependencies-in-a-package-json-file

const fillResult = await this.page.evaluate(async innerAnswer => await window.formFiller.fillAppForm(innerAnswer), answers);
const fillResult = await this.page.evaluate(async innerAnswer => {
try {
return await window.formFiller.fillAppForm(innerAnswer);
Copy link
Member

Choose a reason for hiding this comment

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

sorry for the late feedback on this one: but i'm a little unsure on the value we are adding here... why catch an exception to just rethrow it? what problem are we solving?

Copy link
Author

Choose a reason for hiding this comment

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

If we don't catch the exception, we see a confusing error in the stack trace like

Error: Evaluation failed: FormLogicError
at ExecutionContext._evaluateInternal (node_modules/puppeteer-core/lib/cjs/puppeteer/common/ExecutionContext.js:221:19)
at process._tickCallback (internal/process/next_tick.js:68:7)

When we catch and rethrow, the error in the stack trace makes more sense for the user like

Error: Evaluation failed: Error: Error encountered while filling form: FormLogicError: Could not evaluate: concat(../mother_name, ' baby'), message: Failed to execute 'evaluate' on 'Document': The string 'concat("Jane"s", " baby")' is not a valid XPath expression.

Copy link
Member

Choose a reason for hiding this comment

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

can your test also make an assertion about not just the boilerplate you're adding but also the more descriptive error message like 'error.includes('mother_name')`?

@kennsippell
Copy link
Member

  • Why is the base branch for this 2.x? Is this needed in 3.x?
  • Can you investigate why tests are failing?

@KicaRonaldOkello
Copy link
Author

  • Why is the base branch for this 2.x? Is this needed in 3.x?
  • Can you investigate why tests are failing?

The error does not exist in 3.x, only 2.x

@kennsippell
Copy link
Member

Please run npm version patch before you commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants