Skip to content

Commit

Permalink
Merge branch 'jestjs:main' into malaviya-parth
Browse files Browse the repository at this point in the history
  • Loading branch information
malaviya-parth committed Sep 5, 2023
2 parents f8dbe54 + 97c41f3 commit 70cc622
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,8 @@

### Fixes

- `[jest-snapshot]` Allow for strings as well as template literals in inline snapshots ([#14465](https://github.com/jestjs/jest/pull/14465))

### Performance

- `[@jest/create-cache-key-function]` Cache access of `NODE_ENV` and `BABEL_ENV` ([#14455](https://github.com/jestjs/jest/pull/14455))
Expand Down
12 changes: 5 additions & 7 deletions packages/jest-core/src/lib/activeFiltersMessage.ts
Expand Up @@ -7,11 +7,9 @@

import chalk = require('chalk');
import type {Config} from '@jest/types';
import {isNonNullable} from 'jest-util';

const activeFilters = (
globalConfig: Config.GlobalConfig,
delimiter = '\n',
): string => {
const activeFilters = (globalConfig: Config.GlobalConfig): string => {
const {testNamePattern, testPathPattern} = globalConfig;
if (testNamePattern || testPathPattern) {
const filters = [
Expand All @@ -22,12 +20,12 @@ const activeFilters = (
? chalk.dim('test name ') + chalk.yellow(`/${testNamePattern}/`)
: null,
]
.filter(f => f)
.filter(isNonNullable)
.join(', ');

const messages = [`\n${chalk.bold('Active Filters: ')}${filters}`];
const messages = `\n${chalk.bold('Active Filters: ')}${filters}`;

return messages.filter(message => !!message).join(delimiter);
return messages;
}

return '';
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-snapshot/src/InlineSnapshots.ts
Expand Up @@ -274,7 +274,7 @@ const traverseAst = (
snapshotMatcherNames.push(callee.property.name);

const snapshotIndex = args.findIndex(
({type}) => type === 'TemplateLiteral',
({type}) => type === 'TemplateLiteral' || type === 'StringLiteral',
);

const {snapshot} = inlineSnapshot;
Expand Down
20 changes: 20 additions & 0 deletions packages/jest-snapshot/src/__tests__/InlineSnapshots.test.ts
Expand Up @@ -738,3 +738,23 @@ test('saveInlineSnapshots() prioritize parser from project/editor configuration'
'});\n',
);
});

test('saveInlineSnapshots() replaces string literal, not just template literal', () => {
const filename = path.join(dir, 'my.test.js');
fs.writeFileSync(filename, 'expect("a").toMatchInlineSnapshot("b");\n');

saveInlineSnapshots(
[
{
frame: {column: 13, file: filename, line: 1} as Frame,
snapshot: 'a',
},
],
dir,
'prettier',
);

expect(fs.readFileSync(filename, 'utf-8')).toBe(
'expect("a").toMatchInlineSnapshot(`a`);\n',
);
});
2 changes: 1 addition & 1 deletion website/blog/2018-06-27-supporting-jest-open-source.md
Expand Up @@ -45,7 +45,7 @@ There are two levels of support for the collective: Backer and Sponsor.

#### Backers

Backers of the collective are individuals contributing at least \$2/month. We'll include a list of backers on the Jest homepage, README on github/yarn/npm, and Contributors page.
Backers of the collective are individuals contributing at least $2/month. We'll include a list of backers on the Jest homepage, README on github/yarn/npm, and Contributors page.

#### Sponsors

Expand Down

0 comments on commit 70cc622

Please sign in to comment.