Skip to content

Commit 1caf209

Browse files
Migrate to ESM Only (#48)
* feat!: migrate to ESM-only * chore: speed up web build * chore: fix ESM * fix: mark Vitest 5 as supported * ci: apply automated fixes and generate docs * chore: fix CI * docs: remove all contributors mention Closees #42 * chore: fix tsconfig problems --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 2cf5ef1 commit 1caf209

110 files changed

Lines changed: 11184 additions & 6373 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cli-testing-library": major
3+
---
4+
5+
Upgrade runtime dependencies to their latest major versions, require Node.js 22.18 or newer, publish ESM-only output built with tsdown, and spawn commands without a shell by default.

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
**/.next
22
**/.nx/cache
33
**/.svelte-kit
4+
**/.astro
45
**/build
56
**/coverage
67
**/dist

docs/api.md

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,25 @@ Instead, the following API is what `CLI Testing Library` provides the following.
2222
function render(
2323
command: string,
2424
args: string[],
25-
options?: {
26-
/* You won't often use this, expand below for docs on options */
27-
},
28-
): RenderResult
25+
options?: {/* You won't often use this, expand below for docs on options */},
26+
): RenderResult;
2927
```
3028

3129
Run the CLI application in a newly spawned process.
3230

3331
```javascript
34-
import {render} from 'cli-testing-library'
32+
import { render } from "cli-testing-library";
3533

36-
render('node', ['./path/to/script.js'])
34+
render("node", ["./path/to/script.js"]);
3735
```
3836

3937
```javascript
40-
import {render} from 'cli-testing-library'
38+
import { render } from "cli-testing-library";
4139

42-
test('renders a message', () => {
43-
const {getByText} = render('node', ['./console-out.js'])
44-
expect(getByText('Hello, world!')).toBeTruthy()
45-
})
40+
test("renders a message", () => {
41+
const { getByText } = render("node", ["./console-out.js"]);
42+
expect(getByText("Hello, world!")).toBeTruthy();
43+
});
4644
```
4745

4846
# `render` Options
@@ -62,11 +60,11 @@ to have to specify the absolute path every time. In this case, you can specify a
6260
directory as the render `cwd`.
6361

6462
```javascript
65-
const containingPath = path.resolve(__dirname, './movables')
63+
const containingPath = path.resolve(__dirname, "./movables");
6664

67-
const {getByText} = render('node', ['mover.js'], {
65+
const { getByText } = render("node", ["mover.js"], {
6866
cwd: containingPath,
69-
})
67+
});
7068
```
7169

7270
## `spawnOpts`
@@ -79,11 +77,11 @@ underlying
7977
[`child_process.spawn` NodeJS API](https://nodejs.org/api/child_process.html#child_processspawncommand-args-options).
8078

8179
```javascript
82-
const {getByText} = render('script.ps1', {
80+
const { getByText } = render("script.ps1", {
8381
spawnOpts: {
84-
shell: 'powershell.exe',
82+
shell: "powershell.exe",
8583
},
86-
})
84+
});
8785
```
8886

8987
# `render` Result
@@ -127,7 +125,7 @@ These options are all standard for text matching. To learn more, see our
127125
## `userEvent[eventName]`
128126

129127
```javascript
130-
userEvent[eventName](...eventProps)
128+
userEvent[eventName](...eventProps);
131129
```
132130

133131
> While `userEvent` isn't usually returned on `render` in, say,
@@ -144,10 +142,10 @@ This object is the same as described with
144142
This method is a shortcut for `console.log(prettyCLI(instance)).`
145143

146144
```javascript
147-
import {render} from 'cli-testing-library'
145+
import { render } from "cli-testing-library";
148146

149-
const {debug} = render('command')
150-
debug()
147+
const { debug } = render("command");
148+
debug();
151149
// Hello, world! How are you?
152150
//
153151
// you can also pass an instance: debug(getByText('message'))
@@ -166,9 +164,9 @@ This method allows you to check if the spawned process has exit, and if so, what
166164
exit code it closed with.
167165

168166
```javascript
169-
const instance = render('command')
167+
const instance = render("command");
170168

171-
await waitFor(() => expect(instance.hasExit()).toMatchObject({exitCode: 1}))
169+
await waitFor(() => expect(instance.hasExit()).toMatchObject({ exitCode: 1 }));
172170
```
173171

174172
This method returns `null` if still running, but `{exitCode: number}` if it has
@@ -189,8 +187,8 @@ They're defined as:
189187

