Skip to content

Commit 8001b64

Browse files
author
Brian Vaughn
committed
Fixed raw-loader + Jest problem
1 parent b5195a5 commit 8001b64

File tree

10 files changed

+39
-20
lines changed

10 files changed

+39
-20
lines changed

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
},
1313
"globals": {
1414
"__DEV__": "readonly",
15+
"__TEST__": "readonly",
1516
"jasmine": "readonly",
1617
"spyOn": "readonly"
1718
}

flow.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ declare module 'events' {
1818
}
1919

2020
declare var __DEV__: boolean;
21+
declare var __TEST__: boolean;
2122

2223
declare var jasmine: {|
2324
getEnv: () => {|

packages/react-devtools-core/webpack.backend.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module.exports = {
3535
plugins: [
3636
new DefinePlugin({
3737
__DEV__: true,
38+
__TEST__: false,
3839
'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
3940
'process.env.GITHUB_URL': `"${GITHUB_URL}"`,
4041
}),

packages/react-devtools-core/webpack.standalone.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module.exports = {
3434
plugins: [
3535
new DefinePlugin({
3636
__DEV__: false,
37+
__TEST__: false,
3738
'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
3839
'process.env.GITHUB_URL': `"${GITHUB_URL}"`,
3940
'process.env.NODE_ENV': `"${NODE_ENV}"`,

packages/react-devtools-inline/webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ module.exports = {
3838
},
3939
plugins: [
4040
new DefinePlugin({
41-
__DEV__: __DEV__,
41+
__DEV__,
42+
__TEST__: false,
4243
'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
4344
'process.env.GITHUB_URL': `"${GITHUB_URL}"`,
4445
'process.env.NODE_ENV': `"${NODE_ENV}"`,

shells/browser/shared/webpack.backend.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ module.exports = {
3131
plugins: [
3232
new DefinePlugin({
3333
__DEV__: true,
34+
__TEST__: false,
3435
'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
3536
'process.env.GITHUB_URL': `"${GITHUB_URL}"`,
3637
}),

shells/browser/shared/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module.exports = {
3636
plugins: [
3737
new DefinePlugin({
3838
__DEV__: false,
39+
__TEST__: false,
3940
'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
4041
'process.env.GITHUB_URL': `"${GITHUB_URL}"`,
4142
'process.env.NODE_ENV': `"${NODE_ENV}"`,

shells/dev/webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ const config = {
3939
},
4040
plugins: [
4141
new DefinePlugin({
42-
__DEV__: __DEV__,
42+
__DEV__,
43+
__TEST__: false,
4344
'process.env.GITHUB_URL': `"${GITHUB_URL}"`,
4445
'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
4546
}),

src/__tests__/setupEnv.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ if (!global.hasOwnProperty('localStorage')) {
1212

1313
// Mimic the global we set with Webpack's DefinePlugin
1414
global.__DEV__ = process.env.NODE_ENV !== 'production';
15+
global.__TEST__ = process.env.NODE_ENV === 'test';

src/constants.js

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,8 @@
11
// @flow
22

3-
// $FlowFixMe Cannot resolve module
4-
import rawStyleString from '!!raw-loader!src/devtools/views/root.css'; // eslint-disable-line import/no-webpack-loader-syntax
5-
63
// Flip this flag to true to enable verbose console debug logging.
74
export const __DEBUG__ = false;
85

9-
const extractVar = varName => {
10-
const regExp = new RegExp(`${varName}: ([0-9]+)`);
11-
const match = rawStyleString.match(regExp);
12-
return parseInt(match[1], 10);
13-
};
14-
15-
// TRICKY
16-
// Extracting during build time avoids a temporarily invalid state for the inline target.
17-
// Sometimes the inline target is rendered before root styles are applied,
18-
// which would result in e.g. NaN itemSize being passed to react-window list.
19-
export const COMFORTABLE_LINE_HEIGHT = extractVar(
20-
'comfortable-line-height-data'
21-
);
22-
export const COMPACT_LINE_HEIGHT = extractVar('compact-line-height-data');
23-
246
export const TREE_OPERATION_ADD = 1;
257
export const TREE_OPERATION_REMOVE = 2;
268
export const TREE_OPERATION_REORDER_CHILDREN = 3;
@@ -45,3 +27,31 @@ export const PROFILER_EXPORT_VERSION = 4;
4527

4628
export const CHANGE_LOG_URL =
4729
'https://github.com/bvaughn/react-devtools-experimental/blob/master/CHANGELOG.md';
30+
31+
// HACK
32+
//
33+
// Extracting during build time avoids a temporarily invalid state for the inline target.
34+
// Sometimes the inline target is rendered before root styles are applied,
35+
// which would result in e.g. NaN itemSize being passed to react-window list.
36+
//
37+
// We can't use the Webpack loader syntax in the context of Jest though,
38+
// so tests need some reasonably meaningful fallback value.
39+
let COMFORTABLE_LINE_HEIGHT = 15;
40+
let COMPACT_LINE_HEIGHT = 10;
41+
42+
if (!__TEST__) {
43+
// $FlowFixMe
44+
const rawStyleString = require('!!raw-loader!src/devtools/views/root.css') // eslint-disable-line import/no-webpack-loader-syntax
45+
.default;
46+
47+
const extractVar = varName => {
48+
const regExp = new RegExp(`${varName}: ([0-9]+)`);
49+
const match = rawStyleString.match(regExp);
50+
return parseInt(match[1], 10);
51+
};
52+
53+
COMFORTABLE_LINE_HEIGHT = extractVar('comfortable-line-height-data');
54+
COMPACT_LINE_HEIGHT = extractVar('compact-line-height-data');
55+
}
56+
57+
export { COMFORTABLE_LINE_HEIGHT, COMPACT_LINE_HEIGHT };

0 commit comments

Comments
 (0)