Skip to content

Conversation

@G-Rath
Copy link
Collaborator

@G-Rath G-Rath commented Jul 20, 2019

I didn't type the guards correctly the first time - see this comment for some more info.

This is something that should be looked into at some point; in JS the type guards are implemented using getNodeName, which'll give you the following:

describe(); // describe
describe.only(); // describe.only
describe.only.each('') // describe.only.each

This is then checked using #has against a Set, which has since become an enum.
However the original Set contained both functions and function chains:

const describeAliases = new Set([
  'describe',
  'describe.only',
  'describe.skip',
  'fdescribe',
  'xdescribe',
]);

I've retyped the guards so that they now match the actual runtime checks that are happening, but this means that there is a behavioural difference from the JS version that I think should be commented on.

The behavioural change is that now things like describe.<anything>() will be cause isDescribe to return true.

It's all left me a bit paranoid right now, b/c I've not got enough info to know how big of an impact this'll have on everything - so far I've not had any problems (i.e no tests have failed), but it's technically possible that it means the plugin could try and lint things it shouldn't (which wouldn't necessarily cause an error, since it'll be doing other checks) which we might care about?

This PR should definitely be merged, as it only changes the types to reflect the runtime checks.

node.callee.object.type === AST_NODE_TYPES.Identifier &&
node.callee.object.name in HookName)
node.callee.type === AST_NODE_TYPES.Identifier &&
node.callee.name in HookName
Copy link
Collaborator Author

@G-Rath G-Rath Jul 20, 2019

Choose a reason for hiding this comment

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

I've changed this b/c jest doesn't expect hooks to expose a method property, and this way the two rules that use them don't need to be changed :D

isHook is only used by no-duplicate-hooks and no-hooks.

Copy link
Member

Choose a reason for hiding this comment

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

I don't follow - you can do describe.skip (etc). Or do I misunderstand your comment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

But describe isn't a hook - the HookName enum is for beforeAll, beforeEach, afterEach & afterAll.

That's why it's the only one I made this change to - the others I left as it b/c in the JS version they have member calls (i.e describe.skip)

Copy link
Member

Choose a reason for hiding this comment

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

hah, good point! There are indeed no identifiers on hooks

@SimenB SimenB merged commit 21b295c into jest-community:reapply-ts Jul 20, 2019
@G-Rath G-Rath deleted the ts-migration/improve-guards branch July 20, 2019 09:27
SimenB pushed a commit that referenced this pull request Jul 20, 2019
SimenB pushed a commit that referenced this pull request Jul 21, 2019
SimenB pushed a commit that referenced this pull request Jul 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants