Skip to content

Commit

Permalink
chore: update cucumber packages and fix CCK (#2351)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjgoss authored Nov 10, 2023
1 parent 6eede88 commit 835215e
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 173 deletions.
1 change: 1 addition & 0 deletions .mocharc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
colors: true
fail-zero: true
file:
- test/test_helper.ts
full-trace: true
Expand Down
6 changes: 3 additions & 3 deletions compatibility/cck_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ const CCK_IMPLEMENTATIONS_PATH = 'compatibility/features'
config.truncateThreshold = 100
use(chaiExclude)

describe('Cucumber Compatibility Kit', async () => {
const ndjsonFiles = await glob(`${CCK_FEATURES_PATH}/**/*.ndjson`)
describe('Cucumber Compatibility Kit', () => {
const ndjsonFiles = glob.sync(`${CCK_FEATURES_PATH}/**/*.ndjson`)
ndjsonFiles.forEach((fixturePath) => {
const match = /^.+\/(.+)(\.feature(?:\.md)?)\.ndjson$/.exec(fixturePath)
const match = /^.+[/\\](.+)(\.feature(?:\.md)?)\.ndjson$/.exec(fixturePath)
const suiteName = match[1]
const extension = match[2]
it(`passes the cck suite for '${suiteName}'`, async () => {
Expand Down
91 changes: 36 additions & 55 deletions compatibility/features/attachments/attachments.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,60 @@
import fs from 'node:fs'
import path from 'node:path'
import { ReadableStreamBuffer } from 'stream-buffers'
import { Before, When, World } from '../../../src'
import { Before, When } from '../../../src'

Before((): void => undefined)
Before(() => undefined)

When(
'the string {string} is attached as {string}',
async function (this: World, text: string, mediaType: string) {
await this.attach(text, mediaType)
function (text: string, mediaType: string) {
this.attach(text, mediaType)
}
)

When(
'the string {string} is logged',
async function (this: World, text: string) {
await this.log(text)
}
)
When('the string {string} is logged', function (text: string) {
this.log(text)
})

When('text with ANSI escapes is logged', async function (this: World) {
await this.log(
When('text with ANSI escapes is logged', function () {
this.log(
'This displays a \x1b[31mr\x1b[0m\x1b[91ma\x1b[0m\x1b[33mi\x1b[0m\x1b[32mn\x1b[0m\x1b[34mb\x1b[0m\x1b[95mo\x1b[0m\x1b[35mw\x1b[0m'
)
})

When(
'the following string is attached as {string}:',
async function (this: World, mediaType: string, text: string) {
await this.attach(text, mediaType)
function (mediaType: string, text: string) {
this.attach(text, mediaType)
}
)

When(
'an array with {int} bytes is attached as {string}',
async function (this: World, size: number, mediaType: string) {
function (size: number, mediaType: string) {
const data = [...Array(size).keys()]
const buffer = Buffer.from(data)
await this.attach(buffer, mediaType)
this.attach(buffer, mediaType)
}
)

When(
'a stream with {int} bytes are attached as {string}',
async function (this: World, size: number, mediaType: string) {
const data = [...Array(size).keys()]
const buffer = Buffer.from(data)
const stream = new ReadableStreamBuffer({ chunkSize: 1, frequency: 1 })
stream.put(buffer)
stream.stop()
await this.attach(stream, mediaType)
}
)
When('a JPEG image is attached', async function () {
await this.attach(
fs.createReadStream(
path.join(
process.cwd(),
'node_modules',
'@cucumber',
'compatibility-kit',
'features',
'attachments',
'cucumber.jpeg'
)
),
'image/jpeg'
)
})

When('a JPEG image is attached', async function (this: World) {
When('a PNG image is attached', async function () {
await this.attach(
fs.createReadStream(
path.join(
Expand All @@ -70,7 +71,7 @@ When('a JPEG image is attached', async function (this: World) {
)
})

When('the {word} png is attached', async function (filename) {
When('a PDF document is attached and renamed', async function () {
await this.attach(
fs.createReadStream(
path.join(
Expand All @@ -80,32 +81,12 @@ When('the {word} png is attached', async function (filename) {
'compatibility-kit',
'features',
'attachments',
filename
'document.pdf'
)
),
'image/png'
{
mediaType: 'application/pdf',
fileName: 'renamed.pdf',
}
)
})

When(
'a PDF document is attached with a filename',
async function (this: World) {
await this.attach(
fs.createReadStream(
path.join(
process.cwd(),
'node_modules',
'@cucumber',
'compatibility-kit',
'features',
'attachments',
'document.pdf'
)
),
{
mediaType: 'application/pdf',
fileName: 'document.pdf',
}
)
}
)
8 changes: 4 additions & 4 deletions compatibility/features/hooks/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'node:fs'
import path from 'node:path'
import { When, Before, After, World } from '../../../src'
import { When, Before, After } from '../../../src'

Before(function () {
// no-op
Expand All @@ -14,19 +14,19 @@ When('a step passes', function () {
// no-op
})

When('a step throws an exception', function () {
When('a step fails', function () {
throw new Error('Exception in step')
})

After(function () {
throw new Error('Exception in hook')
// no-op
})

After('@some-tag or @some-other-tag', function () {
throw new Error('Exception in conditional hook')
})

After('@with-attachment', async function (this: World) {
After('@with-attachment', async function () {
await this.attach(
fs.createReadStream(
path.join(
Expand Down
14 changes: 5 additions & 9 deletions compatibility/features/parameter-types/parameter-types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect } from 'chai'
import assert from 'node:assert'
import { Given, defineParameterType } from '../../../src'

class Flight {
Expand All @@ -16,11 +16,7 @@ defineParameterType({
},
})

Given(
'{flight} has been delayed {int} minutes',
function (flight: Flight, delay: number) {
expect(flight.from).to.eq('LHR')
expect(flight.to).to.eq('CDG')
expect(delay).to.eq(45)
}
)
Given('{flight} has been delayed', function (flight: Flight) {
assert.strictEqual(flight.from, 'LHR')
assert.strictEqual(flight.to, 'CDG')
})
10 changes: 5 additions & 5 deletions compatibility/features/pending/pending.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Given } from '../../../src'

Given('an implemented step', function () {
Given('an implemented non-pending step', function () {
// no-op
})

Given('a step that isnt implemented yet', function () {
return 'pending'
Given('an implemented step that is skipped', function () {
// no-op
})

Given('a step that we expect to be skipped', function () {
// no-op
Given('an unimplemented pending step', function () {
return 'pending'
})
44 changes: 15 additions & 29 deletions compatibility/features/rules/rules.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,28 @@
import assert from 'node:assert'
import { Given, When, Then } from '../../../src'

Given(
'there are {int} {float} coins inside',
function (count: number, denomination: number) {
// TODO: implement this
assert(count)
assert(denomination)
}
)
Given('the customer has {int} cents', function (money) {
this.money = money
})

Given('there are no chocolates inside', function () {
// TODO: implement this
Given('there are chocolate bars in stock', function () {
this.stock = ['Mars']
})

Given('there are {int} chocolates inside', function (chocolateCount: number) {
// TODO: implement this
assert(chocolateCount)
Given('there are no chocolate bars in stock', function () {
this.stock = []
})

When(
'the customer tries to buy a {float} chocolate with a {float} coin',
function (price: number, paid: number) {
// TODO: implement this
assert(price)
assert(paid)
When('the customer tries to buy a {int} cent chocolate bar', function (price) {
if (this.money >= price) {
this.chocolate = this.stock.pop()
}
)
})

Then('the sale should not happen', function () {
// TODO: implement this
assert.strictEqual(this.chocolate, undefined)
})

Then(
"the customer's change should be {int} {float} coin(s)",
function (count: number, denomination: number) {
// TODO: implement this
assert(count)
assert(denomination)
}
)
Then('the sale should happen', function () {
assert.ok(this.chocolate)
})
6 changes: 3 additions & 3 deletions compatibility/features/skipped/skipped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ Before('@skip', function () {
return 'skipped'
})

Given('an implemented step', function () {
Given('a step that does not skip', function () {
// no-op
})

Given('a step that we expect to be skipped', function () {
Given('a step that is skipped', function () {
// no-op
})

Given('a step that skips', function () {
Given('I skip a step', function () {
return 'skipped'
})
2 changes: 1 addition & 1 deletion compatibility/features/undefined/undefined.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ Given('an implemented step', function () {
// no-op
})

Given('a step that we expect to be skipped', function () {
Given('a step that will be skipped', function () {
// no-op
})
Loading

0 comments on commit 835215e

Please sign in to comment.