Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: switch from colors to chalk #1895

Merged
merged 6 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
### Changed
- Switch from `colors` to `chalk` for terminal coloring ([#1895](https://github.com/cucumber/cucumber-js/pull/1895))

## [8.0.0-rc.2] - 2022-01-10
### Added
Expand Down
4 changes: 2 additions & 2 deletions features/support/warn_user_about_enabling_developer_mode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { reindent } from 'reindent-template-literals'
import colors from 'colors/safe'
import chalk from 'chalk'

export function warnUserAboutEnablingDeveloperMode(error: any): void {
if (!(error?.code === 'EPERM')) {
Expand All @@ -10,7 +10,7 @@ export function warnUserAboutEnablingDeveloperMode(error: any): void {
}

console.error(
colors.red(
chalk.red(
reindent(`
Error: Unable to run feature tests!

Expand Down
4 changes: 2 additions & 2 deletions features/support/world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { execFile } from 'child_process'
import { expect } from 'chai'
import toString from 'stream-to-string'
import { PassThrough, pipeline, Writable } from 'stream'
import colors from 'colors/safe'
import stripAnsi from 'strip-ansi'
import fs from 'fs'
import path from 'path'
import VError from 'verror'
Expand Down Expand Up @@ -122,7 +122,7 @@ export class World {
error: result.error,
errorOutput: result.stderr,
envelopes,
output: colors.strip(result.stdout),
output: stripAnsi(result.stdout),
}
this.verifiedLastRunError = false
expect(this.lastRun.output).to.not.include('Unhandled rejection')
Expand Down
25 changes: 8 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@
"@cucumber/tag-expressions": "4.1.0",
"assertion-error-formatter": "^3.0.0",
"capital-case": "^1.0.4",
"chalk": "^4.1.2",
"cli-table3": "0.6.1",
"colors": "1.4.0",
"commander": "^8.0.0",
"duration": "^0.2.2",
"durations": "^3.4.2",
Expand Down Expand Up @@ -263,6 +263,7 @@
"sinon-chai": "3.7.0",
"stream-buffers": "3.0.2",
"stream-to-string": "1.2.0",
"strip-ansi": "^6.0.1",
"ts-node": "10.4.0",
"tsd": "0.19.1",
"typescript": "4.5.4"
Expand Down
12 changes: 6 additions & 6 deletions src/cli/publish_banner.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import colors from 'colors/safe'
import chalk from 'chalk'
import Table from 'cli-table3'

const underlineBoldCyan = (x: string): string =>
colors.underline(colors.bold(colors.cyan(x)))
chalk.underline(chalk.bold(chalk.cyan(x)))

const formattedReportUrl = underlineBoldCyan('https://reports.cucumber.io')
const formattedEnv =
colors.cyan('CUCUMBER_PUBLISH_ENABLED') + '=' + colors.cyan('true')
chalk.cyan('CUCUMBER_PUBLISH_ENABLED') + '=' + chalk.cyan('true')
const formattedMoreInfoUrl = underlineBoldCyan(
'https://cucumber.io/docs/cucumber/environment-variables/'
)

const text = `\
Share your Cucumber Report with your team at ${formattedReportUrl}

Command line option: ${colors.cyan('--publish')}
Command line option: ${chalk.cyan('--publish')}
Environment variable: ${formattedEnv}

More information at ${formattedMoreInfoUrl}

To disable this message, add this to your ${colors.bold('./cucumber.js')}:
${colors.bold("module.exports = { default: '--publish-quiet' }")}`
To disable this message, add this to your ${chalk.bold('./cucumber.js')}:
${chalk.bold("module.exports = { default: '--publish-quiet' }")}`

const table = new Table({
style: {
Expand Down
30 changes: 14 additions & 16 deletions src/formatter/get_color_fns.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import colors from 'colors/safe'
import chalk from 'chalk'
import { TestStepResultStatus } from '@cucumber/messages'

colors.enable()

export type IColorFn = (text: string) => string

export interface IColorFns {
Expand All @@ -20,21 +18,21 @@ export default function getColorFns(enabled: boolean): IColorFns {
return {
forStatus(status: TestStepResultStatus) {
return {
AMBIGUOUS: colors.red.bind(colors),
FAILED: colors.red.bind(colors),
PASSED: colors.green.bind(colors),
PENDING: colors.yellow.bind(colors),
SKIPPED: colors.cyan.bind(colors),
UNDEFINED: colors.yellow.bind(colors),
UNKNOWN: colors.yellow.bind(colors),
AMBIGUOUS: chalk.red.bind(chalk),
FAILED: chalk.red.bind(chalk),
PASSED: chalk.green.bind(chalk),
PENDING: chalk.yellow.bind(chalk),
SKIPPED: chalk.cyan.bind(chalk),
UNDEFINED: chalk.yellow.bind(chalk),
UNKNOWN: chalk.yellow.bind(chalk),
}[status]
},
location: colors.gray.bind(colors),
tag: colors.cyan.bind(colors),
diffAdded: colors.green.bind(colors),
diffRemoved: colors.red.bind(colors),
errorMessage: colors.red.bind(colors),
errorStack: colors.grey.bind(colors),
location: chalk.gray.bind(chalk),
tag: chalk.cyan.bind(chalk),
diffAdded: chalk.green.bind(chalk),
diffRemoved: chalk.red.bind(chalk),
errorMessage: chalk.red.bind(chalk),
errorStack: chalk.grey.bind(chalk),
}
} else {
return {
Expand Down