-
-
Notifications
You must be signed in to change notification settings - Fork 133
maint(web): re-add engine .js tests 🎼 #15497
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
base: epic/web-core
Are you sure you want to change the base?
Conversation
User Test ResultsTest specification and instructions User tests are not required Test Artifacts
|
39763fc to
677ca5f
Compare
PR #15093 merged multiple engine modules into one. However, in doing so we lost the .js tests and ran only the .ts ones. This change re-adds the .js tests and fixes them where the code diverged since then. Other changes: - rename `queryEngine.ts` to `cloudQueryEngine.ts` to match the class name - remove unused `keyboard-storage/cloud/index.ts` - expose `CLOUD_TIMEOUT_ERR` and `CLOUD_STUB_REGISTRATION_ERR` as `unitTestEndpoints` - add `test/resources` to exports in `web/package.json`. This was necessary because the compiled .ts test files are under `web/build` whereas the .js test files are under `web/src` and so the relative paths in imports no longer work. Also fix the imports in test files. - apply fix from #15477 if KEYMAN_ROOT is not set I'm not happy to put the compiled files under `web/src/test/auto/resources/build`, but that's the only way I got it to work. If I put the compiled files in `web/build/test/resources` it couldn't find the types for `promise-status-async`. Also, running the .js tests succeeded but then creating the coverage report failed. I was not able to find the reason or a fix for that. As a hack to work around this problem we check the number of failed tests instead of relying on the exit code of the test. Follows: #15093 Test-bot: skip
677ca5f to
e2b31c4
Compare
mcdurdin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should have another go at sorting the locations of files. And a few more changes requested. Happy to rubber-ducky if that makes it easier.
| import { CLOUD_TIMEOUT_ERR, CLOUD_STUB_REGISTRATION_ERR } from './cloud/cloudQueryEngine.js'; | ||
|
|
||
| export const unitTestEndpoints = { | ||
| CLOUD_TIMEOUT_ERR, | ||
| CLOUD_STUB_REGISTRATION_ERR | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't feel right. unitTestEndpoints are intended for targets for unit tests, not for sharing variables. There's no need for these to be exported for their usages in unit tests -- they are both used just one time in nodeCloudeRequester.ts (tests):
keyman/web/src/test/auto/resources/loader/nodeCloudRequester.ts
Lines 35 to 38 in 9930a8c
| // Set callback timer | |
| const timeoutObj = setTimeout(() => { | |
| promise.reject(new Error(CLOUD_TIMEOUT_ERR)); | |
| }, 10000); |
keyman/web/src/test/auto/resources/loader/nodeCloudRequester.ts
Lines 58 to 60 in 9930a8c
| if(!promise.isResolved) { | |
| promise.reject(new Error(CLOUD_STUB_REGISTRATION_ERR)); | |
| } |
IMHO, those errors should just be plain strings in the unit testing code -- it's not deployed, there's no localization need, etc, etc. Just KISS. We can then eliminate the messiness of exporting these two constants.
| import { CLOUD_TIMEOUT_ERR, CLOUD_STUB_REGISTRATION_ERR } from './cloud/cloudQueryEngine.js'; | |
| export const unitTestEndpoints = { | |
| CLOUD_TIMEOUT_ERR, | |
| CLOUD_STUB_REGISTRATION_ERR | |
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, inlined those consts.
| # Unfortunately we get an error from the coverage report generation: | ||
| # "TypeError [ERR_INVALID_URL_SCHEME]: The URL must be of scheme file" | ||
| # The following lines ignore the exit code and instead check the number | ||
| # of failed tests from the output. | ||
| set +e | ||
| OUTPUT_FILE=$(mktemp) | ||
| test-headless engine "" 2>&1 | tee "${OUTPUT_FILE}" | ||
| set -e | ||
|
|
||
| FAILURE_COUNT=$(grep ' failing' "${OUTPUT_FILE}" | xargs | cut -f 1 -d' ') | ||
| rm "${OUTPUT_FILE}" | ||
| builder_echo "(The 'TypeError [ERR_INVALID_URL_SCHEME]: The URL must be of scheme file' is expected)" | ||
| if ((FAILURE_COUNT > 0)); then | ||
| builder_die "Headless engine tests failed (.js tests)" | ||
| fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem right. We are running code coverage tests elsewhere just fine.
| import { env } from 'node:process'; | ||
| const KEYMAN_ROOT = env.KEYMAN_ROOT; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import { dirname } from 'node:path'; | ||
|
|
||
| const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
| const KEYMAN_ROOT = env.KEYMAN_ROOT ?? (__dirname + '/../../../../../../../../'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put this into a helper module in keyman/test/resources and avoid repeating it?
PR #15093 merged multiple engine modules into one. However, in doing so we lost the .js tests and ran only the .ts ones. This change re-adds the .js tests and fixes them where the code diverged since then.
Other changes:
queryEngine.tstocloudQueryEngine.tsto match the class namekeyboard-storage/cloud/index.tsCLOUD_TIMEOUT_ERRandCLOUD_STUB_REGISTRATION_ERRasunitTestEndpointstest/resourcesto exports inweb/package.json. This was necessary because the compiled .ts test files are underweb/buildwhereas the .js test files are underweb/srcand so the relative paths in imports no longer work. Also fix the imports in test files.node-keyboard-loader.tswhich was just a wrapper aroundNodeKeyboardLoader.specialized-backspace.tests.jstospecialized-backspace.tests.tsand fixed resulting issues/warnings.I'm not happy to put the compiled files for
test/auto/resourcesunderweb/src/test/auto/resources/build, but that's the only way I got it to work. If I put the compiled files inweb/build/test/resourcesit couldn't find the types forpromise-status-async.Also, running the .js tests succeeded but then creating the coverage report failed. I was not able to find the reason or a fix for that. As a hack to work around this problem we check the number of failed tests instead of relying on the exit code of the test.
Follows: #15093
Test-bot: skip