-
Notifications
You must be signed in to change notification settings - Fork 12
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
[Feature Request] Accept a Typescript file as configuration for the Merge CLI for monocart-reporter #145
Comments
The default config files are following
But the for example, create a mr.config.ts with options and run CLI following cross-env NODE_OPTIONS="--loader ts-node/esm --no-warnings" monocart merge ./docs/shard*/index.json Unfortunately, it's not working currently, I will fix it in the next patch. |
In your example above I assume you are missing the |
I forgot install
npm i ts-node typescript cross-env -D
cross-env NODE_OPTIONS="--loader ts-node/esm --no-warnings" monocart merge ./docs/shard*/index.json cross-env will support Windows/Linux/MacOS Yes, it is not necessary to specify the config file path with
|
I tried your suggestion but without any luck:
Resulted in:
The contents of the import path from "node:path";
const reportersOutputDir = path.resolve("./test-reporters/playwright");
// commented out the rest of the file since it errors with just this due to the import statement. Apologies if this is a real simple type of error but I'm not very familiar with the frontend ecosystem and I don't know what I should do to get this to work. Any thoughts? Also, as suggested by the article I linked in the initial post, would it not be possible for the merge CLI to use the Meaning we could just do: |
try updating {
"type": "module"
} |
Yes, it could be a bit trouble to directly load Try it with Node.js v22.6.0 + |
Using Node
That is fair, perhaps only worth it if you have significant number of people asking for such a feature.
I don't want to side track this issue with discussion on whether or not types are useful. I would say that this library is meant to be used with Playwright and Playwright encourages/defaults to using Typescript. This means that users can get into the same situation as me where they have Typescript code they want to share between the Playwright config and the merge CLI config. In this case, making it easier to consume a TS file from the merge CLI makes sense I think. |
I found a new lib called |
Please try [email protected]
BTW, There is a open issue in |
Tried version The issue is that when I import something from another file it errors. If i have an import like this: import { getMonocartReporterOptions } from "playwright.monocart-reporter-options"; It fails with:
If I add a import { getMonocartReporterOptions } from "./playwright.monocart-reporter-options"; It fails with a different error:
Not sure if that's an issue with the current implementation in |
The "playwright.monocart-reporter-options" is a file? |
Yes.
If I try to add the extension I get this error:
And then if I add the
I don't think I can add any of those to my project without creating other problems but just to test this I did it and after I got a different error when running the merge CLI command. I got:
The above error is because at the start of the file being imported, import {
CoverageReportOptions,
MonocartReporterOptions,
ReportDescription,
} from "monocart-reporter"; Also, if I don't do any of the above changes and just have a merge config TS file that looks like: // This is a merge CLI TS file
import {
CoverageReportOptions,
MonocartReporterOptions,
ReportDescription,
} from "monocart-reporter"; I get the same error:
Lastly, I want to add that these imports, both the one from "playwright.monocart-reporter-options" and the ones from "monocart-reporter", are fine because they do work when running the playwright tests which uses these TS files that we are having issues with on the merge CLI. |
And I guess you already know this but I wanted to add anyway that if we don't install With a TS merge CLI config like this: // This file is named playwright.monocart-reporter-merge.ts
import path from "node:path";
const reportersOutputDir = path.resolve("./test-reporters/playwright");
const monocartReporterOutputDir = path.resolve(reportersOutputDir, "monocart-reporter");
const options = {
name: "Playground app for @ln/ngx-module-federation-tools",
outputFile: path.resolve(monocartReporterOutputDir, "monocart-report.html"),
}
export default options; And without
I get this error:
Then after installing It feels it's almost there, there's just some issue with imports going on... |
import type { CoverageReportOptions } from "monocart-reporter"; Can you try above? TypeScript has very complex configurations and specifications, which can easily lead to various issues. I am not very familiar with TypeScript, and of course, I have not do exhaustive testing. I hope this can fix it; otherwise, I think it should be go back to using |
Although this is something I've seen some linters recommending at times, my understanding it's that it is an optimization, not a "correct usage" requirement. Meaning that in all my TS projects I have never used So to recap, what I had to do was:
Then given the following contents of a TS merge CLI file: // This is the playwright.monocart-reporter-merge.ts file
import { getMonocartReporterOptions } from "./playwright.monocart-reporter-options.ts";
import { reportersOutputDir } from "./playwright.shared-vars.ts";
const isShardedTestRun = false;
const options = getMonocartReporterOptions(reportersOutputDir, isShardedTestRun);
export default options; And running:
It worked as expected 👏 HOWEVER, the Can't run my Angular app because it errors with:
Can't run jest tests because it errors with:
Can't run playground tests because it errors with:
|
Given my previous comment, I don't think the current implementation with However, even if I did that and for instance created a When you said:
I'm thinking it might be worth to give |
Perhaps
const { code } = transformSync(source.toString(), {
mode: 'strip-only'
// other options
}); For example, try |
I tried that and it didn't work. I also tried other options without any luck 😔 I think the only way we can make progress here is if I give you something you can check for yourself so I took the time and created a minimalistic reproduction of the problem at monocart-merge-cli-demo. I think the README has all the information you need to be able to reproduce the error but let me know if something doesn't work as expected. The repo will let you easily create sharded test reports using monocart-reporter and then test the merge-cli with a TS config file. Note In that demo repo I have used Typescript version 4.3.5 which is what I have on the projects where I'm testing the merge-cli but if you need to update that Typescript version to test things with Amaro then feel free to do so since Amaro as a note on their README saying: Hope this helps 🤞 |
@cenfun Although I'd really like to have an easy way to use a TS file for the merge CLI I want to stress out that it's a minor inconvenient that I can't. If implementing support for this using You already provide an amazing support for this library 🥇 and I just want you to know that I appreciate that a lot and I don't want to make you spend time in quality of life improvements if you don't think they're worth it. |
Thanks for the minimalistic reproduction repo which help to fix issue easily. TypeScript background in your project
So the monocart merge --import my-ts-loader It requires Nodejs 18.19.0 + Testing of popular TypeScript loaders
monocart merge ./shards/**/monocart-report.json --import tsx The only passed lib for your project. This is because it's powerful
monocart merge ./shards/**/monocart-report.json --import ts-node
# or
monocart merge ./shards/**/monocart-report.json --import ts-node/esm
monocart merge ./shards/**/monocart-report.json --import ts-node/register I didn't make it, and found there is a issue in Node.js 20: TypeStrong/ts-node#1997
monocart merge ./shards/**/monocart-report.json --import tsimp/import It seems that the
monocart merge ./shards/**/monocart-report.json --import amaro/register The |
Thank you very much for your patience and getting this done @cenfun 🤗 I'm closing this issue but I would recommend that you add some note to the README on the Using merge CLI section to tell users how they can use TS files for config with this |
@cenfun I couldn't find anything on the README about this feature you've implemented. What do you think about adding something to the README under the Saying:
|
Thanks, the README is updated. |
Would it be possible to accept a
.ts
file as the configuration file passed to the merge CLI?Would it be possible to do something like:
As described in How to use Typescript files inside Javascript file?.
I'm out of my depth here so perhaps I'm just saying nonsense...
If it helps understand why I'm asking this:
It's because I have typescript for the Playwright configuration file and I'd like to share code between the Playwright configuration and the merge CLI configuration and have the shared code in Typescript instead of Javascript.
The text was updated successfully, but these errors were encountered: