Skip to content

Commit

Permalink
chore: upgrade to prettier v3 (#14582)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Sep 28, 2023
1 parent 3e11814 commit 7f1d897
Show file tree
Hide file tree
Showing 26 changed files with 193 additions and 141 deletions.
30 changes: 15 additions & 15 deletions docs/GlobalAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ describe.each([
});
```

#### 2. `` describe.each`table`(name, fn, timeout) ``
#### 2. ``describe.each`table`(name, fn, timeout)``

- `table`: `Tagged Template Literal`
- First row of variable name column headings separated with `|`
Expand Down Expand Up @@ -355,7 +355,7 @@ describe('my other beverage', () => {

### `describe.only.each(table)(name, fn)`

Also under the aliases: `fdescribe.each(table)(name, fn)` and `` fdescribe.each`table`(name, fn) ``
Also under the aliases: `fdescribe.each(table)(name, fn)` and ``fdescribe.each`table`(name, fn)``

Use `describe.only.each` if you want to only run specific tests suites of data driven tests.

Expand All @@ -379,7 +379,7 @@ test('will not be run', () => {
});
```

#### `` describe.only.each`table`(name, fn) ``
#### ``describe.only.each`table`(name, fn)``

```js
describe.only.each`
Expand Down Expand Up @@ -424,7 +424,7 @@ Using `describe.skip` is often a cleaner alternative to temporarily commenting o

### `describe.skip.each(table)(name, fn)`

Also under the aliases: `xdescribe.each(table)(name, fn)` and `` xdescribe.each`table`(name, fn) ``
Also under the aliases: `xdescribe.each(table)(name, fn)` and ``xdescribe.each`table`(name, fn)``

Use `describe.skip.each` if you want to stop running a suite of data driven tests.

Expand All @@ -448,7 +448,7 @@ test('will be run', () => {
});
```

#### `` describe.skip.each`table`(name, fn) ``
#### ``describe.skip.each`table`(name, fn)``

```js
describe.skip.each`
Expand Down Expand Up @@ -566,7 +566,7 @@ test.concurrent.each([
});
```

#### 2. `` test.concurrent.each`table`(name, fn, timeout) ``
#### 2. ``test.concurrent.each`table`(name, fn, timeout)``

- `table`: `Tagged Template Literal`
- First row of variable name column headings separated with `|`
Expand Down Expand Up @@ -613,7 +613,7 @@ test('will not be run', () => {
});
```

#### `` test.only.each`table`(name, fn) ``
#### ``test.only.each`table`(name, fn)``

```js
test.concurrent.only.each`
Expand Down Expand Up @@ -654,7 +654,7 @@ test('will be run', () => {
});
```

#### `` test.concurrent.skip.each`table`(name, fn) ``
#### ``test.concurrent.skip.each`table`(name, fn)``

```js
test.concurrent.skip.each`
Expand All @@ -673,7 +673,7 @@ test('will be run', () => {

### `test.each(table)(name, fn, timeout)`

Also under the alias: `it.each(table)(name, fn)` and `` it.each`table`(name, fn) ``
Also under the alias: `it.each(table)(name, fn)` and ``it.each`table`(name, fn)``

Use `test.each` if you keep duplicating the same test with different data. `test.each` allows you to write the test once and pass data in.

Expand Down Expand Up @@ -722,7 +722,7 @@ test.each([
});
```

#### 2. `` test.each`table`(name, fn, timeout) ``
#### 2. ``test.each`table`(name, fn, timeout)``

- `table`: `Tagged Template Literal`
- First row of variable name column headings separated with `|`
Expand Down Expand Up @@ -779,7 +779,7 @@ test.failing('it is equal', () => {

### `test.failing.each(name, fn, timeout)`

Also under the alias: `it.failing.each(table)(name, fn)` and `` it.failing.each`table`(name, fn) ``
Also under the alias: `it.failing.each(table)(name, fn)` and ``it.failing.each`table`(name, fn)``

:::note

Expand Down Expand Up @@ -851,7 +851,7 @@ Usually you wouldn't check code using `test.only` into source control - you woul

### `test.only.each(table)(name, fn)`

Also under the aliases: `it.only.each(table)(name, fn)`, `fit.each(table)(name, fn)`, `` it.only.each`table`(name, fn) `` and `` fit.each`table`(name, fn) ``
Also under the aliases: `it.only.each(table)(name, fn)`, `fit.each(table)(name, fn)`, ``it.only.each`table`(name, fn)`` and ``fit.each`table`(name, fn)``

Use `test.only.each` if you want to only run specific tests with different test data.

Expand All @@ -873,7 +873,7 @@ test('will not be run', () => {
});
```

#### `` test.only.each`table`(name, fn) ``
#### ``test.only.each`table`(name, fn)``

```js
test.only.each`
Expand Down Expand Up @@ -914,7 +914,7 @@ You could comment the test out, but it's often a bit nicer to use `test.skip` be

### `test.skip.each(table)(name, fn)`

Also under the aliases: `it.skip.each(table)(name, fn)`, `xit.each(table)(name, fn)`, `xtest.each(table)(name, fn)`, `` it.skip.each`table`(name, fn) ``, `` xit.each`table`(name, fn) `` and `` xtest.each`table`(name, fn) ``
Also under the aliases: `it.skip.each(table)(name, fn)`, `xit.each(table)(name, fn)`, `xtest.each(table)(name, fn)`, ``it.skip.each`table`(name, fn)``, ``xit.each`table`(name, fn)`` and ``xtest.each`table`(name, fn)``

Use `test.skip.each` if you want to stop running a collection of data driven tests.

Expand All @@ -936,7 +936,7 @@ test('will be run', () => {
});
```

#### `` test.skip.each`table`(name, fn) ``
#### ``test.skip.each`table`(name, fn)``

```js
test.skip.each`
Expand Down
2 changes: 1 addition & 1 deletion e2e/babel-plugin-jest-hoist/__tests__/typescript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import {color} from '../entry';
import type {Color} from '../types';

jest.mock('some-module', () => ({} as Partial<{}>), {virtual: true});
jest.mock('some-module', () => ({}) as Partial<{}>, {virtual: true});

jest.mock('../entry', () => {
const color: Color = 'blue';
Expand Down
24 changes: 22 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"eslint-plugin-jsdoc": "^46.0.0",
"eslint-plugin-local": "link:./.eslintplugin",
"eslint-plugin-markdown": "^3.0.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-unicorn": "^48.0.0",
"execa": "^5.0.0",
"find-process": "^1.4.1",
Expand Down Expand Up @@ -68,7 +68,7 @@
"node-notifier": "^10.0.0",
"p-limit": "^3.1.0",
"pkg-dir": "^5.0.0",
"prettier": "^2.1.1",
"prettier": "^3.0.3",
"promise": "^8.0.2",
"read-pkg": "^5.2.0",
"resolve": "^1.20.0",
Expand Down Expand Up @@ -163,6 +163,26 @@
"options": {
"parser": "mdx"
}
},
{
"files": [
"e2e/babel-plugin-jest-hoist/__tests__/integration.test.js",
"e2e/coverage-report/notRequiredInTestSuite.js",
"e2e/expect-async-matcher/matchers.js",
"e2e/failures/__tests__/*.js",
"e2e/failures/macros.js",
"e2e/global-setup/*.js",
"e2e/global-teardown/*.js",
"e2e/multi-project-babel/**/*.js",
"e2e/transform/babel-jest-async/only-file-to-transform.js",
"e2e/transform/babel-jest-manual/**/*.js",
"e2e/transform/babel-jest/**/*.js",
"e2e/transform/no-babel-jest/__tests__/failsWithSyntaxError.test.js",
"e2e/transform/transformer-config/**/*.js"
],
"options": {
"parser": "babel-flow"
}
}
]
},
Expand Down
3 changes: 2 additions & 1 deletion packages/babel-plugin-jest-hoist/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
"@babel/core": "^7.11.6",
"@babel/preset-react": "^7.12.1",
"@babel/preset-typescript": "^7.0.0",
"@prettier/sync": "^0.3.0",
"@types/babel__template": "^7.0.2",
"@types/node": "*",
"@types/prettier": "^2.1.5",
"babel-plugin-tester": "^11.0.2",
"prettier": "^2.1.1"
"prettier": "^3.0.3"
},
"publishConfig": {
"access": "public"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
*/

import * as path from 'path';
import {format as formatCode, resolveConfig} from '@prettier/sync';
import pluginTester from 'babel-plugin-tester';
import {format as formatCode, resolveConfig} from 'prettier';
import type {Options} from 'prettier';
import babelPluginJestHoist from '..';

const prettierOptions = {
...resolveConfig.sync(__filename),
const prettierOptions: Options = {
...resolveConfig(__filename),
filepath: __filename,
parser: 'babel-ts',
};

const formatResult = (code: string) => formatCode(code, prettierOptions);
Expand Down
5 changes: 4 additions & 1 deletion packages/expect/src/asymmetricMatchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ export abstract class AsymmetricMatcher<T>
{
$$typeof = Symbol.for('jest.asymmetricMatcher');

constructor(protected sample: T, protected inverse = false) {}
constructor(
protected sample: T,
protected inverse = false,
) {}

protected getMatcherContext(): MatcherContext {
return {
Expand Down
9 changes: 5 additions & 4 deletions packages/expect/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export type ExpectationResult = SyncExpectationResult | AsyncExpectationResult;

export type MatcherFunctionWithContext<
Context extends MatcherContext = MatcherContext,
Expected extends Array<any> = [] /** TODO should be: extends Array<unknown> = [] */,
Expected extends
Array<any> = [] /** TODO should be: extends Array<unknown> = [] */,
> = (
this: Context,
actual: unknown,
Expand Down Expand Up @@ -98,9 +99,9 @@ export interface BaseExpect {
}

export type Expect = {
<T = unknown>(actual: T): Matchers<void, T> &
Inverse<Matchers<void, T>> &
PromiseMatchers<T>;
<T = unknown>(
actual: T,
): Matchers<void, T> & Inverse<Matchers<void, T>> & PromiseMatchers<T>;
} & BaseExpect &
AsymmetricMatchers &
Inverse<Omit<AsymmetricMatchers, 'any' | 'anything'>>;
Expand Down
5 changes: 2 additions & 3 deletions packages/jest-core/src/TestScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,8 @@ class TestScheduler {
options: Record<string, unknown>,
) {
try {
const Reporter: ReporterConstructor = await requireOrImportModule(
reporter,
);
const Reporter: ReporterConstructor =
await requireOrImportModule(reporter);

this.addReporter(
new Reporter(this._globalConfig, options, this._context),
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-core/src/__tests__/watch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ describe('Watch mode flows', () => {
});

it.each`
ok | option
ok | option
${'✔︎'} | ${'bail'}
${'✖︎'} | ${'changedFilesWithAncestor'}
${'✔︎'} | ${'changedSince'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const getOutputStream = (resolve: (message: string) => void) =>
write(message: string) {
resolve(message);
},
} as NodeJS.WriteStream);
}) as NodeJS.WriteStream;

