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

morebits: convert Morebits.wiki.page to use promises #911

Closed
wants to merge 12 commits into from

Conversation

siddharthvp
Copy link
Member

@siddharthvp siddharthvp commented Mar 31, 2020

Includes the commits of pre-requisite #765.

Closes #783.

All functions in Morebits.wiki.page are updated to support promises. The existing callback scheme continues to work. Also, fixes the issues with inconsistency in callback arguments as mentioned in #783.

It's worth noting that after @Amorymeltzer's #712, there is a remarkable structural similarity across most functions.

The stabilize function is untested, as FlaggedRevs is not there on the testwiki, so I have no way to test it.

I've added "tests" as morebits-test-promises.js (last commit). These tests aren't automated - you've copy paste each code chunk to the console to see that that chunk is working as mentioned. Suitable for running on the testwiki only. Converting these to unit tests shouldn't be that difficult, though I couldn't get it right in an hour and a half. Unit tests added, see #911 (comment)

@siddharthvp
Copy link
Member Author

I at last figured out a nice scheme for doing unit testing. Will add the tests in a few days or weeks. Suggest not reviewing this until then, as this would be a lot easier to review then.

@Amorymeltzer
Copy link
Collaborator

Neat! I've been mulling some tests for morebits, it's the only bit that's reasonably amenable to it, but have been preoccupied. I'll be curious to see what you did.

@siddharthvp
Copy link
Member Author

siddharthvp commented Apr 21, 2020

Ok, I've now added the unit tests. How to run:

  • Run npm run server to start up the server. It's a simple Node.js app, server.js.
  • Add mw.loader.load('http://127.0.0.1:5500/twinkle.testloader.js'); in your on-wiki common.js page. (Or just enter that into the console.)
  • Click on the "Run Twinkle unit tests" button at the top. Do this while on a wiki-page that exists (some of the lazily-written tests depend on this.)

Do this on the testwiki, though the tests which create pages also do cleanup after themselves by deleting the pages afterwards. Others edit the user's sandbox. I've created Wikipedia:Twinkle/ExampleNonProtectedPage and Wikipedia:Twinkle/ExampleProtectedPage used in a couple of tests.

We are using browser-based unit testing with the content of workspace files made available in the browser through the localhost server. Any attempt to do node-based unit testing would require trying to replicate the MW environ (mw.config etc etc) which is extremely difficult.

Mocha is used as the testrunner and chai as the assertion library, loaded over CDNs for now. We might as well keep a copies in the repo and load using the server.

All 33 of the tests are passing. Yippee!

@Amorymeltzer
Copy link
Collaborator

Really cool! I'm not particularly familiar with mocha, but this looks pretty great to me. I want to get these out next month, so I'll comment more then, but love it.

I can say from personal experience that trying to replicate the MW environ (mw.config etc etc) is indeed extremely difficult. 😭 😆 😭

@Amorymeltzer
Copy link
Collaborator

Rebased, merged, fixed some errors

Copy link
Collaborator

@Amorymeltzer Amorymeltzer left a comment

Choose a reason for hiding this comment

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

@siddharthvp I don't know what to say on this except it is really very excellent. Promises are probably the hardest thing to wrap my head around, all the more so via jQuery, so I'm really very impressed. The testing regime is great AFAICT, and is a really great start. I'd really like to go further down this road and flesh it out, this is a really nice fire to get going with! And wow does it speed things up! We might need to finally do some purging (e.g. #364) to play catch up.

Unfortunately, I don't think I can merge this. It suffers pretty heavily from the same issue as #1036, where it can redirect to //wiki//wiki//wiki/PAGENAME. Maybe the intersection will help debug both of them, or at least lead us to figure out how to rewrite Morebits.wiki.actionCompleted. Presumably related, but a single tagging can lead to several pairs of "Tagging completed" messages (e.g. three pairs).

ctx.statusElement.error('Internal error: attempt to save a page that has not been loaded!');
ctx.onSaveFailure(this);
return;
return returnError.call(this, 'int-notloaded', 'Internal error: attempt to save a page that has not been loaded!');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Guessing this stands for "internal"? Unimportant to do here, but down the line I think it'd do better with "morebits-" or at least "mb-", then eventually document them somewhere.

// We don't really care about the response
wikipedia_api.post();
} else {
return $.Deferred().rejectWith(this, [this, 'missingparam', 'No rcid available']);
Copy link
Collaborator

Choose a reason for hiding this comment

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

@siddharthvp siddharthvp mentioned this pull request Oct 9, 2020
siddharthvp added a commit to siddharthvp/twinkle that referenced this pull request Nov 26, 2020
The server.js file from wikimedia-gadgets#911. No dependencies. While it's possible to set up a server using `php -S` and `python -m SimpleHTTPServer` etc, putting it in package.json means IDEs can provide a one-click button for running it.
@siddharthvp siddharthvp mentioned this pull request Nov 26, 2020
siddharthvp added a commit that referenced this pull request Nov 28, 2020
The server.js file from #911. No dependencies. While it's possible to set up a server using `php -S` and `python -m SimpleHTTPServer` etc, putting it in package.json means IDEs can provide a one-click button for running it.
siddharthvp added a commit to siddharthvp/twinkle that referenced this pull request Dec 12, 2020
Needed for taskManager to know when the logging has finished in promise-based rewrites. Resolves the kludge in twinkleprod.

Of course this would have been much simpler if Morebits.wiki.page methods themselves returned promises (wikimedia-gadgets#911).
@siddharthvp
Copy link
Member Author

This is hopeless. I haven't really tested again, but it seems the way to go ahead with this is to not use Morebits.wiki.actionCompleted.* The alternative to that is Morebits.taskManager(), which requires tasks to return promises in the first place. $.Deferred()s could be used for that. But still it involves refactoring every single module. And we're talking about refactoring within this twinkle, as if all the refactoring needed for the twinkle-core effort wasn't enough. All the merge conflicts which have accumulated in the meanwhile aren't helping as well. The #1029 path appears much more appealing – no burden of backward compatibility.

Looks like this can be closed, unless @Amorymeltzer you have ideas on getting actionCompleted to work alongside promises.

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

Successfully merging this pull request may close these issues.

Morebits.wiki.page: overhaul callback arguments and enable use of promises
2 participants