Skip to content

Commit

Permalink
fix: include original coordinates in support code library (#2197)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjgoss authored Dec 15, 2022
1 parent c2227ed commit 8b89a9c
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 38 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
Please see [CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CONTRIBUTING.md) on how to contribute to Cucumber.

## [Unreleased]
### Fixed
- Include original coordinates in `loadSupport` result ([#2197](https://github.com/cucumber/cucumber-js/pull/2197))

## [8.9.0] - 2022-11-24
### Added
Expand Down
25 changes: 25 additions & 0 deletions src/api/load_support_spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { IRunEnvironment } from './types'
import path from 'path'
import { loadSupport } from './load_support'
import { loadConfiguration } from './load_configuration'
import { expect } from 'chai'
import { setupEnvironment, teardownEnvironment } from './test_helpers'

describe('loadSupport', () => {
let environment: IRunEnvironment
beforeEach(async () => {
environment = await setupEnvironment()
})
afterEach(async () => teardownEnvironment(environment))

it('should include original paths in the returned support code library', async () => {
const { runConfiguration } = await loadConfiguration({}, environment)
const support = await loadSupport(runConfiguration, environment)

expect(support.originalCoordinates).to.deep.eq({
requireModules: ['ts-node/register'],
requirePaths: [path.join(environment.cwd, 'features', 'steps.ts')],
importPaths: [],
})
})
})
38 changes: 2 additions & 36 deletions src/api/run_cucumber_spec.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,10 @@
import { Envelope, TestStepResultStatus, IdGenerator } from '@cucumber/messages'
import fs from 'mz/fs'
import path from 'path'
import { reindent } from 'reindent-template-literals'
import { PassThrough } from 'stream'
import { Envelope, TestStepResultStatus } from '@cucumber/messages'
import { expect } from 'chai'
import { runCucumber } from './run_cucumber'
import { IRunEnvironment } from './types'
import { loadSupport } from './load_support'
import { loadConfiguration } from './load_configuration'

const newId = IdGenerator.uuid()

async function setupEnvironment(): Promise<Partial<IRunEnvironment>> {
const cwd = path.join(__dirname, '..', '..', 'tmp', `runCucumber_${newId()}`)
await fs.mkdir(path.join(cwd, 'features'), { recursive: true })
await fs.writeFile(
path.join(cwd, 'features', 'test.feature'),
reindent(`Feature: test fixture
Scenario: one
Given a step
Then another step`)
)
await fs.writeFile(
path.join(cwd, 'features', 'steps.ts'),
reindent(`import { Given, Then } from '../../../src'
Given('a step', function () {})
Then('another step', function () {})`)
)
await fs.writeFile(
path.join(cwd, 'cucumber.mjs'),
`export default {paths: ['features/test.feature'], requireModule: ['ts-node/register'], require: ['features/steps.ts']}`
)
const stdout = new PassThrough()
return { cwd, stdout }
}

async function teardownEnvironment(environment: IRunEnvironment) {
await fs.rmdir(environment.cwd, { recursive: true })
environment.stdout.end()
}
import { setupEnvironment, teardownEnvironment } from './test_helpers'

describe('runCucumber', () => {
describe('preloading support code', () => {
Expand Down
6 changes: 5 additions & 1 deletion src/api/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ export async function getSupportCodeLibrary({
requirePaths: string[]
importPaths: string[]
}): Promise<ISupportCodeLibrary> {
supportCodeLibraryBuilder.reset(cwd, newId)
supportCodeLibraryBuilder.reset(cwd, newId, {
requireModules,
requirePaths,
importPaths,
})
requireModules.map((module) => require(module))
requirePaths.map((path) => require(path))
for (const path of importPaths) {
Expand Down
37 changes: 37 additions & 0 deletions src/api/test_helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { IRunEnvironment } from './types'
import path from 'path'
import fs from 'mz/fs'
import { reindent } from 'reindent-template-literals'
import { PassThrough } from 'stream'
import { IdGenerator } from '@cucumber/messages'

const newId = IdGenerator.uuid()

export async function setupEnvironment(): Promise<Partial<IRunEnvironment>> {
const cwd = path.join(__dirname, '..', '..', 'tmp', `api_${newId()}`)
await fs.mkdir(path.join(cwd, 'features'), { recursive: true })
await fs.writeFile(
path.join(cwd, 'features', 'test.feature'),
reindent(`Feature: test fixture
Scenario: one
Given a step
Then another step`)
)
await fs.writeFile(
path.join(cwd, 'features', 'steps.ts'),
reindent(`import { Given, Then } from '../../../src'
Given('a step', function () {})
Then('another step', function () {})`)
)
await fs.writeFile(
path.join(cwd, 'cucumber.mjs'),
`export default {paths: ['features/test.feature'], requireModule: ['ts-node/register'], require: ['features/steps.ts']}`
)
const stdout = new PassThrough()
return { cwd, stdout }
}

export async function teardownEnvironment(environment: IRunEnvironment) {
await fs.rmdir(environment.cwd, { recursive: true })
environment.stdout.end()
}
6 changes: 5 additions & 1 deletion src/runtime/parallel/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ export default class Worker {
supportCodeIds,
options,
}: IWorkerCommandInitialize): Promise<void> {
supportCodeLibraryBuilder.reset(this.cwd, this.newId)
supportCodeLibraryBuilder.reset(this.cwd, this.newId, {
requireModules,
requirePaths,
importPaths,
})
requireModules.map((module) => require(module))
requirePaths.map((module) => require(module))
for (const path of importPaths) {
Expand Down

0 comments on commit 8b89a9c

Please sign in to comment.