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, TESTING] Test code can run form the front-end in all languages #3822

Merged
merged 16 commits into from
Mar 23, 2023

Conversation

TiBiBa
Copy link
Collaborator

@TiBiBa TiBiBa commented Dec 9, 2022

Verify that the code can be ran in all languages:

This PR fixes #3760

@TiBiBa TiBiBa marked this pull request as draft December 9, 2022 11:44
@Felienne
Copy link
Member

Hi @TiBiBa!

I think we said in the meeting that we'd close this and do the testing of the run button in a "manual" way, right (by repeatedly 'clicking' a language and then the run button)

@martinj2001 martinj2001 self-requested a review February 2, 2023 15:06
@martinj2001 martinj2001 marked this pull request as ready for review February 2, 2023 15:06
@martinj2001
Copy link
Contributor

@TiBiBa I think I fixed your problems with this tests, let me know if there is more to fix!

@jpelay jpelay self-assigned this Feb 16, 2023
@jpelay jpelay marked this pull request as draft February 18, 2023 17:55
@jpelay
Copy link
Member

jpelay commented Feb 18, 2023

Hello everyone! I'm turning this into a draft while we keep working on it!

@ghost
Copy link

ghost commented Feb 28, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

@jpelay jpelay marked this pull request as ready for review February 28, 2023 17:01
@jpelay
Copy link
Member

jpelay commented Feb 28, 2023

Hello, everyone! I made a few changes to the test so it can run in every language!

@Felienne
Copy link
Member

Maybe @TiBiBa can take a look? 🙏

Copy link
Member

@Felienne Felienne left a comment

Choose a reason for hiding this comment

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

Hi @jpelay

I tried to test the tests as follows, but it seems to still work?

  1. Break a print keyword, f.e. in French:

_PRINT: ("affiche" | "prt") _SPACE?

  1. Be sure to not rerun on-deploy.sh or it will restore the grammar!

  2. Observe the app is now broken:

image

  1. But the tests still passes:

image

@Felienne Felienne changed the title Make editor box test non english dependent [CHORE, TESTING] Test code can run form the front-end in all languages Mar 8, 2023
@jpelay
Copy link
Member

jpelay commented Mar 10, 2023

Hi @Felienne! Thank you for pointing it out!

