Skip to content

Commit bed2531

Browse files
authored
Merge pull request firefox-devtools#542 from jasonLaster/pp-fix
Fix Pretty Print tests
2 parents beaae7a + a4780d3 commit bed2531

5 files changed

Lines changed: 62 additions & 31 deletions

File tree

public/js/actions/sources.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ function blackbox(source, shouldBlackBox) {
196196
function togglePrettyPrint(id) {
197197
return ({ dispatch, getState, client }) => {
198198
const source = getSource(getState(), id).toJS();
199+
const sourceText = getSourceText(getState(), id).toJS();
200+
201+
if (sourceText.loading) {
202+
return;
203+
}
199204

200205
if (!isEnabled("prettyPrint") || source.isPrettyPrinted) {
201206
return {};
@@ -210,7 +215,6 @@ function togglePrettyPrint(id) {
210215
source,
211216
originalSource,
212217
[PROMISE]: (async function () {
213-
const sourceText = getSourceText(getState(), source.id).toJS();
214218
const text = await _prettyPrintSource({ source, sourceText, url });
215219

216220
dispatch(selectSource(originalSource.id));

public/js/components/Editor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ module.exports = connect(
179179
const selectedId = selectedSource && selectedSource.get("id");
180180

181181
return {
182-
selectedSource: selectedSource,
182+
selectedSource,
183183
sourceText: getSourceText(state, selectedId),
184184
breakpoints: getBreakpointsForSource(state, selectedId),
185185
selectedFrame: getSelectedFrame(state)
Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
const React = require("react");
2-
const { DOM: dom } = React;
2+
const { DOM: dom, PropTypes } = React;
33
const { connect } = require("react-redux");
44
const { bindActionCreators } = require("redux");
55
const actions = require("../actions");
66
const { isEnabled } = require("../feature");
7-
const { getSelectedSource } = require("../selectors");
7+
const { getSelectedSource, getSourceText } = require("../selectors");
88
const Svg = require("./utils/Svg");
9+
const ImPropTypes = require("react-immutable-proptypes");
10+
const classnames = require("classnames");
911

1012
function debugBtn(onClick, type, className = "active", tooltip) {
1113
className = `${type} ${className}`;
@@ -15,33 +17,58 @@ function debugBtn(onClick, type, className = "active", tooltip) {
1517
);
1618
}
1719

18-
function SourceFooter({ togglePrettyPrint, selectedSource }) {
19-
const commandsEnabled = selectedSource ? "" : "disabled";
20-
21-
return dom.div(
22-
{
23-
className: "source-footer"
24-
},
25-
dom.div({ className: "command-bar" },
26-
isEnabled("blackbox") ? debugBtn(
27-
() => {},
28-
"blackBox",
29-
commandsEnabled,
30-
"Toggle Black Boxing"
31-
) : null,
32-
debugBtn(
33-
() => togglePrettyPrint(selectedSource.get("id")),
34-
"prettyPrint",
35-
commandsEnabled,
36-
"Prettify Source"
20+
const SourceFooter = React.createClass({
21+
propTypes: {
22+
selectedSource: ImPropTypes.map.isRequired,
23+
togglePrettyPrint: PropTypes.func,
24+
sourceText: ImPropTypes.map.isRequired
25+
},
26+
27+
displayName: "Editor",
28+
29+
blackboxButton() {
30+
if (!isEnabled("blackbox")) {
31+
return null;
32+
}
33+
34+
return debugBtn(
35+
() => {},
36+
"blackBox",
37+
this.props.selectedSource,
38+
"Toggle Black Boxing"
39+
);
40+
},
41+
42+
prettyPrintButton() {
43+
const { selectedSource, sourceText, togglePrettyPrint } = this.props;
44+
const sourceLoaded = selectedSource && !sourceText.get("loading");
45+
46+
return debugBtn(
47+
() => togglePrettyPrint(selectedSource.get("id")),
48+
"prettyPrint",
49+
classnames({ active: sourceLoaded }),
50+
"Prettify Source"
51+
);
52+
},
53+
54+
render() {
55+
return dom.div({ className: "source-footer" },
56+
dom.div({ className: "command-bar" },
57+
this.blackboxButton(),
58+
this.prettyPrintButton()
3759
)
38-
)
39-
);
40-
}
60+
);
61+
}
62+
});
4163

4264
module.exports = connect(
43-
state => ({
44-
selectedSource: getSelectedSource(state),
45-
}),
65+
state => {
66+
const selectedSource = getSelectedSource(state);
67+
const selectedId = selectedSource && selectedSource.get("id");
68+
return {
69+
selectedSource,
70+
sourceText: getSourceText(state, selectedId)
71+
};
72+
},
4673
dispatch => bindActionCreators(actions, dispatch)
4774
)(SourceFooter);

public/js/test/cypress/commands.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Cypress.addParentCommand("debuggee", function(callback) {
3535
return cy.window().then(win => {
3636
win.injectDebuggee();
3737
return win.client.debuggeeCommand(script);
38-
});
38+
}).wait(1000);
3939
});
4040

4141
Cypress.addParentCommand("navigate", function(url) {

public/js/test/cypress/commands/debugger.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function stepOut() {
123123
}
124124

125125
function prettyPrint() {
126-
return sourceFooter().get("span.prettyPrint").click()
126+
return sourceFooter().get("span.prettyPrint.active").click()
127127
}
128128

129129
/**

0 commit comments

Comments
 (0)