Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Meta
create-react-app
Commits
d639e90b
Unverified
Commit
d639e90b
authored
7 years ago
by
Dan Abramov
Committed by
GitHub
7 years ago
Browse files
Options
Download
Email Patches
Plain Diff
Work around Jest environment resolving bug (#4247)
parent
609aeea6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/react-scripts/package.json
+1
-0
packages/react-scripts/package.json
packages/react-scripts/scripts/test.js
+55
-1
packages/react-scripts/scripts/test.js
with
56 additions
and
1 deletion
+56
-1
packages/react-scripts/package.json
+
1
-
0
View file @
d639e90b
...
@@ -51,6 +51,7 @@
...
@@ -51,6 +51,7 @@
"promise"
:
"8.0.1"
,
"promise"
:
"8.0.1"
,
"raf"
:
"3.4.0"
,
"raf"
:
"3.4.0"
,
"react-dev-utils"
:
"^5.0.0"
,
"react-dev-utils"
:
"^5.0.0"
,
"resolve"
:
"1.6.0"
,
"style-loader"
:
"0.19.0"
,
"style-loader"
:
"0.19.0"
,
"sw-precache-webpack-plugin"
:
"0.11.4"
,
"sw-precache-webpack-plugin"
:
"0.11.4"
,
"url-loader"
:
"0.6.2"
,
"url-loader"
:
"0.6.2"
,
...
...
This diff is collapsed.
Click to expand it.
packages/react-scripts/scripts/test.js
+
55
-
1
View file @
d639e90b
...
@@ -24,7 +24,7 @@ process.on('unhandledRejection', err => {
...
@@ -24,7 +24,7 @@ process.on('unhandledRejection', err => {
require
(
'
../config/env
'
);
require
(
'
../config/env
'
);
const
jest
=
require
(
'
jest
'
);
const
jest
=
require
(
'
jest
'
);
cons
t
argv
=
process
.
argv
.
slice
(
2
);
le
t
argv
=
process
.
argv
.
slice
(
2
);
// Watch unless on CI or in coverage mode
// Watch unless on CI or in coverage mode
if
(
!
process
.
env
.
CI
&&
argv
.
indexOf
(
'
--coverage
'
)
<
0
)
{
if
(
!
process
.
env
.
CI
&&
argv
.
indexOf
(
'
--coverage
'
)
<
0
)
{
...
@@ -46,5 +46,59 @@ argv.push(
...
@@ -46,5 +46,59 @@ argv.push(
)
)
)
)
);
);
// This is a very dirty workaround for https://github.com/facebook/jest/issues/5913.
// We're trying to resolve the environment ourselves because Jest does it incorrectly.
// TODO: remove this (and the `resolve` dependency) as soon as it's fixed in Jest.
const
resolve
=
require
(
'
resolve
'
);
function
resolveJestDefaultEnvironment
(
name
)
{
const
jestDir
=
path
.
dirname
(
resolve
.
sync
(
'
jest
'
,
{
basedir
:
__dirname
,
})
);
const
jestCLIDir
=
path
.
dirname
(
resolve
.
sync
(
'
jest-cli
'
,
{
basedir
:
jestDir
,
})
);
const
jestConfigDir
=
path
.
dirname
(
resolve
.
sync
(
'
jest-config
'
,
{
basedir
:
jestCLIDir
,
})
);
return
resolve
.
sync
(
name
,
{
basedir
:
jestConfigDir
,
});
}
let
cleanArgv
=
[];
let
env
=
'
node
'
;
let
next
;
do
{
next
=
argv
.
shift
();
if
(
next
===
'
--env
'
)
{
env
=
argv
.
shift
();
}
else
if
(
next
.
indexOf
(
'
--env=
'
)
===
0
)
{
env
=
next
.
substring
(
'
--env=
'
.
length
);
}
else
{
cleanArgv
.
push
(
next
);
}
}
while
(
argv
.
length
>
0
);
argv
=
cleanArgv
;
let
resolvedEnv
;
try
{
resolvedEnv
=
resolveJestDefaultEnvironment
(
`jest-environment-
${
env
}
`
);
}
catch
(
e
)
{
// ignore
}
if
(
!
resolvedEnv
)
{
try
{
resolvedEnv
=
resolveJestDefaultEnvironment
(
env
);
}
catch
(
e
)
{
// ignore
}
}
const
testEnvironment
=
resolvedEnv
||
env
;
argv
.
push
(
'
--env
'
,
testEnvironment
);
// @remove-on-eject-end
// @remove-on-eject-end
jest
.
run
(
argv
);
jest
.
run
(
argv
);
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment