Skip to content

Commit

Permalink
make the logging nicer and reference the doc
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjgoss committed Oct 6, 2023
1 parent be6dc50 commit 242ffb6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
5 changes: 4 additions & 1 deletion src/configuration/split_format_descriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export function splitFormatDescriptor(
if (result[1]) {
expected += `:"${result[1]}"`
}
logger.warn(`Should be ${expected}`)
logger.warn(
`Each part of a user-specified format should be quoted; see https://github.com/cucumber/cucumber-js/blob/main/docs/deprecations.md#ambiguous-colons-in-formats
Change to ${expected}`
)
}
let result: string[]
let match1, match2
Expand Down
41 changes: 21 additions & 20 deletions src/configuration/split_format_descriptor_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('splitFormatDescriptor', () => {
input: 'file:///custom/formatter:file:///formatter/output.txt',
output: ['file:///custom/formatter', 'file:///formatter/output.txt'],
warning:
'Should be "file:///custom/formatter":"file:///formatter/output.txt"',
'Change to "file:///custom/formatter":"file:///formatter/output.txt"',
},
{
description: 'splits file URLs for UNC path',
Expand All @@ -36,7 +36,7 @@ describe('splitFormatDescriptor', () => {
'file://hostname/formatter/output.txt',
],
warning:
'Should be "file://hostname/custom/formatter":"file://hostname/formatter/output.txt"',
'Change to "file://hostname/custom/formatter":"file://hostname/formatter/output.txt"',
},
{
description: 'splits file URLs for absolute windows path',
Expand All @@ -46,7 +46,7 @@ describe('splitFormatDescriptor', () => {
'file://C:\\formatter\\output.txt',
],
warning:
'Should be "file://C:\\custom\\formatter":"file://C:\\formatter\\output.txt"',
'Change to "file://C:\\custom\\formatter":"file://C:\\formatter\\output.txt"',
},
{
description:
Expand All @@ -57,7 +57,7 @@ describe('splitFormatDescriptor', () => {
'file:///C:/formatter/output.txt',
],
warning:
'Should be "file:///C:/custom/formatter":"file:///C:/formatter/output.txt"',
'Change to "file:///C:/custom/formatter":"file:///C:/formatter/output.txt"',
},
{
description: 'splits valid file URLs for absolute windows path',
Expand All @@ -67,7 +67,7 @@ describe('splitFormatDescriptor', () => {
'file:///C:\\formatter\\output.txt',
],
warning:
'Should be "file:///C:\\custom\\formatter":"file:///C:\\formatter\\output.txt"',
'Change to "file:///C:\\custom\\formatter":"file:///C:\\formatter\\output.txt"',
},
{
description:
Expand All @@ -78,7 +78,7 @@ describe('splitFormatDescriptor', () => {
'file:///C:/formatter/output.txt',
],
warning:
'Should be "file:///C:/custom/formatter":"file:///C:/formatter/output.txt"',
'Change to "file:///C:/custom/formatter":"file:///C:/formatter/output.txt"',
},
{
description: 'splits absolute unix paths',
Expand All @@ -89,14 +89,14 @@ describe('splitFormatDescriptor', () => {
description: 'splits absolute windows paths',
input: 'C:\\custom\\formatter:C:\\formatter\\output.txt',
output: ['C:\\custom\\formatter', 'C:\\formatter\\output.txt'],
warning: 'Should be "C:\\custom\\formatter":"C:\\formatter\\output.txt"',
warning: 'Change to "C:\\custom\\formatter":"C:\\formatter\\output.txt"',
},
{
description:
'splits absolute windows paths with "/" as directory separator',
input: 'C:/custom/formatter:C:/formatter/output.txt',
output: ['C:/custom/formatter', 'C:/formatter/output.txt'],
warning: 'Should be "C:/custom/formatter":"C:/formatter/output.txt"',
warning: 'Change to "C:/custom/formatter":"C:/formatter/output.txt"',
},
{
description: 'splits UNC paths',
Expand Down Expand Up @@ -125,56 +125,56 @@ describe('splitFormatDescriptor', () => {
'does not split a single file URL for absolute unix path, adds empty string',
input: 'file:///custom/formatter',
output: ['file:///custom/formatter', ''],
warning: 'Should be "file:///custom/formatter"',
warning: 'Change to "file:///custom/formatter"',
},
{
description:
'does not split a single file URL for UNC path, adds empty string',
input: 'file://hostname/custom/formatter',
output: ['file://hostname/custom/formatter', ''],
warning: 'Should be "file://hostname/custom/formatter"',
warning: 'Change to "file://hostname/custom/formatter"',
},
{
description:
'does not split a single file URL for absolute windows path, adds empty string',
input: 'file://C:\\custom\\formatter',
output: ['file://C:\\custom\\formatter', ''],
warning: 'Should be "file://C:\\custom\\formatter"',
warning: 'Change to "file://C:\\custom\\formatter"',
},
{
description:
'does not split a single file URL for absolute windows path with "/" as directory separator, adds empty string',
input: 'file://C:/custom/formatter',
output: ['file://C:/custom/formatter', ''],
warning: 'Should be "file://C:/custom/formatter"',
warning: 'Change to "file://C:/custom/formatter"',
},
{
description:
'does not split a valid single file URL for absolute windows path, adds empty string',
input: 'file:///C:\\custom\\formatter',
output: ['file:///C:\\custom\\formatter', ''],
warning: 'Should be "file:///C:\\custom\\formatter"',
warning: 'Change to "file:///C:\\custom\\formatter"',
},
{
description:
'does not split a valid single file URL for absolute windows path with "/" as directory separator, adds empty string',
input: 'file:///C:/custom/formatter',
output: ['file:///C:/custom/formatter', ''],
warning: 'Should be "file:///C:/custom/formatter"',
warning: 'Change to "file:///C:/custom/formatter"',
},
{
description:
'does not split a single absolute windows path, adds empty string',
input: 'C:\\custom\\formatter',
output: ['C:\\custom\\formatter', ''],
warning: 'Should be "C:\\custom\\formatter"',
warning: 'Change to "C:\\custom\\formatter"',
},
{
description:
'does not split a single absolute windows path with "/" as directory separator, adds empty string',
input: 'C:/custom/formatter',
output: ['C:/custom/formatter', ''],
warning: 'Should be "C:/custom/formatter"',
warning: 'Change to "C:/custom/formatter"',
},
{
description: 'does not split quoted values: case 1',
Expand All @@ -185,13 +185,13 @@ describe('splitFormatDescriptor', () => {
description: 'does not split quoted values: case 2',
input: '"foo:bar":baz:qux',
output: ['foo:bar', 'baz:qux'],
warning: 'Should be "foo:bar":"baz:qux"',
warning: 'Change to "foo:bar":"baz:qux"',
},
{
description: 'does not split quoted values: case 3',
input: 'foo:bar:"baz:qux"',
output: ['foo:bar', 'baz:qux'],
warning: 'Should be "foo:bar":"baz:qux"',
warning: 'Change to "foo:bar":"baz:qux"',
},
{
description: 'does not split quoted values: case 4',
Expand All @@ -202,7 +202,7 @@ describe('splitFormatDescriptor', () => {
description: 'splits string contains multiple ":"',
input: 'foo:bar:baz:qux',
output: ['foo', 'bar:baz:qux'],
warning: 'Should be "foo":"bar:baz:qux"',
warning: 'Change to "foo":"bar:baz:qux"',
},
]

Expand All @@ -211,7 +211,8 @@ describe('splitFormatDescriptor', () => {
const logger = new FakeLogger()
expect(splitFormatDescriptor(logger, input)).to.eql(output)
if (warning) {
expect(logger.warn).to.have.been.calledWith(warning)
expect(logger.warn).to.have.been.called()
expect(logger.warn.firstCall.firstArg as string).to.contain(warning)
} else {
expect(logger.warn).not.to.have.been.called()
}
Expand Down

0 comments on commit 242ffb6

Please sign in to comment.