Skip to content

Commit

Permalink
build: add noImplicitAny and noImplicitReturns, fix compilation (#1286)
Browse files Browse the repository at this point in the history
* add noImplicitReturns to tsconfig.json

* add noImplicitAny to tsconfig.json

* some progress

* more progress

* add typings for verror package

* more progress

* more progress

* whoops

* more progress

* this interface was a bit unnecessary

* use I convention consistently on types

* install types for progress library

* more progress

* more progress

* nearly there

* add typings for resolve

* almost

* fix more test code

* fix type from any to string

* fix up compilation for feature test support code

* declare types in way that works for both typescript and ts-node

* fix all of the unit tests!

* use `ensureSymlinkSync` as it's in the documented API

* use EventEmitter instead of custom interface

* fix up cucumber-messages imports

* remove empty lines

* remove unnecessary Partial

* move type to appropriate file

* create interfaces for helper function request objects

* avoid awkward casting by adding PassThrough to formatter stream interface

* drop redundant key from objct literal

* fix last few issues after merging master
  • Loading branch information
davidjgoss committed Mar 7, 2020
1 parent 6b2b1df commit cf676b8
Show file tree
Hide file tree
Showing 73 changed files with 618 additions and 239 deletions.
20 changes: 13 additions & 7 deletions features/step_definitions/cli_steps.ts
@@ -1,4 +1,4 @@
import { When, Then } from '../../'
import { When, Then, DataTable } from '../../'
import { expect } from 'chai'
import { normalizeText } from '../support/helpers'
import stringArgv from 'string-argv'
Expand Down Expand Up @@ -39,7 +39,7 @@ When(
When(
/^I run cucumber-js \(installed (locally|globally)\)$/,
{ timeout: 10000 },
async function(this: World, location) {
async function(this: World, location: string) {
if (location === 'locally') {
return this.run(this.localExecutablePath, [])
}
Expand All @@ -57,27 +57,30 @@ Then(/^it fails$/, function(this: World) {
this.verifiedLastRunError = true
})

Then(/^it outputs the text:$/, function(this: World, text) {
Then(/^it outputs the text:$/, function(this: World, text: string) {
const actualOutput = normalizeText(this.lastRun.output)
const expectedOutput = normalizeText(text)
expect(actualOutput).to.eql(expectedOutput)
})

Then(/^the output contains the text:$/, function(this: World, text) {
Then(/^the output contains the text:$/, function(this: World, text: string) {
const actualOutput = normalizeText(this.lastRun.output)
const expectedOutput = normalizeText(text)
expect(actualOutput).to.include(expectedOutput)
})

Then('the output does not contain the text:', function(this: World, text) {
Then('the output does not contain the text:', function(
this: World,
text: string
) {
const actualOutput = normalizeText(this.lastRun.output)
const expectedOutput = normalizeText(text)
expect(actualOutput).not.to.include(expectedOutput)
})

Then(/^the error output contains the text snippets:$/, function(
this: World,
table
table: DataTable
) {
const actualOutput = normalizeText(this.lastRun.errorOutput)
table.rows().forEach(row => {
Expand All @@ -86,7 +89,10 @@ Then(/^the error output contains the text snippets:$/, function(
})
})

Then(/^the error output contains the text:$/, function(this: World, text) {
Then(/^the error output contains the text:$/, function(
this: World,
text: string
) {
const actualOutput = normalizeText(this.lastRun.errorOutput)
const expectedOutput = normalizeText(text)
expect(actualOutput).to.include(expectedOutput)
Expand Down
31 changes: 20 additions & 11 deletions features/step_definitions/file_steps.ts
Expand Up @@ -7,37 +7,46 @@ import path from 'path'
import Mustache from 'mustache'
import { World } from '../support/world'

Given(/^a file named "(.*)" with:$/, function(
Given(/^a file named "(.*)" with:$/, async function(
this: World,
filePath,
fileContent
filePath: string,
fileContent: string
) {
const absoluteFilePath = path.join(this.tmpDir, filePath)
if (filePath === '@rerun.txt') {
fileContent = fileContent.replace(/\//g, path.sep)
}
return fsExtra.outputFile(absoluteFilePath, fileContent)
await fsExtra.outputFile(absoluteFilePath, fileContent)
})

Given(/^an empty file named "(.*)"$/, function(this: World, filePath) {
Given(/^an empty file named "(.*)"$/, async function(
this: World,
filePath: string
) {
const absoluteFilePath = path.join(this.tmpDir, filePath)
return fsExtra.outputFile(absoluteFilePath, '')
await fsExtra.outputFile(absoluteFilePath, '')
})

Given(/^a directory named "(.*)"$/, function(this: World, filePath) {
Given(/^a directory named "(.*)"$/, async function(
this: World,
filePath: string
) {
const absoluteFilePath = path.join(this.tmpDir, filePath)
return fsExtra.mkdirp(absoluteFilePath)
await fsExtra.mkdirp(absoluteFilePath)
})

Given(/^"([^"]*)" is an absolute path$/, function(this: World, filePath) {
Given(/^"([^"]*)" is an absolute path$/, function(
this: World,
filePath: string
) {
filePath = Mustache.render(filePath, this)
expect(path.isAbsolute(filePath)).to.eql(true)
})

Then(/^the file "([^"]*)" has the text:$/, async function(
this: World,
filePath,
text
filePath: string,
text: string
) {
filePath = Mustache.render(filePath, this)
const absoluteFilePath = path.resolve(this.tmpDir, filePath)
Expand Down
7 changes: 3 additions & 4 deletions features/step_definitions/fixture_steps.ts
Expand Up @@ -6,17 +6,16 @@ import {
} from '../support/formatter_output_helpers'
import fs from 'mz/fs'
import path from 'path'
import { World } from '../support/world'
import { messages } from 'cucumber-messages'
import { World } from '../support/world'
import Envelope = messages.Envelope

Then(
'the {string} formatter output matches the fixture {string}',
async function(this: World, formatter: string, filePath: string) {
let actual: any
if (formatter === 'message') {
actual = this.lastRun.envelopes.map(e =>
(e as messages.Envelope).toJSON()
)
actual = this.lastRun.envelopes.map((e: Envelope) => e.toJSON())
actual = normalizeMessageOutput(actual, this.tmpDir)
} else {
const actualPath = path.join(this.tmpDir, `${formatter}.out`)
Expand Down
105 changes: 64 additions & 41 deletions features/step_definitions/message_steps.ts
Expand Up @@ -3,59 +3,70 @@ import { Then } from '../../'
import { expect } from 'chai'
import DataTable from '../../src/models/data_table'
import {
getPickleStep,
getPickleNamesInOrderOfExecution,
getPickleStep,
getTestCaseResult,
getTestStepAttachmentsForStep,
getTestStepAttachmentsForHook,
getTestStepAttachmentsForStep,
getTestStepResults,
} from '../support/message_helpers'
import { messages } from 'cucumber-messages'
import { World } from '../support/world'

type StringifiedStatus =
| 'UNKNOWN'
| 'PASSED'
| 'SKIPPED'
| 'PENDING'
| 'UNDEFINED'
| 'AMBIGUOUS'
| 'FAILED'

const { Status } = messages.TestResult

Then('it runs {int} scenarios', function(this: World, expectedCount) {
Then('it runs {int} scenarios', function(this: World, expectedCount: number) {
const testCaseStartedEvents = _.filter(
this.lastRun.envelopes,
e => e.testCaseStarted
)
expect(testCaseStartedEvents).to.have.lengthOf(expectedCount)
})

Then('it runs the scenario {string}', function(this: World, name) {
Then('it runs the scenario {string}', function(this: World, name: string) {
const actualNames = getPickleNamesInOrderOfExecution(this.lastRun.envelopes)
expect(actualNames).to.eql([name])
})

Then('it runs the scenarios {string} and {string}', function(
this: World,
name1,
name2
name1: string,
name2: string
) {
const actualNames = getPickleNamesInOrderOfExecution(this.lastRun.envelopes)
expect(actualNames).to.eql([name1, name2])
})

Then('it runs the scenarios:', function(this: World, table) {
Then('it runs the scenarios:', function(this: World, table: DataTable) {
const expectedNames = table.rows().map(row => row[0])
const actualNames = getPickleNamesInOrderOfExecution(this.lastRun.envelopes)
expect(expectedNames).to.eql(actualNames)
})

Then('scenario {string} has status {string}', function(
this: World,
name,
status
name: string,
status: string
) {
const result = getTestCaseResult(this.lastRun.envelopes, name)
expect(result.status).to.eql(Status[status.toUpperCase()])
expect(result.status).to.eql(
Status[status.toUpperCase() as StringifiedStatus]
)
})

Then('the scenario {string} has the steps:', function(
this: World,
name,
table
name: string,
table: DataTable
) {
const actualTexts = getTestStepResults(this.lastRun.envelopes, name).map(
s => s.text
Expand All @@ -66,44 +77,56 @@ Then('the scenario {string} has the steps:', function(

Then('scenario {string} step {string} has status {string}', function(
this: World,
pickleName,
stepText,
status
pickleName: string,
stepText: string,
status: string
) {
const testStepResults = getTestStepResults(this.lastRun.envelopes, pickleName)
const testStepResult = _.find(testStepResults, ['text', stepText])
expect(testStepResult.result.status).to.eql(Status[status.toUpperCase()])
expect(testStepResult.result.status).to.eql(
Status[status.toUpperCase() as StringifiedStatus]
)
})

Then(
'scenario {string} attempt {int} step {string} has status {string}',
function(this: World, pickleName, attempt, stepText, status) {
function(
this: World,
pickleName: string,
attempt: number,
stepText: string,
status: string
) {
const testStepResults = getTestStepResults(
this.lastRun.envelopes,
pickleName,
attempt
)
const testStepResult = _.find(testStepResults, ['text', stepText])
expect(testStepResult.result.status).to.eql(Status[status.toUpperCase()])
expect(testStepResult.result.status).to.eql(
Status[status.toUpperCase() as StringifiedStatus]
)
}
)

Then('scenario {string} {string} hook has status {string}', function(
this: World,
pickleName,
hookKeyword,
status
pickleName: string,
hookKeyword: string,
status: string
) {
const testStepResults = getTestStepResults(this.lastRun.envelopes, pickleName)
const testStepResult = _.find(testStepResults, ['text', hookKeyword])
expect(testStepResult.result.status).to.eql(Status[status.toUpperCase()])
expect(testStepResult.result.status).to.eql(
Status[status.toUpperCase() as StringifiedStatus]
)
})

Then('scenario {string} step {string} failed with:', function(
this: World,
pickleName,
stepText,
errorMessage
pickleName: string,
stepText: string,
errorMessage: string
) {
const testStepResults = getTestStepResults(this.lastRun.envelopes, pickleName)
const testStepResult = _.find(testStepResults, ['text', stepText])
Expand All @@ -113,10 +136,10 @@ Then('scenario {string} step {string} failed with:', function(

Then('scenario {string} attempt {int} step {string} failed with:', function(
this: World,
pickleName,
attempt,
stepText,
errorMessage
pickleName: string,
attempt: number,
stepText: string,
errorMessage: string
) {
const testStepResults = getTestStepResults(
this.lastRun.envelopes,
Expand All @@ -130,29 +153,29 @@ Then('scenario {string} attempt {int} step {string} failed with:', function(

Then('scenario {string} step {string} has the doc string:', function(
this: World,
pickleName,
stepText,
docString
pickleName: string,
stepText: string,
docString: string
) {
const pickleStep = getPickleStep(this.lastRun.envelopes, pickleName, stepText)
expect(pickleStep.argument.docString.content).to.eql(docString)
})

Then('scenario {string} step {string} has the data table:', function(
this: World,
pickleName,
stepText,
dataTable
pickleName: string,
stepText: string,
dataTable: DataTable
) {
const pickleStep = getPickleStep(this.lastRun.envelopes, pickleName, stepText)
expect(new DataTable(pickleStep.argument.dataTable)).to.eql(dataTable)
})

Then('scenario {string} step {string} has the attachments:', function(
this: World,
pickleName,
stepText,
table
pickleName: string,
stepText: string,
table: DataTable
) {
const expectedAttachments = table.hashes().map(x => {
return {
Expand All @@ -176,9 +199,9 @@ Then('scenario {string} step {string} has the attachments:', function(

Then('scenario {string} {string} hook has the attachments:', function(
this: World,
pickleName,
hookKeyword,
table
pickleName: string,
hookKeyword: string,
table: DataTable
) {
const expectedAttachments = table.hashes().map(x => {
return {
Expand Down
6 changes: 3 additions & 3 deletions features/step_definitions/usage_json_steps.ts
@@ -1,12 +1,12 @@
import _ from 'lodash'
import { Then } from '../../'
import { Then, DataTable } from '../../'
import { expect } from 'chai'
import path from 'path'
import { World } from '../support/world'

Then('it outputs the usage data:', function(this: World, table) {
Then('it outputs the usage data:', function(this: World, table: DataTable) {
const usageData = JSON.parse(this.lastRun.output)
table.hashes().forEach(row => {
table.hashes().forEach((row: any) => {
const rowUsage = _.find(
usageData,
datum =>
Expand Down
4 changes: 2 additions & 2 deletions features/support/hooks.ts
Expand Up @@ -37,7 +37,7 @@ Before(function(

const tmpDirNodeModulesPath = path.join(this.tmpDir, 'node_modules')
const tmpDirCucumberPath = path.join(tmpDirNodeModulesPath, 'cucumber')
fsExtra.createSymlinkSync(projectPath, tmpDirCucumberPath)
fsExtra.ensureSymlinkSync(projectPath, tmpDirCucumberPath)
this.localExecutablePath = path.join(projectPath, 'bin', 'cucumber-js')
})

Expand All @@ -55,7 +55,7 @@ Before('@global-install', function(this: World) {
'node_modules',
moduleName
)
fsExtra.createSymlinkSync(
fsExtra.ensureSymlinkSync(
projectNodeModulePath,
globalInstallNodeModulePath
)
Expand Down

0 comments on commit cf676b8

Please sign in to comment.