Skip to content

Commit 4e77f64

Browse files
authored
fix(types): generate declaration files instead of importing from src (#24)
1 parent a716216 commit 4e77f64

File tree

23 files changed

+132
-35
lines changed

23 files changed

+132
-35
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ practices.</p>
2525
[![Code of Conduct](https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square)](./CODE_OF_CONDUCT.md)
2626

2727
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
28+
2829
[![All Contributors](https://img.shields.io/badge/all_contributors-5-orange.svg?style=flat-square)](#contributors-)
30+
2931
<!-- ALL-CONTRIBUTORS-BADGE:END -->
3032

3133
[![Watch on GitHub](https://img.shields.io/github/watchers/crutchcorn/cli-testing-library.svg?style=social)](https://github.com/crutchcorn/cli-testing-library/watchers)

docs/api.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ exit code it closed with.
185185
```javascript
186186
const instance = render('command')
187187
188-
await waitFor(() => expect(instance.hasExit()).toMatchObject({ exitCode: 1 }))
188+
await waitFor(() => expect(instance.hasExit()).toMatchObject({exitCode: 1}))
189189
```
190190

191191
This method returns `null` if still running, but `{exitCode: number}` if it has
@@ -206,8 +206,8 @@ They're defined as:
206206

207207
```typescript
208208
interface TestInstance {
209-
stdoutArr: Array<{contents: Buffer | string, timestamp: number}>
210-
stderrArr: Array<{contents: Buffer | string, timestamp: number}>
209+
stdoutArr: Array<{contents: Buffer | string; timestamp: number}>
210+
stderrArr: Array<{contents: Buffer | string; timestamp: number}>
211211
}
212212
```
213213

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
console.log("Log here");
2-
console.warn("Warn here");
3-
console.error("Error here");
1+
console.log('Log here')
2+
console.warn('Warn here')
3+
console.error('Error here')

src/config.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,15 @@ let config: InternalConfig = {
2727

2828
// called when getBy* queries fail. (message, container) => Error
2929
getInstanceError(message, testInstance: TestInstance | undefined) {
30-
let instanceWarning: string = "";
30+
let instanceWarning: string = ''
3131
if (testInstance) {
32-
const stdallArrStr = testInstance.getStdallStr();
32+
const stdallArrStr = testInstance.getStdallStr()
3333
instanceWarning = `\n${stdallArrStr}`
3434
} else {
35-
instanceWarning = "";
35+
instanceWarning = ''
3636
}
3737
const error = new Error(
38-
[message, instanceWarning]
39-
.filter(Boolean)
40-
.join('\n\n'),
38+
[message, instanceWarning].filter(Boolean).join('\n\n'),
4139
)
4240
error.name = 'TestingLibraryElementError'
4341
return error

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import {cleanup} from './pure'
44
// or teardown then we'll automatically run cleanup afterEach test
55
// this ensures that tests run in isolation from each other
66
// if you don't like this then set the CTL_SKIP_AUTO_CLEANUP env variable to 'true'.
7-
if (typeof process === 'undefined' || !(process.env && process.env.CTL_SKIP_AUTO_CLEANUP)) {
7+
if (
8+
typeof process === 'undefined' ||
9+
!(process.env && process.env.CTL_SKIP_AUTO_CLEANUP)
10+
) {
811
// ignore teardown() in code coverage because Jest does not support it
912
/* istanbul ignore else */
1013
if (typeof afterEach === 'function') {

src/matchers/to-be-in-the-console.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ export function toBeInTheConsole(instance) {
88
}
99

1010
const errormessage = instance
11-
? getDefaultNormalizer()(instance.stdoutArr.map(obj => obj.contents).join('\n'))
11+
? getDefaultNormalizer()(
12+
instance.stdoutArr.map(obj => obj.contents).join('\n'),
13+
)
1214
: null
1315

1416
return {

src/matchers/to-have-errormessage.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ export function toHaveErrorMessage(testInstance, checkWith) {
1111

1212
const expectsErrorMessage = checkWith !== undefined
1313

14-
const errormessage = getDefaultNormalizer()(testInstance.stderrArr.map(obj => obj.contents).join('\n'))
14+
const errormessage = getDefaultNormalizer()(
15+
testInstance.stderrArr.map(obj => obj.contents).join('\n'),
16+
)
1517

1618
return {
1719
pass: expectsErrorMessage

src/pretty-cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function prettyCLI(testInstance, maxLength) {
1515
throw new TypeError(`Expected an instance but got ${testInstance}`)
1616
}
1717

18-
const outStr = testInstance.getStdallStr();
18+
const outStr = testInstance.getStdallStr()
1919

2020
// eslint-disable-next-line no-negated-condition
2121
return maxLength !== undefined && outStr.length > maxLength

src/pure.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import childProcess from 'child_process'
2+
import {performance} from 'perf_hooks'
23
import stripFinalNewline from 'strip-final-newline'
34
import {RenderOptions, RenderResult, TestInstance} from '../types/pure'
45
import {_runObservers} from './mutation-observer'
@@ -8,7 +9,6 @@ import {bindObjectFnsToInstance, setCurrentInstance} from './helpers'
89
import {fireEvent} from './events'
910
import {getConfig} from './config'
1011
import {logCLI} from './pretty-cli'
11-
import {performance} from 'perf_hooks'
1212

1313
const mountedInstances = new Set<TestInstance>()
1414

@@ -48,8 +48,8 @@ async function render(
4848
},
4949
// An array of strings gathered from stdout when unable to do
5050
// `await stdout` because of inquirer interactive prompts
51-
stdoutArr: [] as Array<{contents: Buffer | string, timestamp: number}>,
52-
stderrArr: [] as Array<{contents: Buffer | string, timestamp: number}>,
51+
stdoutArr: [] as Array<{contents: Buffer | string; timestamp: number}>,
52+
stderrArr: [] as Array<{contents: Buffer | string; timestamp: number}>,
5353
hasExit() {
5454
return this.__exitCode === null ? null : {exitCode: this.__exitCode}
5555
},
@@ -66,7 +66,10 @@ async function render(
6666
}
6767

6868
const resStr = stripFinalNewline(result as string)
69-
execOutputAPI.stdoutArr.push({contents: resStr, timestamp: performance.now()})
69+
execOutputAPI.stdoutArr.push({
70+
contents: resStr,
71+
timestamp: performance.now(),
72+
})
7073
_runObservers()
7174
})
7275

@@ -77,7 +80,10 @@ async function render(
7780
}
7881

7982
const resStr = stripFinalNewline(result as string)
80-
execOutputAPI.stderrArr.push({contents: resStr, timestamp: performance.now()})
83+
execOutputAPI.stderrArr.push({
84+
contents: resStr,
85+
timestamp: performance.now(),
86+
})
8187
_runObservers()
8288
})
8389

@@ -104,12 +110,12 @@ async function render(
104110

105111
await execOutputAPI._isReady
106112

107-
108113
function getStdallStr(this: Omit<TestInstance, 'getStdallStr'>) {
109-
return this.stderrArr.concat(this.stdoutArr)
110-
.sort((a,b) => a.timestamp < b.timestamp ? -1 : 1)
111-
.map(obj => obj.contents)
112-
.join('\n');
114+
return this.stderrArr
115+
.concat(this.stdoutArr)
116+
.sort((a, b) => (a.timestamp < b.timestamp ? -1 : 1))
117+
.map(obj => obj.contents)
118+
.join('\n')
113119
}
114120

115121
return Object.assign(

src/suggestions.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ function canSuggest(currentMethod, requestedMethod, data) {
6161
}
6262

6363
export function getSuggestedQuery(instance, variant = 'get', method) {
64-
const textContent = normalize(instance.stdoutArr.map(obj => obj.contents).join('\n'))
64+
const textContent = normalize(
65+
instance.stdoutArr.map(obj => obj.contents).join('\n'),
66+
)
6567
if (canSuggest('Text', method, textContent)) {
6668
return makeSuggestion('Text', instance, textContent, {variant})
6769
}

0 commit comments

Comments
 (0)