190188
```typescript
191189
interface TestInstance {
192-
stdoutArr: Array<{contents: Buffer | string; timestamp: number}>
193-
stderrArr: Array<{contents: Buffer | string; timestamp: number}>
190+
stdoutArr: Array<{ contents: Buffer | string; timestamp: number }>;
191+
stderrArr: Array<{ contents: Buffer | string; timestamp: number }>;
194192
}
195193
```
196194

@@ -214,15 +212,15 @@ For example, if you're using the [ava](https://github.com/avajs/ava) testing
214212
framework, then you would need to use the `test.afterEach` hook like so:
215213

216214
```javascript
217-
import {cleanup, render} from 'cli-testing-library'
218-
import test from 'ava'
215+
import { cleanup, render } from "cli-testing-library";
216+
import test from "ava";
219217

220-
test.afterEach(cleanup)
218+
test.afterEach(cleanup);
221219

222-
test('renders into document', () => {
223-
render('long-running-command')
220+
test("renders into document", () => {
221+
render("long-running-command");
224222
// ...
225-
})
223+
});
226224

227225
// ... more tests ...
228226
```

docs/configure.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ To disable a suggestion for a single query just add `{suggest:false}` as an
3232
option.
3333

3434
```js
35-
getByText('foo', {suggest: false}) // will not throw a suggestion
35+
getByText("foo", { suggest: false }); // will not throw a suggestion
3636
```
3737

3838
### `getInstanceError`

docs/debug.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ When you use any `get` calls in your test cases, the current state of the
99

1010
```javascript
1111
// Hello world
12-
getByText(container, 'Goodbye world') // will fail by throwing error
12+
getByText(container, "Goodbye world"); // will fail by throwing error
1313
```
1414

1515
The above test case will fail, however it prints the state of your DOM under
@@ -45,7 +45,7 @@ a process. This can be helpful for instance when debugging tests.
4545
It is defined as:
4646

4747
```typescript
48-
function prettyDOM(instance: TestInstance, maxLength?: number): string
48+
function prettyDOM(instance: TestInstance, maxLength?: number): string;
4949
```
5050

5151
It receives the `TestInstance` to print out, an optional extra parameter to

docs/differences.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,18 @@ Usually, in a Testing Library testbed, you'd expect a `getByText` to look
9494
something like this:
9595

9696
```javascript
97-
const {getByText} = render(/* Something */)
97+
const { getByText } = render(/* Something */);
9898

99-
expect(getByText('Hello World')).toBeInTheDocument()
99+
expect(getByText("Hello World")).toBeInTheDocument();
100100
```
101101

102102
In today's version of `CLI Testing Library`, the same would look something like
103103
this:
104104

105105
```javascript
106-
const {getByText} = render(/* Something */)
106+
const { getByText } = render(/* Something */);
107107

108-
expect(getByText('Hello World')).toBeInTheConsole()
108+
expect(getByText("Hello World")).toBeInTheConsole();
109109
```
110110

111111
# Similarities

docs/fire-event.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fireEvent(instance: TestInstance, event: EventString, eventProperties?: Object)
1616
Fire CLI events.
1717

1818
```javascript
19-
fireEvent(getByText(instance, 'Username:'), 'write', {value: 'crutchcorn'})
19+
fireEvent(getByText(instance, "Username:"), "write", { value: "crutchcorn" });
2020
```
2121

2222
## `fireEvent[eventName]`

docs/matchers.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ and you're good to go:
1414

1515
```javascript
1616
// In your own jest-setup.js (or any other name)
17-
import 'cli-testing-library/jest'
17+
import "cli-testing-library/jest";
1818

1919
// In jest.config.js add (if you haven't already)
20-
setupFilesAfterEnv: ['<rootDir>/jest-setup.js']
20+
setupFilesAfterEnv: ["<rootDir>/jest-setup.js"];
2121
```
2222

2323
### With TypeScript
@@ -41,7 +41,7 @@ haven't already:
4141
### `toBeInTheConsole`
4242

4343
```typescript
44-
toBeInTheConsole()
44+
toBeInTheConsole();
4545
```
4646

4747
This allows you to assert whether an instance is present or not. Useful when
@@ -55,7 +55,7 @@ Input your name:
5555
```
5656

5757
```javascript
58-
expect(getByText(instance, 'Input your name:')).toBeInTheConsole()
58+
expect(getByText(instance, "Input your name:")).toBeInTheConsole();
5959
```
6060

6161
<hr />
@@ -86,5 +86,5 @@ File not found in output
8686
```
8787

