Update the standalone test runner to compile Typescript sources at runtime#378
Update the standalone test runner to compile Typescript sources at runtime#378austinEng wants to merge 3 commits intogpuweb:mainfrom
Conversation
austinEng
left a comment
There was a problem hiding this comment.
Here's the overall structure, still need some tweaks. Sending it out now for early feedback.
| tsconfig['compilerOptions']['moduleResolution']); | ||
|
|
||
| // https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API | ||
| const output = ts.transpile(file, compilerOptions); |
There was a problem hiding this comment.
Would be good if this could use Babel as well since that's what we use for the actual build.
| <input type="button" id="copyResultsJSON" value="Copy results as JSON"> | ||
| </p> | ||
| <script> | ||
| if ('serviceWorker' in navigator) { |
There was a problem hiding this comment.
Need to guard this on some define like IS_STANDALONE_DEV or something
There was a problem hiding this comment.
What would that do? This file is only used for standalone dev. Should probably throw an exception if service workers aren't available.
There was a problem hiding this comment.
It's also used for the standalone build that's published to gh-pages.
Maybe we could also turn this file into a template.
package.json
Outdated
| "typescript": "^4.0.3" | ||
| } | ||
| "typescript": "^4.0.3", | ||
| "val-loader": "^2.1.2", |
There was a problem hiding this comment.
val-loader is unused.
| @@ -0,0 +1,10 @@ | |||
| { | |||
There was a problem hiding this comment.
May not be relevant with babel, but this is only used in service-worker/index.ts I assume? Could we just hardcode these into that file?
There was a problem hiding this comment.
This tsconfig is for the actual service-worker/index.ts file. But it imports the root tsconfig.json for runtime compilation of the other sources.
| <input type="button" id="copyResultsJSON" value="Copy results as JSON"> | ||
| </p> | ||
| <script> | ||
| if ('serviceWorker' in navigator) { |
There was a problem hiding this comment.
What would that do? This file is only used for standalone dev. Should probably throw an exception if service workers aren't available.
standalone/index.html
Outdated
| const script = document.createElement('script'); | ||
| script.type = "module"; | ||
| script.src = "../src/common/runtime/standalone.ts"; | ||
|
|
||
| document.body.append(script); |
There was a problem hiding this comment.
Could this be just import('../src/common/runtime/standalone.ts')?
| @@ -0,0 +1,67 @@ | |||
| const path = require('path'); | |||
There was a problem hiding this comment.
How does webpack get triggered?
There was a problem hiding this comment.
This is happening with npm run dev. Which will both start and http server and watch changes to recompile if the service worker file changes (maybe a but overkill but was very nice for development).
|
|
||
| // See https://webpack.js.org/api/loaders/. | ||
| // Module loader that replaces an import with a module that contains the generated | ||
| // listing for a test suite. Assumes the listing is at /path/to/{suite}/listing.ts. |
There was a problem hiding this comment.
I was thinking for the moment we might still require a build step when new files are added. OTOH, if we have code to generate listing.ts running server-side (which I assume this is?) then should we just do all the TS compilation server-side...?
There was a problem hiding this comment.
I didn't actually verify this yet, but Webpack's watcher should regenerate the listing on changes. If it doesn't we should be able to set it up to do that.
But yea you're right we could probably make all the compilation happen server side without the need for service worker. It'll probably be faster that way too.
It might be cleaner to just write our own http server for this.
There was a problem hiding this comment.
I'm going to try our own http server. It avoids bundling shenanigans and is less memory and is much simpler, especially if we intend for this to be dev only.
There was a problem hiding this comment.
Sounds good. I really would like to go the service worker route for WPT someday, but given we have no way to do this now with a reasonable file size, this does seem more straightforward.
There was a problem hiding this comment.
I was pretty excited about this, but now seeing that the compiles take tens and sometimes 100-something milliseconds (maybe cause the browser is busy doing something else like fetching, etc.) it seems like it potentially could be rather detrimental for test runner performance and increase run times on CI a lot. Maybe the code structure could be better, because it looks like with the service worker, fetches and compiles aren't happening in parallel. If we did Promise.all of all the dynamic imports instead of awaiting each, maybe this would be less of a problem.
How do you imagine we would go the service worker route for WPT while maintaining a reasonable file size?
- WPT gains a fetch deps + build step? (might as well just compile the TS here)
- We use a tiny TS compiler?
If we want WPT service worker to happen in the nearish-term, maybe we should stick with service worker on standalone so most of the code is there.
There was a problem hiding this comment.
another important bit here is that service worker won't work if you serve the CTS from a remote server. It's explicitly allowed for localhost, but if you try to get at it from some random IP address, service worker isn't available - unless you run with --disable-web-security
There was a problem hiding this comment.
We can definitely get the fetches to happen in parallel. Though I assume by default the service worker won't actually parallelize the synchronous TS compilation?
My only idea for WPT is to use a tiny TS compiler (I haven't been able to find any such thing, even though it's theoretically possible), or get approval to drop a big dep into WPT (no idea how likely).
Good to know about the localhost thing, is that it would work on localhost or https but not http?
|
Closing in favor of #386 |
No description provided.