It does seem like the page is refreshing, but the language is not changing? This one was supposed to show content from Bulgarian (notice that switch-language-bg was selected, but instead is still showing content from Arabic. It does appear that after changing the language once, that one keeps locked!

image

@Felienne
Copy link
Member

Hi @jpelay!!

I might have a hunch as to why this does not test all languages!!! (@rix0rrr gave me the idea)

The current language is not present in the dropdown, so if you start with the first one (Arabic) will be selected:

image

Then we pick the second one, Bulgarian:

image

Now... the next one is Bengali:

image

This might mean we are skipping languages (I am not sure) So we first need to populate a stable list of languages and iterate over these.

@jpelay
Copy link
Member

jpelay commented Mar 13, 2023

It might be, but I'm actually iterating trhough the list of languages, and clicking each one individually. Each language have their own id, so you can select then individually!

@Felienne
Copy link
Member

It might be, but I'm actually iterating trhough the list of languages, and clicking each one individually. Each language have their own id, so you can select then individually!

Ah ok.... then it is probably something else!

@jpelay
Copy link
Member

jpelay commented Mar 14, 2023

I'm still kinda blocked here, but found out something. This is how the logs look after printing g.lang in each setup_language. Here the first language, ar, have already been selected and processed and we're onto the next language, bg, the section with ### is in change_language so the language is being changed, and the section with *** is in each setup_language:

####################################################################################################
bg
####################################################################################################
[2023-03-14 11:45:05,153] app.py teardown_request_finish_logging 320 <DEBUG>: {'path': '/change_language', 'method': 'POST', 'remote_ip': '127.0.0.1', 'user_agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Cypress/12.0.2 Chrome/106.0.5249.51 Electron/21.0.0 Safari/537.36', 'start_time': '2023-03-14T15:45:05.152911Z', 'pid': 6373, 'loadavg': 0.73, 'fault': 0, 'http_code': 200, 'end_time': '2023-03-14T15:45:05.153467Z', 'user_ms': 0, 'sys_ms': 0, 'max_rss': 66756, 'inc_max_rss': 0, 'duration_ms': 0}
[2023-03-14 11:45:05,153] _internal.py _log 113 <INFO>: 127.0.0.1 - - [14/Mar/2023 11:45:05] "POST /change_language HTTP/1.1" 200 -
****************************************************************************************************
ar
****************************************************************************************************
[2023-03-14 11:45:05,194] app.py teardown_request_finish_logging 320 <DEBUG>: {'path': '/hedy', 'method': 'GET', 'remote_ip': '127.0.0.1', 'user_agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Cypress/12.0.2 Chrome/106.0.5249.51 Electron/21.0.0 Safari/537.36', 'start_time': '2023-03-14T15:45:05.175177Z', 'pid': 6373, 'loadavg': 0.73, 'fault': 0, 'load_yaml_pickled_ms': 0, 'load_yaml_pickled_cnt': 5, 'render_template_ms': 6, 'render_template_cnt': 1, 'http_code': 200, 'end_time': '2023-03-14T15:45:05.194598Z', 'user_ms': 19, 'sys_ms': 0, 'max_rss': 66864, 'inc_max_rss': 108, 'duration_ms': 19}
[2023-03-14 11:45:05,195] _internal.py _log 113 <INFO>: 127.0.0.1 - - [14/Mar/2023 11:45:05] "GET /hedy HTTP/1.1" 200 -
****************************************************************************************************
bg
****************************************************************************************************
[2023-03-14 11:45:05,819] app.py teardown_request_finish_logging 320 <DEBUG>: {'path': '/vendor/skulpt.min.js.map', 'method': 'GET', 'remote_ip': '127.0.0.1', 'user_agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Cypress/12.0.2 Chrome/106.0.5249.51 Electron/21.0.0 Safari/537.36', 'start_time': '2023-03-14T15:45:05.817109Z', 'pid': 6373, 'loadavg': 0.73, 'fault': 0, 'render_template_ms': 0, 'render_template_cnt': 1, 'http_code': 404, 'end_time': '2023-03-14T15:45:05.819514Z', 'user_ms': 2, 'sys_ms': 0, 'max_rss': 66896, 'inc_max_rss': 0, 'duration_ms': 2}
[2023-03-14 11:45:05,819] _internal.py _log 113 <INFO>: 127.0.0.1 - - [14/Mar/2023 11:45:05] "GET /vendor/skulpt.min.js.map HTTP/1.1" 404 -
****************************************************************************************************
bg
****************************************************************************************************
[2023-03-14 11:45:05,872] app.py teardown_request_finish_logging 320 <DEBUG>: {'path': '/js/appbundle.js.map', 'method': 'GET', 'remote_ip': '127.0.0.1', 'user_agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Cypress/12.0.2 Chrome/106.0.5249.51 Electron/21.0.0 Safari/537.36', 'start_time': '2023-03-14T15:45:05.871905Z', 'pid': 6373, 'loadavg': 0.73, 'fault': 0, 'http_code': 200, 'end_time': '2023-03-14T15:45:05.872597Z', 'user_ms': 0, 'sys_ms': 0, 'max_rss': 66896, 'inc_max_rss': 0, 'duration_ms': 0}
[2023-03-14 11:45:05,872] _internal.py _log 113 <INFO>: 127.0.0.1 - - [14/Mar/2023 11:45:05] "GET /js/appbundle.js.map HTTP/1.1" 200 -
****************************************************************************************************
bg
****************************************************************************************************
[2023-03-14 11:45:07,231] app.py teardown_request_finish_logging 320 <DEBUG>: {'path': '/parse', 'method': 'POST', 'remote_ip': '127.0.0.1', 'user_agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Cypress/12.0.2 Chrome/106.0.5249.51 Electron/21.0.0 Safari/537.36', 'start_time': '2023-03-14T15:45:06.103452Z', 'pid': 6373, 'loadavg': 0.73, 'fault': 0, 'level': 1, 'lang': 'ar', 'session_id': '72809ae8a04d4d18a8489bbcccfb6365', 'username': None, 'db_update:program-stats': 1, 'db_update_ms': 2, 'db_update_cnt': 1, 'transpile_ms': 508, 'transpile_cnt': 1, 'server_error': None, 'http_code': 200, 'end_time': '2023-03-14T15:45:07.231256Z', 'user_ms': 1126, 'sys_ms': 0, 'max_rss': 67408, 'inc_max_rss': 512, 'duration_ms': 1127}
[2023-03-14 11:45:07,231] _internal.py _log 113 <INFO>: 127.0.0.1 - - [14/Mar/2023 11:45:07] "POST /parse HTTP/1.1" 200 -
****************************************************************************************************
bg
****************************************************************************************************
[2023-03-14 11:45:07,306] app.py teardown_request_finish_logging 320 <DEBUG>: {'path': '/vendor/skulpt-stdlib-extensions.js', 'method': 'GET', 'remote_ip': '127.0.0.1', 'user_agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Cypress/12.0.2 Chrome/106.0.5249.51 Electron/21.0.0 Safari/537.36', 'start_time': '2023-03-14T15:45:07.305516Z', 'pid': 6373, 'loadavg': 0.73, 'fault': 0, 'http_code': 304, 'end_time': '2023-03-14T15:45:07.305984Z', 'user_ms': 0, 'sys_ms': 0, 'max_rss': 67408, 'inc_max_rss': 0, 'duration_ms': 0}
[2023-03-14 11:45:07,306] _internal.py _log 113 <INFO>: 127.0.0.1 - - [14/Mar/2023 11:45:07] "GET /vendor/skulpt-stdlib-extensions.js HTTP/1.1" 304 -
****************************************************************************************************

Notice how the only path that retains the language ar is in the path /hedy, and that is try for every language!

@Felienne
Copy link
Member

Yes so that does look suspiciously like it is trying the first language (ar) and then the first one again (bg) and then again the first one (ar)!

@jpelay
Copy link
Member

jpelay commented Mar 14, 2023

Somehow is working now, after changing... nothing

image

@rix0rrr
Copy link
Collaborator

rix0rrr commented Mar 18, 2023

I changed the premise a little, maybe this is a cheat technique that might help!

image

There are three things I did:

  • First, we need to get a list of languages "from somewhere". For now, I hardcoded a list into the source. Potentially you could generate a JSON file with list of languages at build time or something, and have cy.readFile() read that list.
  • Then, I generate a test for every language in that list. By doing a for loop, and calling it('...', () => { .. }) inside the for loop, we get a new test for every language in the list.
  • Finally, to make it easy to switch to a particular language without using the UI (cheating, I know), I added the ability to force the current language to a particular language by passing the query argument ?language=. So if you add ?language=fr to a URL, it will immediately cause a switch to French.

Does this help as a start? Up to you to finish it by finding a way to get the list of languages in Cypress (potentially copy/paste might even be good enough for a bit...?) and making the test check what you want it to.


If you want to do multiple tests per language, it might even be nicer to put the for loop around the describe. Do something like:

const LANGUAGES_TO_TEST = [ /* ... */ ];

for (const language of LANGUAGES_TO_TEST) {

  describe(`in the language ${language}`, () => {
    it('is possible to run a program', () => { ... });

    it('is possible to do something else', () => { ... });
  });
}

For some reason, this for loop that creates closures closing over the loop variable worked "as you'd expect" the first time for me (in fact, I didn't even think twice about it), but it might be a little dangerous nevertheless. Traditionally, there can be problems if you create a closure that refers to a loop variable. This Stack Overflow post might be good to have a read through so that you can recognize the problem quickly if you ever run into it.

An easy fix if we are uneasy might be:

for (const x of LANGUAGES_TO_TEST) {
  const language = x; // Make a fresh variable for every loop iteration

  // ...
}

Although it just might be that declaring the loop variable const is 100% guaranteed to be good enough.

@reedspool
Copy link
Collaborator

@rix0rrr below is not a response about your for loop strategy. I think you just nailed it your first time and no more changes are necessary but good to keep everyone aware of that sticky JS confusion!

I followed my (and Felienne's) suspicions about the for loop during the collaborator meeting. I just did a quick search for loop cypress testing and happened to find this SO answer with a comment that confirms those suspicions.

Tl;dr: this problem is exactly what cy.each solves. See that answer and that those docs and if you still have questions about how to proceed I'd be happy to look further!

This is of course if we are not satisfied with @rix0rrr 's solid approach! That seems like a very reasonable tactic!

@rix0rrr
Copy link
Collaborator

rix0rrr commented Mar 19, 2023

@reedspool that SO post seems to be about using loops inside the test, vs what this code is doing which is creating multiple tests at module load time.

But it might be you are referring back to a discussion I wasn’t part of?

@jpelay
Copy link
Member

jpelay commented Mar 20, 2023

Hi! @rix0rrr and @reedspool!

@reedspool I quickly tried the SO approach about wrapping the array and running each but it still didn't work.
@rix0rrr I tried yours and it ineed is a good start! I will work on this further.

Thanks to both of you for the help!

@reedspool
Copy link
Collaborator

Glad you've got a good path forward @jpelay!

@rix0rrr Yes sorry about the confusion, I was continuing on thoughts we shared at the last Collaborators meeting.

@jpelay
Copy link
Member

jpelay commented Mar 22, 2023

Hi all!! @Felienne I added the languages to test just hard coding there in the test. I will improve this once we tackle the test for the pygame features. But it now works! I edited keywords-es.lark and it fails.

image

Thanks @rix0rrr and @reedspool again for the help offered!

@Felienne
Copy link
Member

OMG what a tour de force this was!! So happy it is working now. I made an issue for the hard-coded list of languages, just so we don't forget: #4168

@mergify
Copy link
Contributor

mergify bot commented Mar 23, 2023

Thank you for contributing! Your pull request is now going on the merge train (choo choo! Do not click update from main anymore, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit a75cd70 into main Mar 23, 2023
@mergify mergify bot deleted the make_editor_box_test_non_english_dependent branch March 23, 2023 08:43
@mergify
Copy link
Contributor

mergify bot commented Mar 23, 2023

Thank you for contributing! Your pull request is now going on the merge train (choo choo! Do not click update from main anymore, and be sure to allow changes to be pushed to your fork).

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.

[CYPRESS] Test run button in non-English too
6 participants