Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make prettier optional for inline snapshots #7792

Merged
merged 110 commits into from
Nov 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
6ba49b8
vscode auto-formatting. will revert eventually
mmkal Feb 3, 2019
ca8cc43
use string replacement rather than prettier to insert snapshots
mmkal Feb 3, 2019
15701bf
make formatting go back to how it was?
mmkal Feb 3, 2019
2658e2c
add end of file newline
mmkal Feb 3, 2019
9aeac1a
fallback to @babel/parser when prettier isn't present
mmkal Feb 3, 2019
e9a2b07
use spyOn instead of $FlowFixMe mock
mmkal Feb 3, 2019
9594ea2
update changelog
mmkal Feb 3, 2019
3bc79e7
remove trailing whitespace
mmkal Feb 3, 2019
1555d65
make sure snapshot creation works with property matchers and without …
mmkal Feb 3, 2019
cc921cc
lint
mmkal Feb 4, 2019
0c2547e
use prettier --write
mmkal Feb 4, 2019
69016b1
add @babel/parser as snapshot dependency
mmkal Feb 4, 2019
716a620
prettier didn't take last time for some reason
mmkal Feb 4, 2019
dbb3bcf
shorten comment
mmkal Feb 4, 2019
93bb88b
use the same plugins as prettier
mmkal Feb 5, 2019
59c0cb1
Merge branch 'uglier-inline-snapshots' of https://github.com/mmkal/je…
mmkal Feb 5, 2019
ac57288
prettier fixes
mmkal Feb 5, 2019
bee86ee
Merge branch 'master' into uglier-inline-snapshots
mmkal Feb 7, 2019
188d731
use loadPartialConfig from @babel/core rather than hard-coded list
mmkal Feb 12, 2019
6ecb0a4
add @babel/core dependency
mmkal Feb 12, 2019
2ed041e
Merge branch 'master' into uglier-inline-snapshots
mmkal Mar 4, 2019
2f3f2e1
fix merge errors
mmkal Mar 4, 2019
8c820d6
case test fake frames to Frame type
mmkal Mar 4, 2019
5ef7328
make vscode stop messing up formatting
mmkal Mar 4, 2019
741ca7f
use babel generate instead of hacky comma hacks
mmkal Mar 4, 2019
4f5ea4b
use imports and flatten test.each
mmkal Mar 4, 2019
4a4d86c
prettier fix #123532
mmkal Mar 4, 2019
a4d30a7
move changelog entry
mmkal Mar 4, 2019
f77b104
lint fixes
mmkal Mar 4, 2019
e94e95d
Merge branch 'master' into uglier-inline-snapshots
mmkal Mar 4, 2019
f5dd3d3
Merge branch 'master' into uglier-inline-snapshots
mmkal Mar 11, 2019
a102014
lint
mmkal Mar 11, 2019
9215a44
prettier changelog
mmkal Mar 11, 2019
f9bbf05
Merge branch 'master' into uglier-inline-snapshots
mmkal Mar 12, 2019
c504dee
Merge branch 'master' into uglier-inline-snapshots
mmkal Mar 21, 2019
97e609e
Merge branch 'master' into uglier-inline-snapshots
mmkal Apr 11, 2019
3e92e6c
fix conflicts
mmkal Apr 11, 2019
5f26766
add todo
mmkal Apr 11, 2019
eea3199
placeholder prettier formatting block
mmkal Apr 11, 2019
442f1cd
reign in @babel/generate's creative license a bit
mmkal Apr 11, 2019
121ddaf
run prettier twice ¯\_(ツ)_/¯
mmkal Apr 11, 2019
9a46420
trim babel's creativity again
mmkal Apr 11, 2019
ae376f6
clean up
mmkal Apr 11, 2019
38c3c32
prettier
mmkal Apr 11, 2019
b92f988
use Function to avoid fixing types all over the place
mmkal Apr 11, 2019
a8ce8c1
oops
mmkal Apr 11, 2019
2d7d3b0
Merge branch 'master' into uglier-inline-snapshots
mmkal May 15, 2019
173835e
Merge branch 'master' into uglier-inline-snapshots
mmkal Jun 23, 2019
6fae9d1
prettier
mmkal Jun 23, 2019
87d79d2
fix: remove callee property name check
mmkal Jun 23, 2019
c787b8d
prettier
mmkal Jun 23, 2019
81d63aa
alphabetize imports
mmkal Jun 25, 2019
5205259
move changelog entry to master
mmkal Jun 25, 2019
d97f6cf
check plugin is missing before adding
mmkal Jun 29, 2019
127d492
prettier
mmkal Jun 29, 2019
2ef0b1b
prettier
mmkal Jun 29, 2019
e0d50a5
prettier!
mmkal Jun 29, 2019
4c39c17
Merge remote-tracking branch 'upstream/master' into uglier-inline-sna…
mmkal Oct 19, 2019
11b2309
run yarn install to update lockfile
mmkal Oct 19, 2019
49ae9ea
prettier
mmkal Oct 19, 2019
fa29eab
null check
mmkal Oct 19, 2019
8262b0d
Merge branch 'master' into uglier-inline-snapshots
SimenB Nov 9, 2019
b4d7dd1
fix: lint issues
mmkal Nov 9, 2019
22c1e4e
make @babel/* packages peerDependencies
mmkal Nov 9, 2019
12393d7
oh dear more lint
mmkal Nov 9, 2019
6d4815f
ah needed to update prettier locally
mmkal Nov 9, 2019
b2dfa56
I forgot lockfiles are kinda trustworthy now
mmkal Nov 9, 2019
2bc8090
move generator, parser and traverse back to dependencies
mmkal Nov 9, 2019
1b10dc8
Merge remote-tracking branch 'upstream/master' into uglier-inline-sna…
jeysal Apr 10, 2020
5fe9929
require.resolve Babel syntax plugin
jeysal Apr 10, 2020
449999d
correct changelog position
jeysal Apr 10, 2020
5ae7f0f
extract runPrettier fn
jeysal Apr 10, 2020
8ebb456
Babel parse correctly
jeysal Apr 10, 2020
0d2ea99
dedupe babel deps
SimenB Apr 11, 2020
355bde6
Update packages/jest-snapshot/src/inline_snapshots.ts
jeysal Apr 12, 2020
26acdd0
plugin-syntax-typescript dep
jeysal Apr 12, 2020
6f48559
preset current node syntax and dep cleanup
jeysal Apr 12, 2020
784b3d7
babel core peer dep
jeysal Apr 12, 2020
81f12a4
lint
jeysal Apr 12, 2020
dae5678
Merge branch 'master' into uglier-inline-snapshots
SimenB Apr 12, 2020
27cf6e0
Merge remote-tracking branch 'upstream/master' into uglier-inline-sna…
jeysal Apr 26, 2020
3f89b25
basic jest-runtime require.resolve test
jeysal Apr 27, 2020
eb5b9d3
implement require.resolve option outsideJestVm for internal modules only
jeysal Apr 27, 2020
e141ace
review improvements
jeysal Apr 28, 2020
faed042
lint
jeysal Apr 28, 2020
49bed60
Merge branch 'runtime-require-resolve-outside' into uglier-inline-sna…
jeysal Apr 28, 2020
fc086cc
WIP require prettier/Babel from outsideJestVm
jeysal Apr 28, 2020
a2a05bd
use Symbol key for resolve option
jeysal Apr 28, 2020
a6d6d36
Merge branch 'runtime-require-resolve-outside' into uglier-inline-sna…
jeysal Apr 28, 2020
7efccac
Update CHANGELOG.md
jeysal Apr 28, 2020
13c960e
Merge branch 'master' into uglier-inline-snapshots
jeysal Nov 8, 2020
06a7fb0
changelog merge
jeysal Nov 8, 2020
478d8f6
merge fixup
jeysal Nov 8, 2020
b3e2f73
yarn.lock merge
jeysal Nov 8, 2020
f375ece
merge amends
jeysal Nov 8, 2020
a641fdd
merge amends
jeysal Nov 8, 2020
81bc81e
semantic merge for test
jeysal Nov 10, 2020
be68e58
Merge branch 'master' into uglier-inline-snapshots
jeysal Nov 10, 2020
36efffa
lint
jeysal Nov 11, 2020
c53a579
Merge branch 'master' into uglier-inline-snapshots
jeysal Nov 14, 2020
f261822
use babel stuff
jeysal Nov 14, 2020
9651814
Merge branch 'master' into uglier-inline-snapshots
jeysal Nov 14, 2020
857d5eb
ts-expect-error now needed because we no longer define the requireOut…
jeysal Nov 14, 2020
7f97e87
prettier 2 devdep
jeysal Nov 14, 2020
d72b98f
types
jeysal Nov 14, 2020
8364ca1
babel-preset-current-node-syntax v1
jeysal Nov 14, 2020
5536359
jest-circus config is passed already
jeysal Nov 14, 2020
c4156b0
update snapshot formatting
jeysal Nov 14, 2020
b6327e4
use upstream types
SimenB Nov 15, 2020
69f8f0d
remove obsolete circus deps
jeysal Nov 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- `[jest-config]` [**BREAKING**] Default to Node testing environment instead of browser (JSDOM) ([#9874](https://github.com/facebook/jest/pull/9874))
- `[jest-runner]` [**BREAKING**] set exit code to 1 if test logs after teardown ([#10728](https://github.com/facebook/jest/pull/10728))
- `[jest-snapshot]`: [**BREAKING**] Make prettier optional for inline snapshots - fall back to string replacement ([#7792](https://github.com/facebook/jest/pull/7792))

### Fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ _getJestObj().mock("./App", () => () =>
/*#__PURE__*/ _jsxDEV(
"div",
{
children: "Hello world"
children: "Hello world",
},
void 0,
false,
{
fileName: _jsxFileName,
lineNumber: 1,
columnNumber: 32
columnNumber: 32,
},
this
)
Expand Down
3 changes: 0 additions & 3 deletions packages/jest-circus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
"./runner": "./runner.js"
},
"dependencies": {
"@babel/traverse": "^7.1.0",
"@jest/environment": "^26.6.2",
"@jest/test-result": "^26.6.2",
"@jest/types": "^26.6.2",
"@types/babel__traverse": "^7.0.4",
"@types/node": "*",
"chalk": "^4.0.0",
"co": "^4.6.0",
Expand All @@ -41,7 +39,6 @@
"@babel/core": "^7.1.0",
"@babel/register": "^7.0.0",
"@jest/test-utils": "^26.6.2",
"@types/babel__traverse": "^7.0.4",
"@types/co": "^4.6.0",
"@types/dedent": "^0.7.0",
"@types/graceful-fs": "^4.1.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,9 @@ const jestAdapter = async (
FRAMEWORK_INITIALIZER,
);

