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

Parse compiled cjs step definitions #222

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- (Javascript) Support for compiled cjs style step definitions ([#222](https://github.com/cucumber/language-service/pull/222))

### Fixed
- (Ruby) Support `And` and `But` step definition annotations ([#211](https://github.com/cucumber/language-service/pull/211))
- (Python) Title variants of Behave's decorators (`Step`, `Given`, `When`, `Then`) ([#213](https://github.com/cucumber/language-service/pull/213))
Expand Down
39 changes: 39 additions & 0 deletions src/language/javascriptLanguage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,45 @@ import { Language } from './types.js'

export const javascriptLanguage: Language = {
...tsxLanguage,
defineStepDefinitionQueries: [
...tsxLanguage.defineStepDefinitionQueries,
// Compiled cjs step definitions of the format:
// (0, some_cucumber_import.Given)("step pattern here", function...)
`(call_expression
function: (parenthesized_expression
(sequence_expression
(member_expression
property: (property_identifier) @function-name
)
)
)
arguments: (arguments
[
(string) @expression
(regex) @expression
(template_string) @expression
]
)
(#match? @function-name "Given|When|Then")
) @root`,
// Compiled cjs step definitions of the format:
// (0, Given)("step pattern here", function...)
`(call_expression
function: (parenthesized_expression
(sequence_expression
(identifier) @function-name
)
)
arguments: (arguments
[
(string) @expression
(regex) @expression
(template_string) @expression
]
)
(#match? @function-name "Given|When|Then")
) @root`,
],
defaultSnippetTemplate: `
{{ keyword }}('{{ expression }}', ({{ #parameters }}{{ #seenParameter }}, {{ /seenParameter }}{{ name }}{{ /parameters }}) => {
// {{ blurb }}
Expand Down
1 change: 1 addition & 0 deletions test/language/ExpressionBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ function defineContract(makeParserAdapter: () => ParserAdapter) {
'a {planet}',
/^a regexp$/,
"the bee's knees",
...(languageName === 'javascript' ? ['a compiled format'] : []),
])
assert.deepStrictEqual(errors, [
'There is already a parameter type with name int',
Expand Down
8 changes: 6 additions & 2 deletions test/language/testdata/javascript/StepDefinitions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Given } from '@cucumber/cucumber'
import cucumber, { Given } from '@cucumber/cucumber'
import assert from 'assert'
import React from 'react'

Expand All @@ -24,6 +24,10 @@ Given('an {undefined-parameter}', async function (date) {
assert(date)
})

Given("the bee's knees", async function () {
;(0, Given)("the bee's knees", async function () {
assert(true)
})

;(0, cucumber.Given)('a compiled format', async function () {
assert(true)
})