8888
```javascript
89-
expect(instance).toHaveErrorMessage('File not found in output')
89+
expect(instance).toHaveErrorMessage("File not found in output");
9090
```

docs/queries.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ Library's,
1616
# Example
1717

1818
```javascript
19-
import {render} from 'cli-testing-library'
19+
import { render } from "cli-testing-library";
2020

21-
test('should show login form', () => {
22-
const {getByText} = render('ftp-automation.sh')
23-
const input = getByText('Username')
21+
test("should show login form", () => {
22+
const { getByText } = render("ftp-automation.sh");
23+
const input = getByText("Username");
2424
// Events and assertions...
25-
})
25+
});
2626
```
2727

2828
# Types of Queries
@@ -68,33 +68,33 @@ Hello World
6868

6969
```javascript
7070
// Matching a string:
71-
getByText('Hello World') // full string match
72-
getByText('llo Worl', {exact: false}) // substring match
73-
getByText('hello world', {exact: false}) // ignore case
71+
getByText("Hello World"); // full string match
72+
getByText("llo Worl", { exact: false }); // substring match
73+
getByText("hello world", { exact: false }); // ignore case
7474

7575
// Matching a regex:
76-
getByText(/World/) // substring match
77-
getByText(/world/i) // substring match, ignore case
78-
getByText(/^hello world$/i) // full string match, ignore case
79-
getByText(/Hello W?oRlD/i) // substring match, ignore case, searches for "hello world" or "hello orld"
76+
getByText(/World/); // substring match
77+
getByText(/world/i); // substring match, ignore case
78+
getByText(/^hello world$/i); // full string match, ignore case
79+
getByText(/Hello W?oRlD/i); // substring match, ignore case, searches for "hello world" or "hello orld"
8080

8181
// Matching with a custom function:
82-
getByText((content, instance) => content.startsWith('Hello'))
82+
getByText((content, instance) => content.startsWith("Hello"));
8383
```
8484

8585
**_Will not_ find the instance:**
8686

8787
```javascript
8888
// full string does not match
89-
getByText('Goodbye World')
89+
getByText("Goodbye World");
9090

9191
// case-sensitive regex with different case
92-
getByText(/hello world/)
92+
getByText(/hello world/);
9393

9494
// function looking contents that don't exist:
9595
getByText((content, instance) => {
96-
return instance.stdoutStr.includes('Goodbye World')
97-
})
96+
return instance.stdoutStr.includes("Goodbye World");
97+
});
9898
```
9999

100100
## Precision
@@ -143,19 +143,19 @@ behaviour:
143143
To perform a match against text without trimming:
144144

145145
```javascript
146-
getByText('text', {
147-
normalizer: getDefaultNormalizer({trim: false}),
148-
})
146+
getByText("text", {
147+
normalizer: getDefaultNormalizer({ trim: false }),
148+
});
149149
```
150150

151151
To override normalization to remove some Unicode characters whilst keeping some
152152
(but not all) of the built-in normalization behavior:
153153

154154
```javascript
155-
getByText('text', {
156-
normalizer: str =>
157-
getDefaultNormalizer({trim: false})(str).replace(/[\u200E-\u200F]*/g, ''),
158-
})
155+
getByText("text", {
156+
normalizer: (str) =>
157+
getDefaultNormalizer({ trim: false })(str).replace(/[\u200E-\u200F]*/g, ""),
158+
});
159159
```
160160

161161
# ByText
@@ -183,10 +183,10 @@ Input your name:
183183
```
184184

185185
```jsx
186-
import {render} from 'cli-testing-library'
186+
import { render } from "cli-testing-library";
187187

188-
const {getByText} = render('command')
189-
const instance = getByText(/input your name/i)
188+
const { getByText } = render("command");
189+
const instance = getByText(/input your name/i);
190190
```
191191

192192
## Options
@@ -218,10 +218,10 @@ Could not find file
218218
```
219219

220220
```jsx
221-
import {render} from 'cli-testing-library'
221+
import { render } from "cli-testing-library";
222222

223-
const {getByError} = render('command')
224-
const instance = getByError(/not find file/)
223+
const { getByError } = render("command");
224+
const instance = getByError(/not find file/);
225225
```
226226

227227
## Options

0 commit comments

Comments
 (0)