const getPrettier = () =>
config.prettierPath ? require(config.prettierPath) : null;
const getBabelTraverse = () => require('@babel/traverse').default;

const {globals, snapshotState} = await initialize({
config,
environment,
getBabelTraverse,
getPrettier,
globalConfig,
localRequire: runtime.requireModule.bind(runtime),
parentProcess: process,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/

import type BabelTraverse from '@babel/traverse';
import throat from 'throat';
import type {JestEnvironment} from '@jest/environment';
import {
Expand Down Expand Up @@ -46,8 +45,6 @@ interface JestGlobals extends Global.TestFrameworkGlobals {
export const initialize = async ({
config,
environment,
getPrettier,
getBabelTraverse,
globalConfig,
localRequire,
parentProcess,
Expand All @@ -57,8 +54,6 @@ export const initialize = async ({
}: {
config: Config.ProjectConfig;
environment: JestEnvironment;
getPrettier: () => null | any;
getBabelTraverse: () => typeof BabelTraverse;
globalConfig: Config.GlobalConfig;
localRequire: <T = unknown>(path: Config.Path) => T;
testPath: Config.Path;
Expand Down Expand Up @@ -162,8 +157,7 @@ export const initialize = async ({
const snapshotPath = snapshotResolver.resolveSnapshotPath(testPath);
const snapshotState = new SnapshotState(snapshotPath, {
expand,
getBabelTraverse,
getPrettier,
prettierPath: config.prettierPath,
updateSnapshot,
});
// @ts-expect-error: snapshotState is a jest extension of `expect`
Expand Down
5 changes: 2 additions & 3 deletions packages/jest-jasmine2/src/setup_jest_globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,12 @@ export default ({

patchJasmine();
const {expand, updateSnapshot} = globalConfig;
const {prettierPath} = config;
const snapshotResolver = buildSnapshotResolver(config);
const snapshotPath = snapshotResolver.resolveSnapshotPath(testPath);
const snapshotState = new SnapshotState(snapshotPath, {
expand,
getBabelTraverse: () => require('@babel/traverse').default,
getPrettier: () =>
config.prettierPath ? require(config.prettierPath) : null,
prettierPath,
updateSnapshot,
});
// @ts-expect-error: snapshotState is a jest extension of `expect`
Expand Down
20 changes: 18 additions & 2 deletions packages/jest-snapshot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@
"./package.json": "./package.json"
},
"dependencies": {
"@babel/generator": "^7.7.2",
"@babel/parser": "^7.7.2",
"@babel/plugin-syntax-typescript": "^7.7.2",
"@babel/traverse": "^7.7.2",
"@babel/types": "^7.0.0",
"@jest/types": "^26.6.2",
"@types/babel__traverse": "^7.0.4",
"@types/prettier": "^2.0.0",
"@types/prettier": "^2.1.5",
"babel-preset-current-node-syntax": "^1.0.0",
"chalk": "^4.0.0",
"expect": "^26.6.2",
"graceful-fs": "^4.2.4",
Expand All @@ -32,14 +37,25 @@
"semver": "^7.3.2"
},
"devDependencies": {
"@babel/core": "^7.7.2",
"@babel/preset-flow": "^7.7.2",
"@babel/preset-react": "^7.7.2",
"@babel/traverse": "^7.3.4",
"@jest/test-utils": "^26.6.2",
"@types/graceful-fs": "^4.1.3",
"@types/natural-compare": "^1.4.0",
"@types/semver": "^7.1.0",
"ansi-regex": "^5.0.0",
"ansi-styles": "^4.2.0",
"prettier": "^1.19.1"
"prettier": "^2.0.0"
},
"peerDependencies": {
jeysal marked this conversation as resolved.
Show resolved Hide resolved
"@babel/core": "^7.7.2"
},
"peerDependenciesMeta": {
"@babel/core": {
"optional": true
jeysal marked this conversation as resolved.
Show resolved Hide resolved
}
},
"engines": {
"node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0"
Expand Down
Loading