it('prints the jest version', async () => {
expect.assertions(1);
Expand Down
5 changes: 2 additions & 3 deletions packages/jest-core/src/runJest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ const processResults = async (
}

if (testResultsProcessor) {
const processor = await requireOrImportModule<TestResultsProcessor>(
testResultsProcessor,
);
const processor =
await requireOrImportModule<TestResultsProcessor>(testResultsProcessor);
runResults = await processor(runResults);
}
if (isJSON) {
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-core/src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,8 @@ const checkForConflicts = (
.join(' and ');
error = `
Watch plugins ${plugins} both attempted to register key ${chalk.bold.red(
`<${key}>`,
)}.
`<${key}>`,
)}.
Please change the key configuration for one of the conflicting plugins to avoid overlap.`.trim();
}

Expand Down
19 changes: 11 additions & 8 deletions packages/jest-each/src/table/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,19 @@ const formatTitle = (
rowIndex: number,
): string =>
row
.reduce<string>((formattedTitle, value) => {
const [placeholder] = getMatchingPlaceholders(formattedTitle);
const normalisedValue = normalisePlaceholderValue(value);
if (!placeholder) return formattedTitle;
.reduce<string>(
(formattedTitle, value) => {
const [placeholder] = getMatchingPlaceholders(formattedTitle);
const normalisedValue = normalisePlaceholderValue(value);
if (!placeholder) return formattedTitle;

if (placeholder === PRETTY_PLACEHOLDER)
return interpolatePrettyPlaceholder(formattedTitle, normalisedValue);
if (placeholder === PRETTY_PLACEHOLDER)
return interpolatePrettyPlaceholder(formattedTitle, normalisedValue);

return util.format(formattedTitle, normalisedValue);
}, interpolateTitleIndex(interpolateEscapedPlaceholders(title), rowIndex))
return util.format(formattedTitle, normalisedValue);
},
interpolateTitleIndex(interpolateEscapedPlaceholders(title), rowIndex),
)
.replace(new RegExp(JEST_EACH_PLACEHOLDER_ESCAPE, 'g'), PLACEHOLDER_PREFIX);

const normalisePlaceholderValue = (value: unknown) =>
Expand Down
4 changes: 3 additions & 1 deletion packages/jest-expect/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import type {
} from 'jest-snapshot';

export type JestExpect = {
<T = unknown>(actual: T): JestMatchers<void, T> &
<T = unknown>(
actual: T,
): JestMatchers<void, T> &
Inverse<JestMatchers<void, T>> &
PromiseMatchers<T>;
// Duplicated due to https://github.com/microsoft/rushstack/issues/1709
Expand Down
5 changes: 2 additions & 3 deletions packages/jest-haste-map/src/crawlers/watchman.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,8 @@ export async function watchmanCrawl(options: CrawlerOptions): Promise<{
);

if (options.computeSha1) {
const {capabilities} = await cmd<WatchmanListCapabilitiesResponse>(
'list-capabilities',
);
const {capabilities} =
await cmd<WatchmanListCapabilitiesResponse>('list-capabilities');

if (capabilities.includes('field-content.sha1hex')) {
fields.push('content.sha1hex');
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-jasmine2/src/__tests__/reporter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Jasmine2Reporter', () => {
description: 'description',
failedExpectations: [],
fullName: name,
} as any as SpecResult);
}) as any as SpecResult;
reporter.suiteStarted({description: 'parent'} as SuiteResult);
reporter.suiteStarted({description: 'child'} as SuiteResult);
reporter.specDone(makeSpec('spec 1'));
Expand Down
3 changes: 1 addition & 2 deletions packages/jest-mock/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -744,8 +744,7 @@ export class ModuleMocker {
}

return finalReturnValue;
},
metadata.length || 0);
}, metadata.length || 0);

const f = this._createMockFunction(metadata, mockConstructor) as Mock;
f._isMockFunction = true;
Expand Down
5 changes: 2 additions & 3 deletions packages/jest-transform/src/ScriptTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,8 @@ class ScriptTransformer {
throw new Error(makeInvalidTransformerError(transformPath));
}
if (isTransformerFactory(transformer)) {
transformer = await transformer.createTransformer(
transformerConfig,
);
transformer =
await transformer.createTransformer(transformerConfig);
}
if (
typeof transformer.process !== 'function' &&
Expand Down
Loading

0 comments on commit 7f1d897

Please sign in to comment.