-
Notifications
You must be signed in to change notification settings - Fork 21
Replace Settings
class by getSettings
function
#14
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
Conversation
If we're starting to refactor this, should we talk about refactoring It seems like smelly code to have a new Setttings().settings.testMatch` The other confusing thing is if we've got a class representing settings, why do we have an array of other settings ( |
What about: export interface ConfigRepresentation {
testRegex: string | string[];
testMatch: string[];
jestVersionMajor: number | null;
};
export class Settings extends EventEmitter {
constructor(workspace: ProjectWorkspace, options?: Options);
getSettings(): Promise<ConfigRepresentation[]>;
} In principle we could move this |
Definitely keen to see const settings = new Settings({/* ... */});
const getConfig = (): Promise<void> => {
return new Promise(resolve => {
settings.getConfig(() => {
resolve();
});
});
};
// wait for Promise to return so we have the correct settings for testMatch and testRegex.
await getConfig(); |
That's way less confusing for me @stephtr. 😌 |
chime in my 2 cents, I think there is a great opportunity to move this whole class into a single stateless function, let's say
|
I now ended up with (the tests are still to be updated): type Glob = string;
type ProjectConfiguration = {
testRegex: string | Array<string>,
testMatch: Array<Glob>,
};
type JestSettings = {
jestVersionMajor: number,
configs: ProjectConfiguration[],
};
function parseSettings(text: string, debug: Boolean = false): JestSettings {...}
export function getSettings(workspace: ProjectWorkspace, options?: Options): Promise<JestSettings> {...} Is everyone fine with that? |
You can pull Doesn't really make a difference of course, just throwing it out there 🙂 Might not be worth the dep (as it's just strings or arrays of strings) |
Settings
Settings
class by getSettings
function
That definitely makes sense.
|
Oh, is this written in Flow? Then I apologize - we only export TS types... I'd forgotten this was extracted before we migrated to TS 😬 |
It's fine, it is still useful for the |
Was all of that conversion done manually @SimenB? |
Yeah - it was pretty straight forward to just rename the file, replace all (I'll try to write a blog post about the migration in the next couple of weeks - my vacation starts tomorrow and the weather in Oslo is gonna be pretty bad, so I'll have some time in the next few day to get a good start) |
Nevertheless have a nice vacation! I just updated the tests, now my PR would be complete. const makeBuffer = (content: string) => {
// Buffer.from is not supported in < Node 5.10
if (typeof Buffer.from === 'function') {
return Buffer.from(content);
}
return Buffer.from(content);
}; |
@seanpoulter since you already started the review, wanna finish it? We have a pre-release 26-beta, once this PR is merged, we could cut an official v26.0.0 |
Sorry @connectdotz, I didn't start a review. I stopped at pointing out the code smell. If anyone else has the capacity please feel free to do the code review. I'm worried you might be waiting on me to have enough spare time to relearn what's going on in this repo. |
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.
looks good to me, thanks @stephtr 👍
@stephtr just discovered this in
Apparently, all tests depends on |
@stephtr do you prefer we revert the merge until we figure out what caused this new error, or to patch it in a separate PR? |
I'll take a look at it in the evening. I initially thought that settings wouldn't affect the vscode plug in...
…________________________________
From: ConnectDotz <notifications@github.com>
Sent: Monday, July 29, 2019 12:40:17 PM
To: jest-community/jest-editor-support <jest-editor-support@noreply.github.com>
Cc: Stephan Troyer <stephantroyer@live.at>; Mention <mention@noreply.github.com>
Subject: Re: [jest-community/jest-editor-support] Replace `Settings` class by `getSettings` function (#14)
@stephtr<https://github.com/stephtr> do you prefer we revert the merge until we figure out what caused this new error, or to patch it in a separate PR?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#14?email_source=notifications&email_token=ABL7IWDR6ILX7R7RLCAWIYLQB3CJDA5CNFSM4IDSBZC2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3AKCXI#issuecomment-515940701>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ABL7IWC4LEDXIEAS3JHU5JLQB3CJDANCNFSM4IDSBZCQ>.
|
Unfortunately I still haven't found the underlying issue even though I tried a few things. My guess however still is, that it is rather an issue with a dependency update between the last two versions than related to this PR. Today I try to find the culprit commit. |
@stephtr I tried linking
any thought on how to fix it? |
I also gave it another try today morning. However so far I wasn't successful. I tried previous commits but found no one which wasn't throwing some exceptions. Updating babel also didn't help.
Currently I don't even understand the underlying problem. I'll still play around with it a bit today, but unfortunately my hope isn't that high. Update: I got only so far, that my error message currently is:
I have the feeling that this is coming from |
I might have a chance to investigate tonight. Are these the right steps to reproduce it? Feel free to edit this message as required. Steps to reproduce
Expected behaviour
Actual behaviour
|
Exactly. It always boils down to the fact, that some function result within node_modules is undefined even though it shouldn't be the case. In my cases the reason was always that some function inadvertently got mocked (I assume by Jest) after a few tests succeeded. Mocked the functions just return undefined, which leads to the observed exceptions. |
@stephtr you can try using jestSetup.js to force it unmock... |
Wow thanks, I now at least see the smoking gun. The entries of jestSetup.js don't work if the dependencies happen to be located within node_modules of another dependency. I therefore had to add a few lines of |
Perhaps we should consider turning off automock in |
Maybe that's the best way, even though it would require quite some work on manual mocking (without automock the tests result in many pages of error messages). |
ok, I found a cheap fix with unmockedModulePathPatterns...
After adding this to |
Wow, that really sounds perfect! |
Until now
Settings.settings
had been populated by the constructor using Jest's default values.This however had a few disadvantages:
jest-config
, which by itself pulled in a large amount of further dependencies.getConfigs
.As an alternative I propose to set
Settings.settings
toundefined
instead (andSettings.configs
to an empty array), until one of the getConfigs functions has been called. This will be a breaking change and if accepted, should probably wait until the next major version.