Skip to content

Commit

Permalink
doctor-general-jest seems to be working again
Browse files Browse the repository at this point in the history
  • Loading branch information
brekk committed Feb 2, 2024
1 parent a7cdd6c commit c7db8a4
Show file tree
Hide file tree
Showing 19 changed files with 137 additions and 102 deletions.
28 changes: 14 additions & 14 deletions packages/climate/autotests/builder.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ test('configurate', done => {
'strip-aliased': true,
},
}

const HELP_CONFIG = {
help: 'This text!',
// optional
Expand All @@ -26,12 +25,10 @@ test('configurate', done => {
happyHour: 'Does happy hour apply here?',
multiplier: 'How many units should we apply?',
}

const CONFIG_DEFAULTS = {
color: true,
happyHour: false,
}

const parseArgs = args =>
configurate(
YARGS_CONFIG,
Expand All @@ -42,25 +39,28 @@ test('configurate', done => {
// process.argv.slice(2)
args
)

// renders in the failure channel
fork(x => {
expect(stripAnsi(x).split('\n')).toEqual([
' dumbwaiter ',
expect(
stripAnsi(x)
.split('\n')
.map(z => z.trim())
).toEqual([
'dumbwaiter',
'',
'order food!',
'',
' -m / --meal',
' Pass the name of the meal you want',
'-m / --meal',
'Pass the name of the meal you want',
'',
' -h / --happyHour',
' Does happy hour apply here?',
'-h / --happyHour',
'Does happy hour apply here?',
'',
' -x / --multiplier',
' How many units should we apply?',
'-x / --multiplier',
'How many units should we apply?',
'',
' -h / --help',
' This text!',
'-h / --help',
'This text!',
])
done()
})(done)(parseArgs(['--help']))
Expand Down
20 changes: 10 additions & 10 deletions packages/climate/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,22 @@ export const showHelpWhen = curry(function _showHelpWhen(check, parsed) {
*
* // renders in the failure channel
* fork(x => {
* expect(stripAnsi(x).split('\n')).toEqual([
* " dumbwaiter ",
* expect(stripAnsi(x).split('\n').map(z => z.trim())).toEqual([
* "dumbwaiter",
* "",
* "order food!",
* "",
* " -m / --meal",
* " Pass the name of the meal you want",
* "-m / --meal",
* "Pass the name of the meal you want",
* "",
* " -h / --happyHour",
* " Does happy hour apply here?",
* "-h / --happyHour",
* "Does happy hour apply here?",
* "",
* " -x / --multiplier",
* " How many units should we apply?",
* "-x / --multiplier",
* "How many units should we apply?",
* "",
* " -h / --help",
* " This text!",
* "-h / --help",
* "This text!",
* ])
* done()
* })(done)(
Expand Down
5 changes: 1 addition & 4 deletions packages/doctor-general-jest/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import MAIN from './index'
import {
validatePlugin as validate,
checkPlugin as interrogate,
} from 'doctor-general'
import { validate, interrogate } from 'doctor-general'

test('doctor-general-jest is statically valid', () => {
expect(validate(MAIN)).toBeTruthy()
Expand Down
22 changes: 10 additions & 12 deletions packages/doctor-general-jest/renderer-jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ const handleSpecialCases = ifElse(
const grabCommentData = applySpec({
title: fromStructureOr('Unknown', 'name'),
example: fromStructureOr('', 'example'),
future: fromStructureOr('', 'future'),
future: fromStructureOr(false, 'future'),
})

const getCurried = fromStructureOr([], 'curried')
const MAGIC_IMPORT_KEY = 'drgen-import-above'
const hasMagicImport = includes(MAGIC_IMPORT_KEY)
const renderTest = ({ title, example, future: asyncCallback }) => {

const renderTest = ({ title, example, future }) => {
if (!matchesTestable(example)) return ''
const exlines = example.filter(l => !l.startsWith('```'))
const hasImports = any(hasMagicImport, exlines)
Expand All @@ -47,7 +48,7 @@ const renderTest = ({ title, example, future: asyncCallback }) => {
? [exlines.slice(0, importIndex), exlines.slice(importIndex + 1)]
: [[], exlines]
return `${imps.length ? imps.join('\n') + '\n' : ''}test('${title}', (${
asyncCallback ? 'done' : ''
future ? 'done' : ''
}) => {
${content.join('\n ')}
})
Expand All @@ -66,22 +67,19 @@ const handleCurriedExample = pipe(
title,
summary,
example,
// example: example.split('\n'),
future,
})
})(curried)
},
log.renderer('out?'),
filter(isNotEmpty),
join('\n')
)

export const commentToJestTest = pipe(
log.renderer('comment to jest'),
handleSpecialCases(
ifElse(
pipe(getCurried, isNotEmpty),
handleCurriedExample,
pipe(grabCommentData, renderTest)
)
export const commentToJestTest = handleSpecialCases(
ifElse(
pipe(getCurried, isNotEmpty),
handleCurriedExample,
pipe(grabCommentData, renderTest)
)
)
70 changes: 38 additions & 32 deletions packages/doctor-general/__snapshots__/comment.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -65,46 +65,52 @@ exports[`processCurriedComment 1`] = `
"structure": {
"curried": [
{
"lines": "\`\`\`js
import { execWithConfig } from 'kiddo'
import { fork } from 'fluture'
fork(console.warn)(console.log)(
execWithConfig(
function customCancellationFunction() {},
'echo',
{ cleanup: true },
['ahoy']
)
)
\`\`\`",
"lines": [
"\`\`\`js",
" import { execWithConfig } from 'kiddo'",
" import { fork } from 'fluture'",
" fork(console.warn)(console.log)(",
" execWithConfig(",
" function customCancellationFunction() {},",
" 'echo',",
" { cleanup: true },",
" ['ahoy']",
" )",
" )",
"\`\`\`",
],
"name": "execWithConfig",
"summary": "Passes all possible configuration values plus a cancellation function.",
},
{
"lines": "\`\`\`js
import { execWithCancel } from 'kiddo'
import { fork } from 'fluture'
fork(console.warn)(console.log)(
execWithCancel(
function customCancellationFunction() {},
'echo',
['ahoy']
)
)
\`\`\`",
"lines": [
"\`\`\`js",
" import { execWithCancel } from 'kiddo'",
" import { fork } from 'fluture'",
" fork(console.warn)(console.log)(",
" execWithCancel(",
" function customCancellationFunction() {},",
" 'echo',",
" ['ahoy']",
" )",
" )",
"\`\`\`",
],
"name": "execWithCancel",
"summary": "Eschews any configuration and instead only expects a cancellation function, command and arguments.",
},
{
"lines": "\`\`\`js test=true
import { fork } from 'fluture'
// drgen-import-above
const blah = Math.round(Math.random() * 100000)
fork(done)(z => {
expect(z.stdout).toEqual('' + blah)
done()
})(exec('echo', [blah]))
\`\`\`",
"lines": [
"\`\`\`js test=true",
" import { fork } from 'fluture'",
" // drgen-import-above",
" const blah = Math.round(Math.random() * 100000)",
" fork(done)(z => {",
" expect(z.stdout).toEqual('' + blah)",
" done()",
" })(exec('echo', [blah]))",
"\`\`\`",
],
"name": "exec",
"summary": "Eschews any configuration or cancellation function. Needs only command and arguments.",
},
Expand Down
24 changes: 22 additions & 2 deletions packages/doctor-general/__snapshots__/index.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,37 @@ exports[`default export 1`] = `
"MAGIC_COMMENT_END": "*/",
"MAGIC_COMMENT_START": "/**",
"MAGIC_IMPORT_KEY": "drgen-import-above",
"OPTIONAL_KEYS": [
"postProcess",
],
"TESTABLE_EXAMPLE": "test=true",
"VALID_KEYS": [
"output",
"group",
"process",
"renderer",
"postRender",
"postProcess",
],
"WHITESPACE_PRESERVING_TAGS": [
"example",
"curried",
],
"addLineNumbers": [Function],
"arity": [Function],
"arityOf": [Function],
"capitalToKebab": [Function],
"checkInterpreter": [Function],
"cleanupKeywords": [Function],
"drgen": [Function],
"findJSDocKeywords": [Function],
"formatComment": [Function],
"getExample": [Function],
"getImportsForTests": [Function],
"getPageSummary": [Function],
"getPartialForProcessing": [Function],
"groupContiguousBlocks": [Function],
"hasExample": [Function],
"interrogate": [Function],
"isAsterisky": [Function],
"isJSDocComment": [Function],
"iterateOverWorkspacesAndReadFiles": [Function],
Expand All @@ -44,10 +58,13 @@ exports[`default export 1`] = `
"verbose": [Function],
},
"matchLinks": [Function],
"monorepoPreRunner": [Function],
"monorepoRunner": [Function],
"nixKeyword": [Function],
"objectifyAllComments": [Function],
"objectifyComments": [Function],
"optional": [Function],
"optionalWithContext": [Function],
"parse": [Function],
"parseFile": [Function],
"processComments": [Function],
Expand All @@ -56,6 +73,8 @@ exports[`default export 1`] = `
"readPackageJsonWorkspaces": [Function],
"renderComments": [Function],
"renderFileWith": [Function],
"required": [Function],
"requiredWithContext": [Function],
"safeTrim": [Function],
"segmentBlock": [Function],
"stripEmptyCommentLines": [Function],
Expand All @@ -66,7 +85,8 @@ exports[`default export 1`] = `
"trimComment": [Function],
"trimSummary": [Function],
"uncommentBlock": [Function],
"validateInterpreter": [Function],
"validate": [Function],
"whereWithContext": [Function],
"wipeComment": [Function],
"writeArtifact": [Function],
"writeCommentsToFiles": [Function],
Expand Down
10 changes: 10 additions & 0 deletions packages/doctor-general/autotests/interpreter.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This test automatically generated by doctor-general.
// Sourced from 'interpreter.js', edits to this file may be erased.
import { arity } from '../interpreter'

test('arity', () => {
expect(arity((a, b, c) => {})).toEqual(3)
expect(arity(function tertiary(a, b, c) {})).toEqual(3)
expect(arity(a => b => c => c)).toEqual(1)
expect(arity('poo')).toEqual(-1)
})
11 changes: 11 additions & 0 deletions packages/doctor-general/autotests/text.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// This test automatically generated by doctor-general.
// Sourced from 'text.js', edits to this file may be erased.
import { trimComment } from '../text'

test('trimComment', () => {
expect(trimComment(' * zipzop')).toEqual('zipzop')
expect(trimComment(' * squiggle ')).toEqual('squiggle')
const input = ' ~~kljlkjlk2j32lkj3 ' + Math.round(Math.random() * 1000)
expect(trimComment(input)).toEqual(input)
expect(trimComment(29292)).toEqual(29292)
})
4 changes: 2 additions & 2 deletions packages/doctor-general/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ export function processCurriedComment(comment = {}) {
ireduce(function structureCurried(agg, x, i) {
if (i === 0) {
const first = processCurriedItemSummary(head(curried))
first.lines = trimStart(x.join('\n'))
first.lines = trimStart(x.join('\n')).split('\n')
return agg.concat(first)
}
const lead = head(x)
const lines = slice(2, Infinity, x)
const o = processCurriedItemSummary(lead)
o.lines = trimStart(lines.join('\n'))
o.lines = trimStart(lines.join('\n')).split('\n')
return agg.concat(o)
}, []),
defaultTo([]),
Expand Down
2 changes: 1 addition & 1 deletion packages/doctor-general/comment.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ test('objectifyComments', () => {
links: [],
start: 28,
structure: {
name: ['coolpage'],
name: 'coolpage',
description: '',
page: ['coolpage'],
},
Expand Down
1 change: 1 addition & 0 deletions packages/doctor-general/doctor-general.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from './parse'
export * from './reader'
export * from './text'
export * from './writer'
export * from './interpreter'
7 changes: 1 addition & 6 deletions packages/doctor-general/drgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ import { renderComments, processComments } from './comment'
import { monorepoRunner } from './reader'
import { writeArtifact } from './writer'
import { validate, interrogate } from './interpreter'
export {
validate as validateInterpreter,
interrogate as checkInterpreter,
} from './interpreter'

const handleInvalidInterpreter = pipe(
interrogate,
Expand Down Expand Up @@ -118,8 +114,7 @@ export const drgen = curry(function _drgen(cancel, config) {
log.core('showMatchesOnly', showMatchesOnly)
log.core('interpreter!', interpreter)
if (!validate(interpreter)) {
pipe(handleInvalidInterpreter, rejectF)(interpreter)
return cancel
return pipe(handleInvalidInterpreter, rejectF)(interpreter)
}
const partial = getPartialForProcessing(config)
const rawInput = monorepoMode
Expand Down
Loading

0 comments on commit c7db8a4

Please sign in to comment.