Skip to content

Commit

Permalink
Update unified-engine, unified, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 19, 2023
1 parent c545bbd commit 010bdfc
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function args(cliConfig) {
let config
/** @type {chokidar.FSWatcher|undefined} */
let watcher
/** @type {boolean|string|undefined} */
/** @type {URL|boolean|string|undefined} */
let output

try {
Expand Down
9 changes: 9 additions & 0 deletions lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ export function options(flags, configuration) {
' $ ' + name + ' . -o'
].join('\n')

/** @type {string} */
let key

for (key in config) {
if (config[key] === null) {
config[key] = undefined
}
}

return {
helpMessage: help,
cwd: configuration.cwd,
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@
],
"dependencies": {
"@types/text-table": "^0.2.0",
"camelcase": "^7.0.0",
"camelcase": "^8.0.0",
"chalk": "^5.0.0",
"chokidar": "^3.0.0",
"fault": "^2.0.0",
"json5": "^2.0.0",
"minimist": "^1.0.0",
"text-table": "^0.2.0",
"unified-engine": "^10.0.0"
"unified-engine": "^11.0.0"
},
"devDependencies": {
"@types/minimist": "^1.0.0",
"@types/tape": "^5.0.0",
"@types/touch": "^3.0.0",
"bail": "^2.0.0",
"c8": "^8.0.0",
"execa": "^7.0.0",
"execa": "^8.0.0",
"prettier": "^3.0.0",
"remark": "^14.0.0",
"remark-cli": "^11.0.0",
Expand All @@ -58,8 +58,8 @@
"touch": "^3.0.0",
"type-coverage": "^2.0.0",
"typescript": "^5.0.0",
"unified": "^10.0.0",
"vfile-reporter-json": "^3.0.0",
"unified": "^11.0.0",
"vfile-reporter-json": "^4.0.0",
"xo": "^0.56.0"
},
"scripts": {
Expand Down
43 changes: 36 additions & 7 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import test from 'tape'
import strip from 'strip-ansi'
import touch from 'touch'

const cross = process.platform === 'win32' ? '×' : '✖'

const fixtures = path.join('test', 'fixtures')
const cwd = path.join(fixtures, 'example')
const bin = path.join(cwd, 'cli.js')
Expand All @@ -23,9 +21,11 @@ test('unified-args', (t) => {
t.test('should fail on missing files', (t) => {
const expected = [
'missing.txt',
' 1:1 error No such file or directory',
' error No such file or folder',
' [cause]:',
' Error: ENOENT:…',
'',
cross + ' 1 error'
'✖ 1 error'
].join('\n')

t.plan(1)
Expand All @@ -34,7 +34,7 @@ test('unified-args', (t) => {
() => t.fail(),
(/** @type {ExecaReturnValue} */ error) => {
t.deepEqual(
[error.exitCode, strip(error.stderr)],
[error.exitCode, cleanError(error.stderr)],
[1, expected],
'should fail'
)
Expand Down Expand Up @@ -597,11 +597,11 @@ test('unified-args', (t) => {
t.test('should fail when given an ignored path', (t) => {
const expected = [
'one.txt',
' 1:1 error Cannot process specified file: it’s ignored',
' error Cannot process specified file: it’s ignored',
'',
'two.txt: no issues found',
'',
cross + ' 1 error'
'✖ 1 error'
].join('\n')

t.plan(1)
Expand Down Expand Up @@ -780,3 +780,32 @@ test('unified-args', (t) => {

t.end()
})

/**
* Clean an error so that it’s easier to test.
*
* This particularly removed error cause messages, which change across Node
* versions.
* It also drops file paths, which differ across platforms.
*
* @param {string} value
* Error, report, or stack.
* @param {number | undefined} [max=Infinity]
* Lines to include.
* @returns {string}
* Clean error.
*/
function cleanError(value, max) {
return (
strip(value)
// Clean syscal errors
.replace(/( *Error: [A-Z]+:)[^\n]*/g, '$1…')

.replace(/\(.+[/\\]/g, '(')
.replace(/file:.+\//g, '')
.replace(/\d+:\d+/g, '1:1')
.split('\n')
.slice(0, max || Number.POSITIVE_INFINITY)
.join('\n')
)
}

0 comments on commit 010bdfc

Please sign in to comment.