Skip to content

Commit

Permalink
chore: avoid backticks without template in strings (#12328)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB authored Feb 8, 2022
1 parent dfbe71d commit 506a062
Show file tree
Hide file tree
Showing 93 changed files with 385 additions and 359 deletions.
13 changes: 12 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ module.exports = {
'sort-keys': 'off',
},
},
// snapshots in examples plus inline snapshots need to keep backtick
{
files: ['*.md', 'e2e/custom-inline-snapshot-matchers/__tests__/*'],
rules: {
quotes: [
'error',
'single',
{allowTemplateLiterals: true, avoidEscape: true},
],
},
},
{
files: ['website/**/*'],
rules: {
Expand Down Expand Up @@ -469,7 +480,7 @@ module.exports = {
quotes: [
'error',
'single',
{allowTemplateLiterals: true, avoidEscape: true},
{allowTemplateLiterals: false, avoidEscape: true},
],
radix: 'warn',
'require-jsdoc': 'off',
Expand Down
4 changes: 2 additions & 2 deletions e2e/__tests__/customReporters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe('Custom Reporters Integration', () => {

test('prints reporter errors', () => {
writeFiles(DIR, {
'__tests__/test.test.js': `test('test', () => {});`,
'__tests__/test.test.js': "test('test', () => {});",
'package.json': JSON.stringify({
jest: {
reporters: ['default', '<rootDir>/reporter.js'],
Expand All @@ -163,7 +163,7 @@ describe('Custom Reporters Integration', () => {
onNodeVersions('>=12.17.0', () => {
test('supports reporter written in ESM', () => {
writeFiles(DIR, {
'__tests__/test.test.js': `test('test', () => {});`,
'__tests__/test.test.js': "test('test', () => {});",
'package.json': JSON.stringify({
jest: {
reporters: ['default', '<rootDir>/reporter.mjs'],
Expand Down
6 changes: 3 additions & 3 deletions e2e/__tests__/executeTestsOnceInMpr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ test('Tests are executed only once even in an MPR', () => {

/* eslint-disable sort-keys */
writeFiles(DIR, {
'foo/folder/my-test-bar.js': `test('bar', () => console.log('Bar!'));`,
'foo/folder/my-test-bar.js': "test('bar', () => console.log('Bar!'));",
'foo/folder/package.json': JSON.stringify(childConfig, null, 2),

'foo/directory/my-test-baz.js': `test('baz', () => console.log('Baz!'));`,
'foo/directory/my-test-baz.js': "test('baz', () => console.log('Baz!'));",
'foo/directory/package.json': JSON.stringify(childConfig, null, 2),

'foo/whatever/my-test-qux.js': `test('qux', () => console.log('Qux!'));`,
'foo/whatever/my-test-qux.js': "test('qux', () => console.log('Qux!'));",
'foo/whatever/package.json': JSON.stringify(childConfig, null, 2),

'package.json': JSON.stringify(config, null, 2),
Expand Down
14 changes: 7 additions & 7 deletions e2e/__tests__/globalSetup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ test('globalSetup is triggered once before all test suites', () => {
const setupPath = path.join(e2eDir, 'setup.js');
const result = runWithJson(e2eDir, [
`--globalSetup=${setupPath}`,
`--testPathPattern=__tests__`,
'--testPathPattern=__tests__',
]);

expect(result.exitCode).toBe(0);
Expand All @@ -71,7 +71,7 @@ test('jest throws an error when globalSetup does not export a function', () => {
const setupPath = path.resolve(__dirname, '../global-setup/invalidSetup.js');
const {exitCode, stderr} = runJest(e2eDir, [
`--globalSetup=${setupPath}`,
`--testPathPattern=__tests__`,
'--testPathPattern=__tests__',
]);

expect(exitCode).toBe(1);
Expand Down Expand Up @@ -155,7 +155,7 @@ test('globalSetup throws with named export', () => {

const {exitCode, stderr} = runJest(e2eDir, [
`--globalSetup=${setupPath}`,
`--testPathPattern=__tests__`,
'--testPathPattern=__tests__',
]);

expect(exitCode).toBe(1);
Expand All @@ -166,13 +166,13 @@ test('globalSetup throws with named export', () => {
});

test('should not transpile the transformer', () => {
const {exitCode} = runJest('global-setup-custom-transform', [`--no-cache`]);
const {exitCode} = runJest('global-setup-custom-transform', ['--no-cache']);

expect(exitCode).toBe(0);
});

test('should transform node_modules if configured by transformIgnorePatterns', () => {
const {exitCode} = runJest('global-setup-node-modules', [`--no-cache`]);
const {exitCode} = runJest('global-setup-node-modules', ['--no-cache']);

expect(exitCode).toBe(0);
});
Expand All @@ -190,7 +190,7 @@ test('properly handle rejections', () => {
`,
});

const {exitCode, stderr} = runJest(rejectionDir, [`--no-cache`]);
const {exitCode, stderr} = runJest(rejectionDir, ['--no-cache']);

expect(exitCode).toBe(1);
expect(stderr).toContain('Error: Jest: Got error running globalSetup');
Expand All @@ -199,7 +199,7 @@ test('properly handle rejections', () => {

onNodeVersions('>=12.17.0', () => {
test('globalSetup works with ESM modules', () => {
const {exitCode} = runJest('global-setup-esm', [`--no-cache`], {
const {exitCode} = runJest('global-setup-esm', ['--no-cache'], {
nodeOptions: '--experimental-vm-modules --no-warnings',
});

Expand Down
8 changes: 4 additions & 4 deletions e2e/__tests__/globalTeardown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test('globalTeardown is triggered once after all test suites', () => {
const teardownPath = path.resolve(e2eDir, 'teardown.js');
const result = runWithJson('global-teardown', [
`--globalTeardown=${teardownPath}`,
`--testPathPattern=__tests__`,
'--testPathPattern=__tests__',
]);

expect(result.exitCode).toBe(0);
Expand All @@ -55,7 +55,7 @@ test('jest throws an error when globalTeardown does not export a function', () =
const teardownPath = path.resolve(e2eDir, 'invalidTeardown.js');
const {exitCode, stderr} = runJest(e2eDir, [
`--globalTeardown=${teardownPath}`,
`--testPathPattern=__tests__`,
'--testPathPattern=__tests__',
]);

expect(exitCode).toBe(1);
Expand Down Expand Up @@ -126,7 +126,7 @@ test('globalTeardown throws with named export', () => {

const {exitCode, stderr} = runJest(e2eDir, [
`--globalTeardown=${teardownPath}`,
`--testPathPattern=__tests__`,
'--testPathPattern=__tests__',
]);

expect(exitCode).toBe(1);
Expand All @@ -138,7 +138,7 @@ test('globalTeardown throws with named export', () => {

onNodeVersions('>=12.17.0', () => {
test('globalTeardown works with ESM modules', () => {
const {exitCode} = runJest('global-teardown-esm', [`--no-cache`], {
const {exitCode} = runJest('global-teardown-esm', ['--no-cache'], {
nodeOptions: '--experimental-vm-modules --no-warnings',
});

Expand Down
10 changes: 5 additions & 5 deletions e2e/__tests__/jest.config.js.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ afterAll(() => cleanup(DIR));

test('works with jest.config.js', () => {
writeFiles(DIR, {
'__tests__/a-banana.js': `test('banana', () => expect(1).toBe(1));`,
'jest.config.js': `module.exports = {testRegex: '.*-banana.js'};`,
'__tests__/a-banana.js': "test('banana', () => expect(1).toBe(1));",
'jest.config.js': "module.exports = {testRegex: '.*-banana.js'};",
'package.json': '{}',
});

Expand All @@ -35,7 +35,7 @@ test('traverses directory tree up until it finds jest.config', () => {
test('banana', () => expect(1).toBe(1));
test('abc', () => console.log(slash(process.cwd())));
`,
'jest.config.js': `module.exports = {testRegex: '.*-banana.js'};`,
'jest.config.js': "module.exports = {testRegex: '.*-banana.js'};",
'package.json': '{}',
'some/nested/directory/file.js': '// nothing special',
});
Expand All @@ -57,8 +57,8 @@ test('traverses directory tree up until it finds jest.config', () => {

test('invalid JS in jest.config.js', () => {
writeFiles(DIR, {
'__tests__/a-banana.js': `test('banana', () => expect(1).toBe(1));`,
'jest.config.js': `module.exports = i'll break this file yo`,
'__tests__/a-banana.js': "test('banana', () => expect(1).toBe(1));",
'jest.config.js': "module.exports = i'll break this file yo",
'package.json': '{}',
});

Expand Down
21 changes: 12 additions & 9 deletions e2e/__tests__/jest.config.ts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ afterAll(() => cleanup(DIR));

test('works with jest.config.ts', () => {
writeFiles(DIR, {
'__tests__/a-giraffe.js': `test('giraffe', () => expect(1).toBe(1));`,
'jest.config.ts': `export default {testEnvironment: 'jest-environment-node', testRegex: '.*-giraffe.js'};`,
'__tests__/a-giraffe.js': "test('giraffe', () => expect(1).toBe(1));",
'jest.config.ts':
"export default {testEnvironment: 'jest-environment-node', testRegex: '.*-giraffe.js'};",
'package.json': '{}',
});

Expand All @@ -30,8 +31,9 @@ test('works with jest.config.ts', () => {

test('works with tsconfig.json', () => {
writeFiles(DIR, {
'__tests__/a-giraffe.js': `test('giraffe', () => expect(1).toBe(1));`,
'jest.config.ts': `export default {testEnvironment: 'jest-environment-node', testRegex: '.*-giraffe.js'};`,
'__tests__/a-giraffe.js': "test('giraffe', () => expect(1).toBe(1));",
'jest.config.ts':
"export default {testEnvironment: 'jest-environment-node', testRegex: '.*-giraffe.js'};",
'package.json': '{}',
'tsconfig.json': '{ "compilerOptions": { "module": "esnext" } }',
});
Expand All @@ -50,7 +52,8 @@ test('traverses directory tree up until it finds jest.config', () => {
test('giraffe', () => expect(1).toBe(1));
test('abc', () => console.log(slash(process.cwd())));
`,
'jest.config.ts': `export default {testEnvironment: 'jest-environment-node', testRegex: '.*-giraffe.js'};`,
'jest.config.ts':
"export default {testEnvironment: 'jest-environment-node', testRegex: '.*-giraffe.js'};",
'package.json': '{}',
'some/nested/directory/file.js': '// nothing special',
});
Expand All @@ -72,8 +75,8 @@ test('traverses directory tree up until it finds jest.config', () => {

test('it does type check the config', () => {
writeFiles(DIR, {
'__tests__/a-giraffe.js': `test('giraffe', () => expect(1).toBe(1));`,
'jest.config.ts': `export default { testTimeout: "10000" }`,
'__tests__/a-giraffe.js': "test('giraffe', () => expect(1).toBe(1));",
'jest.config.ts': 'export default { testTimeout: "10000" }',
'package.json': '{}',
});

Expand All @@ -84,8 +87,8 @@ test('it does type check the config', () => {

test('invalid JS in jest.config.ts', () => {
writeFiles(DIR, {
'__tests__/a-giraffe.js': `test('giraffe', () => expect(1).toBe(1));`,
'jest.config.ts': `export default i'll break this file yo`,
'__tests__/a-giraffe.js': "test('giraffe', () => expect(1).toBe(1));",
'jest.config.ts': "export default i'll break this file yo",
'package.json': '{}',
});

Expand Down
4 changes: 2 additions & 2 deletions e2e/__tests__/jestChangedFiles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ it('does not find changes in files with no diff, for git', async () => {
test('handles a bad revision for "changedSince", for git', async () => {
writeFiles(DIR, {
'.watchmanconfig': '',
'__tests__/file1.test.js': `require('../file1'); test('file1', () => {});`,
'__tests__/file1.test.js': "require('../file1'); test('file1', () => {});",
'file1.js': 'module.exports = {}',
'package.json': '{}',
});
Expand Down Expand Up @@ -494,7 +494,7 @@ testIfHg('monitors only root paths for hg', async () => {
testIfHg('handles a bad revision for "changedSince", for hg', async () => {
writeFiles(DIR, {
'.watchmanconfig': '',
'__tests__/file1.test.js': `require('../file1'); test('file1', () => {});`,
'__tests__/file1.test.js': "require('../file1'); test('file1', () => {});",
'file1.js': 'module.exports = {}',
'package.json': '{}',
});
Expand Down
4 changes: 2 additions & 2 deletions e2e/__tests__/jestEnvironmentJsdom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ afterAll(() => cleanup(DIR));

test('check is not leaking memory', () => {
writeFiles(DIR, {
'__tests__/a.test.js': `test('a', () => console.log('a'));`,
'__tests__/b.test.js': `test('b', () => console.log('b'));`,
'__tests__/a.test.js': "test('a', () => console.log('a'));",
'__tests__/b.test.js': "test('b', () => console.log('b'));",
'package.json': JSON.stringify({jest: {testEnvironment: 'jsdom'}}),
});

Expand Down
4 changes: 2 additions & 2 deletions e2e/__tests__/jestRequireActual.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ test('understands dependencies using jest.requireActual', () => {
test('a', () => {});
`,
'__tests__/b.test.js': `test('b', () => {});`,
'a.js': `module.exports = {}`,
'__tests__/b.test.js': "test('b', () => {});",
'a.js': 'module.exports = {}',
'package.json': JSON.stringify({jest: {}}),
});

Expand Down
4 changes: 2 additions & 2 deletions e2e/__tests__/jestRequireMock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ test('understands dependencies using jest.requireMock', () => {
test('a', () => {});
`,
'__tests__/b.test.js': `test('b', () => {});`,
'a.js': `module.exports = {}`,
'__tests__/b.test.js': "test('b', () => {});",
'a.js': 'module.exports = {}',
'package.json': JSON.stringify({jest: {}}),
});

Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/logHeapUsage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ afterAll(() => cleanup(DIR));

test('logs memory usage', () => {
writeFiles(DIR, {
'__tests__/a-banana.js': `test('banana', () => expect(1).toBe(1));`,
'__tests__/a-banana.js': "test('banana', () => expect(1).toBe(1));",
'package.json': JSON.stringify({jest: {testEnvironment: 'node'}}),
});

Expand Down
18 changes: 10 additions & 8 deletions e2e/__tests__/multiProjectRunner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ afterEach(() => cleanup(DIR));
test("--listTests doesn't duplicate the test files", () => {
writeFiles(DIR, {
'.watchmanconfig': '',
'/project1.js': `module.exports = {rootDir: './', displayName: 'BACKEND'}`,
'/project2.js': `module.exports = {rootDir: './', displayName: 'BACKEND'}`,
'__tests__/inBothProjectsTest.js': `test('test', () => {});`,
'/project1.js': "module.exports = {rootDir: './', displayName: 'BACKEND'}",
'/project2.js': "module.exports = {rootDir: './', displayName: 'BACKEND'}",
'__tests__/inBothProjectsTest.js': "test('test', () => {});",
'package.json': JSON.stringify({
jest: {projects: ['<rootDir>/project1.js', '<rootDir>/project2.js']},
}),
Expand Down Expand Up @@ -139,13 +139,13 @@ test('"No tests found" message for projects', () => {
test('file1', () => {});
`,
'project1/file1.js': SAMPLE_FILE_CONTENT,
'project1/jest.config.js': `module.exports = {rootDir: './'}`,
'project1/jest.config.js': "module.exports = {rootDir: './'}",
'project2/__tests__/file1.test.js': `
const file1 = require('../file1');
test('file1', () => {});
`,
'project2/file1.js': SAMPLE_FILE_CONTENT,
'project2/jest.config.js': `module.exports = {rootDir: './'}`,
'project2/jest.config.js': "module.exports = {rootDir: './'}",
});
const {stdout: verboseOutput} = runJest(DIR, [
'--no-watchman',
Expand Down Expand Up @@ -352,9 +352,11 @@ test('resolves projects and their <rootDir> properly', () => {
setupFiles: ['<rootDir>/project1_setup.js'],
testEnvironment: 'node',
}),
'project1/__tests__/test.test.js': `test('project1', () => expect(global.project1).toBe(true))`,
'project1/__tests__/test.test.js':
"test('project1', () => expect(global.project1).toBe(true))",
'project1/project1_setup.js': 'global.project1 = true;',
'project2/__tests__/test.test.js': `test('project2', () => expect(global.project2).toBe(true))`,
'project2/__tests__/test.test.js':
"test('project2', () => expect(global.project2).toBe(true))",
'project2/project2.conf.json': JSON.stringify({
name: 'project2',
rootDir: '../', // root dir is set to the top level
Expand Down Expand Up @@ -427,7 +429,7 @@ test('resolves projects and their <rootDir> properly', () => {

({stderr} = runJest(DIR, ['--no-watchman']));
expect(stderr).toMatch(
`Can't find a root directory while resolving a config file path.`,
"Can't find a root directory while resolving a config file path.",
);
expect(stderr).toMatch(/banana/);
});
Expand Down
Loading

0 comments on commit 506a062

Please sign in to comment.