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

change(web): config, sourcemap cleanup + adds some c8 reporting 🧩 #8995

Merged
merged 16 commits into from
Jun 19, 2023

Conversation

jahorton
Copy link
Contributor

Tackles a few small points and one maybe-medium point:

  1. I've been noticing some noise and inconsistencies with the reported path locations for original sourcefiles in the output sourcemaps. For example, sometimes subdirectories of the main src/ would get duplicated in said paths. It turns out that this was due to use of the sourceRoot config option in some of the TS config files; removing it prevents that duplication.

  2. When viewing KMW's source in developer mode, the layout of the sources didn't quite match the repository layout. We can workaround it by setting the esbuild sourceRoot to a higher-level directory for the repo or similar. This is now fixed:

image

At one point, I thought about having it set with this repository's URL as the effective root, so that the paths would reflect their in-repo locations. Once I realized that it'd be far to tricky to point to a specific tag or similar - instead, always pointing to the master version, I reconsidered.

I'd be perfectly happy to change the name on that root if desired.

  1. Noting some of the recent use of c8 within the kmc in-repo project, I decided to try it out with Web and its submodules - and for most headless cases, I was able to get it working! It only generates reports for us; it won't cause any failing builds at this time.

common/web/keyboard-processor:

image

common/models/wordbreakers:

image

common/models/templates:

image

common/web/lm-worker:

image

web/src/engine/package-cache:

image

I was pretty pleasantly surprised to see the numbers this high on these components!

Unfortunately, I ran into a blocker for doing this when headless integration tests involving both the main thread and the worker were involved - thus, common/web/input-processor and common/predictive-text do not generate reports at this time. I know how to bypass the issue and get reports manually upon request, though.

I submitted an issue at bcoe/c8#477 for the problem I ran into; my hacky 'bypass' is mentioned there too. As it requires editing one of the c8 package's scripts directly, I don't consider the 'bypass' viable as a workaround at this time.

Using the bypass:

common/web/input-processor:

image

This makes sense; the automated tests here mostly exist to ensure integration with the worker isn't broken.

common/predictive-text:

image

@eddieantonio was quite thorough with establishing unit tests when we were collaborating on the predictive-text feature's development, and it shows - both here and in all the other component packages listed above. (Many thanks!)

While I did experiment a bit with attempting cross-project coverage... that got messy very quickly, so I backed out of it for now. I can tell that c8 does have some sort of internal report-merging mechanism, and it would be nice to leverage that, but it's not currently worth the time investment required.

Additionally, this had the fortunate benefit of helping me to discover and resolve some previously-uncaught sourcemap issues.

  1. The lm-worker project no longer needs the 'sourcemap remapper' tool I previously wrote. The path-mapping is now handled far more cleanly than before.

@keymanapp-test-bot skip

@jahorton jahorton added this to the A17S15 milestone Jun 12, 2023
@jahorton jahorton requested a review from mcdurdin as a code owner June 12, 2023 07:45
Copy link
Member

@mcdurdin mcdurdin left a comment

Choose a reason for hiding this comment

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

This is looking good. Just one request: can we consolidate on the package.json scripts stuff -- so npm run <foo> always calls into gosh ./build.sh foo, like we have started doing for npm run build?

Comment on lines 46 to 50
"build": "gosh ./build.sh",
"tsc": "tsc",
"mocha": "mocha",
"test": "mocha -r test/helpers.js"
"test": "mocha -r test/helpers.js",
"c8": "c8"
Copy link
Member

Choose a reason for hiding this comment

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

Can we make these use build.sh, and then we don't need tsc, mocha, or c8 scripts also:

"test": "gosh ./build.sh test"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't even notice the test bit.

That said, I like having tsc, mocha and the like so I can directly run those calls on occasion outside of build.sh scripts. I definitely use this from time to time with mocha (and karma for DOM-reliant Web components).

Copy link
Member

Choose a reason for hiding this comment

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

You can of course do $KEYMAN_ROOT/node_modules/.bin/tsc etc (or even add your node_modules/.bin to your path)

common/models/wordbreakers/package.json Outdated Show resolved Hide resolved
common/web/keyboard-processor/package.json Outdated Show resolved Hide resolved
common/web/lm-worker/package.json Outdated Show resolved Hide resolved
common/web/utils/package.json Outdated Show resolved Hide resolved
@@ -1,6 +1,6 @@
import { assert } from 'chai';

import ManagedPromise from '../../build/obj/managedPromise.js';
import { ManagedPromise } from '@keymanapp/web-utils';
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, is this self-referential? Is that a good thing?

Copy link
Contributor Author

@jahorton jahorton Jun 13, 2023

Choose a reason for hiding this comment

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

src/test/...: we're importing the package for its unit test. Importing through the primary index helps c8 to properly assess coverage for all files, even if we manually exclude some in the config. Directly referencing the raw built modules made a difference for c8 for some reason.

web/package.json Outdated Show resolved Hide resolved
@jahorton jahorton requested a review from mcdurdin June 15, 2023 01:47
Copy link
Member

@mcdurdin mcdurdin left a comment

Choose a reason for hiding this comment

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

LGTM

@jahorton jahorton merged commit 0532405 into feature-esmodule-web-engine Jun 19, 2023
15 of 16 checks passed
@jahorton jahorton deleted the change/srcmap-cleanup-and-c8-use branch June 19, 2023 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

2 participants