Skip to content

Commit

Permalink
fix: respect color support before using ansi colors
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Apr 16, 2024
1 parent 9848c32 commit b7be1a5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
"getopts": "^2.3.0",
"ms": "^2.1.3",
"serialize-error": "^11.0.3",
"slash": "^5.1.0"
"slash": "^5.1.0",
"supports-color": "^9.4.0"
},
"author": "virk,japa",
"license": "MIT",
Expand Down
50 changes: 24 additions & 26 deletions src/cli_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@

// @ts-ignore-error
import getopts from 'getopts'
import colors from '@poppinss/colors'
import { colors } from './helpers.js'
import type { CLIArgs } from './types.js'

const ansi = colors.ansi()

/**
* Known commandline options. The user can still define additional flags and they
* will be parsed aswell, but without any normalization
Expand All @@ -32,34 +30,34 @@ const OPTIONS = {
* Help string to display when the `--help flag is used`
*/
const GET_HELP = () => `
${ansi.yellow('@japa/runner v2.3.0')}
${colors.yellow('@japa/runner v2.3.0')}
${ansi.green('--tests')} ${ansi.dim('Filter tests by the test title')}
${ansi.green('--groups')} ${ansi.dim('Filter tests by the group title')}
${ansi.green('--tags')} ${ansi.dim('Filter tests by tags')}
${ansi.green('--files')} ${ansi.dim('Filter tests by the file name')}
${ansi.green('--force-exit')} ${ansi.dim('Forcefully exit the process')}
${ansi.green('--timeout')} ${ansi.dim('Define default timeout for all tests')}
${ansi.green('--retries')} ${ansi.dim('Define default retries for all tests')}
${ansi.green('--reporters')} ${ansi.dim('Activate one or more test reporters')}
${ansi.green('--failed')} ${ansi.dim('Run tests failed during the last run')}
${ansi.green('-h, --help')} ${ansi.dim('View help')}
${colors.green('--tests')} ${colors.dim('Filter tests by the test title')}
${colors.green('--groups')} ${colors.dim('Filter tests by the group title')}
${colors.green('--tags')} ${colors.dim('Filter tests by tags')}
${colors.green('--files')} ${colors.dim('Filter tests by the file name')}
${colors.green('--force-exit')} ${colors.dim('Forcefully exit the process')}
${colors.green('--timeout')} ${colors.dim('Define default timeout for all tests')}
${colors.green('--retries')} ${colors.dim('Define default retries for all tests')}
${colors.green('--reporters')} ${colors.dim('Activate one or more test reporters')}
${colors.green('--failed')} ${colors.dim('Run tests failed during the last run')}
${colors.green('-h, --help')} ${colors.dim('View help')}
${ansi.yellow('Examples:')}
${ansi.dim('node bin/test.js --tags="@github"')}
${ansi.dim('node bin/test.js --tags="~@github"')}
${ansi.dim('node bin/test.js --tags="@github,@slow,@integration" --match-all')}
${ansi.dim('node bin/test.js --force-exit')}
${ansi.dim('node bin/test.js --files="user"')}
${ansi.dim('node bin/test.js --files="functional/user"')}
${ansi.dim('node bin/test.js --files="unit/user"')}
${colors.yellow('Examples:')}
${colors.dim('node bin/test.js --tags="@github"')}
${colors.dim('node bin/test.js --tags="~@github"')}
${colors.dim('node bin/test.js --tags="@github,@slow,@integration" --match-all')}
${colors.dim('node bin/test.js --force-exit')}
${colors.dim('node bin/test.js --files="user"')}
${colors.dim('node bin/test.js --files="functional/user"')}
${colors.dim('node bin/test.js --files="unit/user"')}
${ansi.yellow('Notes:')}
${colors.yellow('Notes:')}
- When groups and tests filters are applied together. We will first filter the
tests by group title and then apply the tests title filter.
- The timeout defined on test object takes precedence over the ${ansi.green('--timeout')} flag.
- The retries defined on test object takes precedence over the ${ansi.green('--retries')} flag.
- The ${ansi.green('--files')} flag checks for the file names ending with the filter substring.
- The timeout defined on test object takes precedence over the ${colors.green('--timeout')} flag.
- The retries defined on test object takes precedence over the ${colors.green('--retries')} flag.
- The ${colors.green('--files')} flag checks for the file names ending with the filter substring.
`

/**
Expand Down
3 changes: 2 additions & 1 deletion src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
*/

import useColors from '@poppinss/colors'
import supportsColor from 'supports-color'
import { Colors } from '@poppinss/colors/types'

export const colors: Colors = useColors.ansi()
export const colors: Colors = supportsColor.stdout ? useColors.ansi() : useColors.silent()

/**
* A collection of platform specific icons
Expand Down

0 comments on commit b7be1a5

Please sign in to comment.