Skip to content

Commit

Permalink
chore: use consistent casing in escape characters (jestjs#14806)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Dec 29, 2023
1 parent 3054e56 commit 90ef733
Show file tree
Hide file tree
Showing 25 changed files with 54 additions and 58 deletions.
7 changes: 2 additions & 5 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ module.exports = {
'plugin:markdown/recommended',
'plugin:import/errors',
'plugin:eslint-comments/recommended',
'plugin:prettier/recommended',
'plugin:unicorn/recommended',
'plugin:promise/recommended',
'plugin:prettier/recommended',
],
globals: {
console: 'readonly',
Expand Down Expand Up @@ -424,6 +424,7 @@ module.exports = {
rules: {
'unicorn/prefer-code-point': 'off',
'unicorn/prefer-optional-catch-binding': 'off',
'unicorn/text-encoding-identifier-case': 'off',
},
},
{
Expand Down Expand Up @@ -670,7 +671,6 @@ module.exports = {

// nah
'unicorn/consistent-destructuring': 'off',
'unicorn/no-nested-ternary': 'off',
'unicorn/no-lonely-if': 'off',
'unicorn/no-null': 'off',
'unicorn/no-process-exit': 'off',
Expand All @@ -688,7 +688,6 @@ module.exports = {
'unicorn/catch-error-name': 'off',
'unicorn/consistent-function-scoping': 'off',
'unicorn/error-message': 'off',
'unicorn/escape-case': 'off',
'unicorn/no-await-expression-member': 'off',
'unicorn/no-console-spaces': 'off',
'unicorn/no-empty-file': 'off',
Expand All @@ -699,7 +698,6 @@ module.exports = {
'unicorn/no-typeof-undefined': 'off',
'unicorn/no-useless-promise-resolve-reject': 'off',
'unicorn/no-useless-undefined': 'off',
'unicorn/number-literal-case': 'off',
'unicorn/prefer-date-now': 'off',
'unicorn/prefer-logical-operator-over-ternary': 'off',
'unicorn/prefer-math-trunc': 'off',
Expand All @@ -710,7 +708,6 @@ module.exports = {
'unicorn/prefer-spread': 'off',
'unicorn/prefer-string-replace-all': 'off',
'unicorn/prevent-abbreviations': 'off',
'unicorn/text-encoding-identifier-case': 'off',

// enabling this is blocked by https://github.com/microsoft/rushstack/issues/2780
'unicorn/prefer-export-from': 'off',
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/coverageHandlebars.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ it('code coverage for Handlebars', () => {
expect(result.stdout).toMatchSnapshot();

const coverageMapFile = path.join(coverageDir, 'coverage-final.json');
const coverageMap = JSON.parse(readFileSync(coverageMapFile, 'utf-8'));
const coverageMap = JSON.parse(readFileSync(coverageMapFile, 'utf8'));

expect(
Object.keys(coverageMap).map(filename => path.basename(filename)),
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/coverageRemapping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ it('maps code coverage against original source', () => {
expect(result.exitCode).toBe(0);

const coverageMapFile = path.join(coverageDir, 'coverage-final.json');
const coverageMap = JSON.parse(readFileSync(coverageMapFile, 'utf-8'));
const coverageMap = JSON.parse(readFileSync(coverageMapFile, 'utf8'));

// reduce absolute paths embedded in the coverage map to just filenames
for (const filename of Object.keys(coverageMap)) {
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/coverageTransformInstrumented.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ it('code coverage for transform instrumented code', () => {
expect(result.exitCode).toBe(0);

const coverageMapFile = path.join(coverageDir, 'coverage-final.json');
const coverageMap = JSON.parse(readFileSync(coverageMapFile, 'utf-8'));
const coverageMap = JSON.parse(readFileSync(coverageMapFile, 'utf8'));

// reduce absolute paths embedded in the coverage map to just filenames
for (const filename of Object.keys(coverageMap)) {
Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/watchModeNoAccess.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ test('does not re-run tests when only access time is modified', async () => {
expect(numberOfTestRuns(testRun.getCurrentOutput().stderr)).toBe(2);

// Should re-run the test
fs.writeFileSync(modulePath, 'module.exports = 1;', {encoding: 'utf-8'});
fs.writeFileSync(modulePath, 'module.exports = 1;', 'utf8');
await testRun.waitUntil(({stderr}) => numberOfTestRuns(stderr) === 3);
});
2 changes: 1 addition & 1 deletion e2e/custom-reporters/reporters/TestReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class TestReporter {
*/
clearLine() {
if (process.stdout.isTTY) {
process.stderr.write('\x1b[999D\x1b[K');
process.stderr.write('\x1B[999D\x1B[K');
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/create-jest/src/runCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export async function runCreate(rootDir = process.cwd()): Promise<void> {

try {
projectPackageJson = JSON.parse(
fs.readFileSync(projectPackageJsonPath, 'utf-8'),
fs.readFileSync(projectPackageJsonPath, 'utf8'),
) as ProjectPackageJson;
} catch {
throw new MalformedPackageJsonError(projectPackageJsonPath);
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type ResolveOptions = {
optional?: boolean;
};

export const BULLET: string = chalk.bold('\u25cf ');
export const BULLET: string = chalk.bold('\u25CF ');
export const DOCUMENTATION_NOTE = ` ${chalk.bold(
'Configuration Documentation:',
)}
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-haste-map/src/crawlers/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function findNative(
'stdout is null - this should never happen. Please open up an issue at https://github.com/jestjs/jest',
);
}
child.stdout.setEncoding('utf-8');
child.stdout.setEncoding('utf8');
child.stdout.on('data', data => (stdout += data));

child.stdout.on('close', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,16 @@ exports[`on node >=15.0.0 should return the inner errors of an AggregateError 1`
AggregateError:
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:586:22)</intensity>
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:587:22)</intensity>
Errors contained in AggregateError:
Err 1
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:587:7)</intensity>
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:588:7)</intensity>
Err 2
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:588:7)</intensity>
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:589:7)</intensity>
"
`;
Expand Down Expand Up @@ -177,12 +177,12 @@ exports[`should return the error cause if there is one 1`] = `
Test exception
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:565:17)</intensity>
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:566:17)</intensity>
Cause:
Cause Error
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:568:17)</intensity>
<dim>at Object.<anonymous> (</intensity>packages/jest-message-util/src/__tests__/messages.test.ts<dim>:569:17)</intensity>
"
`;
1 change: 1 addition & 0 deletions packages/jest-message-util/src/__tests__/messages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const vendorStack =

const babelStack =
' ' +
// eslint-disable-next-line unicorn/escape-case
`
packages/react/src/forwardRef.js: Unexpected token, expected , (20:10)
\u001b[0m \u001b[90m 18 | \u001b[39m \u001b[36mfalse\u001b[39m\u001b[33m,\u001b[39m
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-message-util/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const TITLE_INDENT = ' ';
const MESSAGE_INDENT = ' ';
const STACK_INDENT = ' ';
const ANCESTRY_SEPARATOR = ' \u203A ';
const TITLE_BULLET = chalk.bold('\u25cf ');
const TITLE_BULLET = chalk.bold('\u25CF ');
const STACK_TRACE_COLOR = chalk.dim;
const STACK_PATH_REGEXP = /\s*at.*\(?(:\d*:\d*|native)\)?/;
const EXEC_ERROR_MESSAGE = 'Test suite failed to run';
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-reporters/src/DefaultReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import type {ReporterOnStartOptions} from './types';
type write = WriteStream['write'];
type FlushBufferedOutput = () => void;

const TITLE_BULLET = chalk.bold('\u25cf ');
const TITLE_BULLET = chalk.bold('\u25CF ');

export default class DefaultReporter extends BaseReporter {
private _clear: string; // ANSI clear sequence for the last printed status
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-reporters/src/wrapAnsiString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function wrapAnsiString(
return string;
}

const ANSI_REGEXP = /[\u001b\u009b]\[\d{1,2}m/gu;
const ANSI_REGEXP = /[\u001B\u009B]\[\d{1,2}m/gu;
const tokens = [];
let lastIndex = 0;
let match;
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-resolve/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import chalk = require('chalk');
import {ValidationError} from 'jest-validate';
import Resolver from './resolver';

const BULLET: string = chalk.bold('\u25cf ');
const BULLET: string = chalk.bold('\u25CF ');
const DOCUMENTATION_NOTE = ` ${chalk.bold('Configuration Documentation:')}
https://jestjs.io/docs/configuration
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('Runtime require.resolve', () => {
await fs.writeFile(
absoluteFilePath,
'module.exports = require.resolve(__filename);',
'utf-8',
'utf8',
);

const runtime = await createRuntime(__filename);
Expand All @@ -66,10 +66,10 @@ describe('Runtime require.resolve', () => {
`module.exports = require.resolve(${JSON.stringify(
target,
)}, {paths: []});`,
'utf-8',
'utf8',
);

await fs.writeFile(target, 'module.exports = {}', 'utf-8');
await fs.writeFile(target, 'module.exports = {}', 'utf8');

const runtime = await createRuntime(__filename);
const resolved = runtime.requireModule(runtime.__mockRootPath, entrypoint);
Expand Down
36 changes: 18 additions & 18 deletions packages/jest-snapshot/src/__tests__/InlineSnapshots.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test('saveInlineSnapshots() replaces empty function call with a template literal
'prettier',
);

expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
'expect(1).toMatchInlineSnapshot(`1`);\n',
);
});
Expand Down Expand Up @@ -187,7 +187,7 @@ it('foos', async () => {
null,
);

expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
`${`
it('foos', async () => {
const Foo = (props: { foo: string }) => <div>{props.foo}</div>;
Expand Down Expand Up @@ -229,7 +229,7 @@ expect(a).toMatchInlineSnapshot();
null,
);

expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
`${`
const Foo = (props: { foo: string }) => <div>{props.foo}</div>;
const a = Foo({ foo: "hello" });
Expand Down Expand Up @@ -260,7 +260,7 @@ expect(a).toMatchInlineSnapshot(\`[1, 2]\`);
'prettier',
);

expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
`const a = [1, 2];
expect(a).toMatchInlineSnapshot(\`[1, 2]\`);
expect(a).toMatchInlineSnapshot(\`[1, 2]\`);
Expand Down Expand Up @@ -292,7 +292,7 @@ test.each([['babel'], ['flow'], ['typescript']])(
jest.mocked(prettier.resolveConfig.sync).mock.results[0].value,
).toEqual({parser});

expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
'expect(1).toMatchInlineSnapshot(`1`);\n',
);
},
Expand All @@ -313,7 +313,7 @@ test('saveInlineSnapshots() replaces existing template literal with property mat
'prettier',
);

expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
'expect(1).toMatchInlineSnapshot({}, `1`);\n',
);
});
Expand All @@ -335,7 +335,7 @@ test.each(['prettier', null])(
prettierModule,
);

expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
'expect(1).toMatchInlineSnapshot({}, `1`);\n',
);
},
Expand Down Expand Up @@ -391,7 +391,7 @@ test('saveInlineSnapshots() uses escaped backticks', () => {
const frame = {column: 13, file: filename, line: 1} as Frame;
saveInlineSnapshots([{frame, snapshot: '`'}], dir, 'prettier');

expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
'expect("`").toMatchInlineSnapshot(`\\``);\n',
);
});
Expand All @@ -415,7 +415,7 @@ test('saveInlineSnapshots() works with non-literals in expect call', () => {
'prettier',
);

expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
"expect({a: 'a'}).toMatchInlineSnapshot(`{a: 'a'}`);\n",
);
});
Expand Down Expand Up @@ -444,7 +444,7 @@ test('saveInlineSnapshots() indents multi-line snapshots with spaces', () => {
'prettier',
);

expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
"it('is a test', () => {\n" +
" expect({a: 'a'}).toMatchInlineSnapshot(`\n" +
' Object {\n' +
Expand Down Expand Up @@ -487,7 +487,7 @@ test('saveInlineSnapshots() does not re-indent error snapshots', () => {
'prettier',
);

expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
"it('is an error test', () => {\n" +
' expect(() => {\n' +
" throw new Error(['a', 'b'].join('\\n'));\n" +
Expand Down Expand Up @@ -537,7 +537,7 @@ test('saveInlineSnapshots() does not re-indent already indented snapshots', () =
'prettier',
);

expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
"it('is a test', () => {\n" +
" expect({a: 'a'}).toMatchInlineSnapshot(`\n" +
' Object {\n' +
Expand Down Expand Up @@ -580,7 +580,7 @@ test('saveInlineSnapshots() indents multi-line snapshots with tabs', () => {
'prettier',
);

expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
"it('is a test', () => {\n" +
"\texpect({a: 'a'}).toMatchInlineSnapshot(`\n" +
'\t\tObject {\n' +
Expand Down Expand Up @@ -613,7 +613,7 @@ test('saveInlineSnapshots() indents snapshots after prettier reformats', () => {
'prettier',
);

expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
"it('is a test', () =>\n" +
" expect({a: 'a'}).toMatchInlineSnapshot(`\n" +
' Object {\n' +
Expand Down Expand Up @@ -645,7 +645,7 @@ test('saveInlineSnapshots() does not indent empty lines', () => {
'prettier',
);

expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
"it('is a test', () =>\n" +
' expect(`hello\n\nworld`).toMatchInlineSnapshot(`\n' +
' hello\n' +
Expand Down Expand Up @@ -680,7 +680,7 @@ test('saveInlineSnapshots() indents awaited snapshots with spaces', () => {
'prettier',
);

expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
"it('is a test', async () => {\n" +
" const a = Promise.resolve({a: 'a'});\n" +
' await expect(a).resolves.toMatchInlineSnapshot(`\n' +
Expand Down Expand Up @@ -722,7 +722,7 @@ test('saveInlineSnapshots() prioritize parser from project/editor configuration'
);

expect(prettierSpy).not.toHaveBeenCalled();
expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
'const foo = {\n' +
' "1": "Some value",\n' +
'};\n' +
Expand All @@ -747,7 +747,7 @@ test('saveInlineSnapshots() replaces string literal, not just template literal',
'prettier',
);

expect(fs.readFileSync(filename, 'utf-8')).toBe(
expect(fs.readFileSync(filename, 'utf8')).toBe(
'expect("a").toMatchInlineSnapshot(`a`);\n',
);
});
2 changes: 1 addition & 1 deletion packages/jest-transform/src/runtimeErrorsAndWarnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import chalk = require('chalk');
import slash = require('slash');

const BULLET = '\u25cf ';
const BULLET = '\u25CF ';
const DOCUMENTATION_NOTE = ` ${chalk.bold(
'Code Transformation Documentation:',
)}
Expand Down
Loading

0 comments on commit 90ef733

Please sign in to comment.