Skip to content

Commit

Permalink
Compiled cjs step definitions (#222)
Browse files Browse the repository at this point in the history
* Expand javascript step definition queries to match compiled cjs style steps

* Update changelog

* Direct import of gherkin keywords with compiled cjs

---------

Co-authored-by: Kieran Ryan <kierankilkenny@gmail.com>
  • Loading branch information
finnmerlett and kieran-ryan committed Jul 14, 2024
1 parent 6db4a1a commit b452811
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
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
- Parameter highlighting for scenario outline steps with leading spaces ([#219](https://github.com/cucumber/language-service/pull/219))
- (Ruby) Support `And` and `But` step definition annotations ([#211](https://github.com/cucumber/language-service/pull/211))
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)
})

0 comments on commit b452811

Please sign in to comment.