Skip to content

Commit 61dab27

Browse files
authored
Switch devkit to be an ES Module (#201)
1 parent e28091c commit 61dab27

File tree

15 files changed

+61
-59
lines changed

15 files changed

+61
-59
lines changed

devkit/package-lock.json

Lines changed: 1 addition & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

devkit/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.0.0",
44
"description": "Development kit for the cucumber compatibility kit packages",
55
"private": true,
6+
"type": "module",
67
"main": "src/index.ts",
78
"scripts": {
89
"copy-samples": "npm run copy-to:javascript && npm run copy-to:ruby && npm run copy-to:java",

devkit/samples/attachments/attachments.ndjson

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
{"pickle":{"id":"25","uri":"samples/attachments/attachments.feature","astNodeIds":["11"],"tags":[],"name":"Attaching PDFs with a different filename","language":"en","steps":[{"id":"24","text":"a PDF document is attached and renamed","type":"Action","astNodeIds":["10"]}]}}
1010
{"pickle":{"id":"27","uri":"samples/attachments/attachments.feature","astNodeIds":["13"],"tags":[],"name":"Attaching URIs","language":"en","steps":[{"id":"26","text":"a link to \"https://cucumber.io\" is attached","type":"Action","astNodeIds":["12"]}]}}
1111
{"stepDefinition":{"id":"28","pattern":{"type":"CUCUMBER_EXPRESSION","source":"the string {string} is attached as {string}"},"sourceReference":{"uri":"samples/attachments/attachments.ts","location":{"line":4}}}}
12-
{"stepDefinition":{"id":"29","pattern":{"type":"CUCUMBER_EXPRESSION","source":"the string {string} is logged"},"sourceReference":{"uri":"samples/attachments/attachments.ts","location":{"line":8}}}}
13-
{"stepDefinition":{"id":"30","pattern":{"type":"CUCUMBER_EXPRESSION","source":"text with ANSI escapes is logged"},"sourceReference":{"uri":"samples/attachments/attachments.ts","location":{"line":12}}}}
14-
{"stepDefinition":{"id":"31","pattern":{"type":"CUCUMBER_EXPRESSION","source":"the following string is attached as {string}:"},"sourceReference":{"uri":"samples/attachments/attachments.ts","location":{"line":18}}}}
15-
{"stepDefinition":{"id":"32","pattern":{"type":"CUCUMBER_EXPRESSION","source":"an array with {int} bytes is attached as {string}"},"sourceReference":{"uri":"samples/attachments/attachments.ts","location":{"line":22}}}}
16-
{"stepDefinition":{"id":"33","pattern":{"type":"CUCUMBER_EXPRESSION","source":"a PDF document is attached and renamed"},"sourceReference":{"uri":"samples/attachments/attachments.ts","location":{"line":31}}}}
17-
{"stepDefinition":{"id":"34","pattern":{"type":"CUCUMBER_EXPRESSION","source":"a link to {string} is attached"},"sourceReference":{"uri":"samples/attachments/attachments.ts","location":{"line":38}}}}
12+
{"stepDefinition":{"id":"29","pattern":{"type":"CUCUMBER_EXPRESSION","source":"the string {string} is logged"},"sourceReference":{"uri":"samples/attachments/attachments.ts","location":{"line":11}}}}
13+
{"stepDefinition":{"id":"30","pattern":{"type":"CUCUMBER_EXPRESSION","source":"text with ANSI escapes is logged"},"sourceReference":{"uri":"samples/attachments/attachments.ts","location":{"line":15}}}}
14+
{"stepDefinition":{"id":"31","pattern":{"type":"CUCUMBER_EXPRESSION","source":"the following string is attached as {string}:"},"sourceReference":{"uri":"samples/attachments/attachments.ts","location":{"line":21}}}}
15+
{"stepDefinition":{"id":"32","pattern":{"type":"CUCUMBER_EXPRESSION","source":"an array with {int} bytes is attached as {string}"},"sourceReference":{"uri":"samples/attachments/attachments.ts","location":{"line":28}}}}
16+
{"stepDefinition":{"id":"33","pattern":{"type":"CUCUMBER_EXPRESSION","source":"a PDF document is attached and renamed"},"sourceReference":{"uri":"samples/attachments/attachments.ts","location":{"line":37}}}}
17+
{"stepDefinition":{"id":"34","pattern":{"type":"CUCUMBER_EXPRESSION","source":"a link to {string} is attached"},"sourceReference":{"uri":"samples/attachments/attachments.ts","location":{"line":47}}}}
1818
{"testRunStarted":{"id":"35","timestamp":{"seconds":0,"nanos":0}}}
1919
{"testCase":{"id":"36","pickleId":"15","testSteps":[{"id":"37","pickleStepId":"14","stepDefinitionIds":["28"],"stepMatchArgumentsLists":[{"stepMatchArguments":[{"group":{"start":11,"value":"\"hello\"","children":[{"start":12,"value":"hello","children":[{"children":[]}]},{"children":[{"children":[]}]}]},"parameterTypeName":"string"},{"group":{"start":34,"value":"\"application/octet-stream\"","children":[{"start":35,"value":"application/octet-stream","children":[{"children":[]}]},{"children":[{"children":[]}]}]},"parameterTypeName":"string"}]}]}],"testRunStartedId":"35"}}
2020
{"testCase":{"id":"38","pickleId":"17","testSteps":[{"id":"39","pickleStepId":"16","stepDefinitionIds":["29"],"stepMatchArgumentsLists":[{"stepMatchArguments":[{"group":{"start":11,"value":"\"hello\"","children":[{"start":12,"value":"hello","children":[{"children":[]}]},{"children":[{"children":[]}]}]},"parameterTypeName":"string"}]}]}],"testRunStartedId":"35"}}
Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { When } from '@cucumber/fake-cucumber'
22
import fs from 'node:fs'
33

4-
When('the string {string} is attached as {string}', async function (text: string, mediaType: string) {
5-
await this.attach(text, mediaType)
6-
})
4+
When(
5+
'the string {string} is attached as {string}',
6+
async function (text: string, mediaType: string) {
7+
await this.attach(text, mediaType)
8+
}
9+
)
710

811
When('the string {string} is logged', async function (text: string) {
912
await this.log(text)
@@ -15,26 +18,32 @@ When('text with ANSI escapes is logged', async function () {
1518
)
1619
})
1720

18-
When('the following string is attached as {string}:', async function (mediaType: string, text: string) {
19-
await this.attach(text, mediaType)
20-
})
21+
When(
22+
'the following string is attached as {string}:',
23+
async function (mediaType: string, text: string) {
24+
await this.attach(text, mediaType)
25+
}
26+
)
2127

2228
When(
2329
'an array with {int} bytes is attached as {string}',
24-
async function (size: number, mediaType: string) {
30+
async function (size: number, mediaType: string) {
2531
const data = [...Array(size).keys()]
2632
const buffer = Buffer.from(data)
2733
await this.attach(buffer, mediaType)
2834
}
2935
)
3036

3137
When('a PDF document is attached and renamed', async function () {
32-
await this.attach(fs.createReadStream(__dirname + '/document.pdf'), {
38+
await this.attach(
39+
fs.createReadStream(import.meta.dirname + '/document.pdf'),
40+
{
3341
mediaType: 'application/pdf',
34-
fileName: 'renamed.pdf'
35-
})
42+
fileName: 'renamed.pdf',
43+
}
44+
)
3645
})
3746

3847
When('a link to {string} is attached', async function (uri: string) {
39-
await this.link(uri)
48+
await this.link(uri)
4049
})

devkit/samples/examples-tables-attachment/examples-tables-attachment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { When } from '@cucumber/fake-cucumber'
22
import fs from 'node:fs'
33

44
When('a JPEG image is attached', async function () {
5-
await this.attach(fs.createReadStream(__dirname + '/cucumber.jpeg'), 'image/jpeg')
5+
await this.attach(fs.createReadStream(import.meta.dirname + '/cucumber.jpeg'), 'image/jpeg')
66
})
77

88
When('a PNG image is attached', async function () {
9-
await this.attach(fs.createReadStream(__dirname + '/cucumber.png'), 'image/png')
9+
await this.attach(fs.createReadStream(import.meta.dirname + '/cucumber.png'), 'image/png')
1010
})

devkit/samples/hooks-attachment/hooks-attachment.ndjson

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
{"source":{"data":"Feature: Hooks - Attachments\n Hooks are special steps that run before or after each scenario's steps.\n\n Like regular steps, it is possible to attach a file to the output.\n\n Scenario: With an valid attachment in the hook and a passed step\n When a step passes\n","uri":"samples/hooks-attachment/hooks-attachment.feature","mediaType":"text/x.cucumber.gherkin+plain"}}
33
{"gherkinDocument":{"feature":{"tags":[],"location":{"line":1,"column":1},"language":"en","keyword":"Feature","name":"Hooks - Attachments","description":" Hooks are special steps that run before or after each scenario's steps.\n\n Like regular steps, it is possible to attach a file to the output.","children":[{"scenario":{"id":"1","tags":[],"location":{"line":6,"column":3},"keyword":"Scenario","name":"With an valid attachment in the hook and a passed step","description":"","steps":[{"id":"0","location":{"line":7,"column":5},"keyword":"When ","keywordType":"Action","text":"a step passes"}],"examples":[]}}]},"comments":[],"uri":"samples/hooks-attachment/hooks-attachment.feature"}}
44
{"pickle":{"id":"3","uri":"samples/hooks-attachment/hooks-attachment.feature","astNodeIds":["1"],"tags":[],"name":"With an valid attachment in the hook and a passed step","language":"en","steps":[{"id":"2","text":"a step passes","type":"Action","astNodeIds":["0"]}]}}
5-
{"stepDefinition":{"id":"5","pattern":{"type":"CUCUMBER_EXPRESSION","source":"a step passes"},"sourceReference":{"uri":"samples/hooks-attachment/hooks-attachment.ts","location":{"line":9}}}}
5+
{"stepDefinition":{"id":"5","pattern":{"type":"CUCUMBER_EXPRESSION","source":"a step passes"},"sourceReference":{"uri":"samples/hooks-attachment/hooks-attachment.ts","location":{"line":11}}}}
66
{"hook":{"id":"4","type":"BEFORE_TEST_CASE","sourceReference":{"uri":"samples/hooks-attachment/hooks-attachment.ts","location":{"line":4}}}}
7-
{"hook":{"id":"6","type":"AFTER_TEST_CASE","sourceReference":{"uri":"samples/hooks-attachment/hooks-attachment.ts","location":{"line":13}}}}
7+
{"hook":{"id":"6","type":"AFTER_TEST_CASE","sourceReference":{"uri":"samples/hooks-attachment/hooks-attachment.ts","location":{"line":15}}}}
88
{"testRunStarted":{"id":"7","timestamp":{"seconds":0,"nanos":0}}}
99
{"testCase":{"id":"8","pickleId":"3","testSteps":[{"id":"9","hookId":"4"},{"id":"10","pickleStepId":"2","stepDefinitionIds":["5"],"stepMatchArgumentsLists":[{"stepMatchArguments":[]}]},{"id":"11","hookId":"6"}],"testRunStartedId":"7"}}
1010
{"testCaseStarted":{"id":"12","testCaseId":"8","timestamp":{"seconds":0,"nanos":1000000},"attempt":0}}

devkit/samples/hooks-attachment/hooks-attachment.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@ import { When, Before, After } from '@cucumber/fake-cucumber'
22
import fs from 'node:fs'
33

44
Before({}, async function () {
5-
await this.attach(fs.createReadStream(__dirname + '/cucumber.svg'), 'image/svg+xml')
5+
await this.attach(
6+
fs.createReadStream(import.meta.dirname + '/cucumber.svg'),
7+
'image/svg+xml'
8+
)
69
})
710

8-
911
When('a step passes', function () {
1012
// no-op
1113
})
1214

1315
After({}, async function () {
14-
await this.attach(fs.createReadStream(__dirname + '/cucumber.svg'), 'image/svg+xml')
16+
await this.attach(
17+
fs.createReadStream(import.meta.dirname + '/cucumber.svg'),
18+
'image/svg+xml'
19+
)
1520
})

devkit/src/ExecutionContext.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from '@cucumber/messages'
77
import { Readable } from 'stream'
88

9-
import { Clock } from './Clock'
9+
import { Clock } from './Clock.js'
1010

1111
const LOG_MEDIA_TYPE = 'text/x.cucumber.log+plain'
1212
const LINK_MEDIA_TYPE = 'text/uri-list'

devkit/src/GlobalContext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Envelope } from '@cucumber/messages'
22

3-
import { Clock } from './Clock'
4-
import { ExecutionContext } from './ExecutionContext'
3+
import { Clock } from './Clock.js'
4+
import { ExecutionContext } from './ExecutionContext.js'
55

66
export class GlobalContext extends ExecutionContext {
77
constructor(

devkit/src/Runner.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import {
1818
TimeConversion,
1919
} from '@cucumber/messages'
2020

21-
import { Clock } from './Clock'
22-
import { GlobalContext } from './GlobalContext'
23-
import { makeSnippets } from './makeSnippets'
24-
import { Stopwatch } from './Stopwatch'
25-
import { World } from './World'
21+
import { Clock } from './Clock.js'
22+
import { GlobalContext } from './GlobalContext.js'
23+
import { makeSnippets } from './makeSnippets.js'
24+
import { Stopwatch } from './Stopwatch.js'
25+
import { World } from './World.js'
2626

2727
const NON_SUCCESS_STATUSES = new Set<TestStepResultStatus>([
2828
TestStepResultStatus.PENDING,

0 commit comments

Comments
 (0)