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

Update prettier to the latest version 🚀 #1016

Merged
merged 2 commits into from
Sep 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
"lint-staged": "^4.0.0",
"markdox": "^0.1.10",
"mobx-react-devtools": "^4.2.11",
"prettier": "1.7.1",
"prettier": "1.7.2",
"react-test-renderer": "^15.5.4"
}
}
30 changes: 24 additions & 6 deletions spec/code-manager-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ describe("CodeManager", () => {
it("getRows", () => {
spyOn(editor, "getTextInBufferRange");
CM.getRows(editor, 1, 10);
const range = { start: { row: 1, column: 0 }, end: { row: 10, column: 9999999 } };
const range = {
start: { row: 1, column: 0 },
end: { row: 10, column: 9999999 }
};
expect(editor.getTextInBufferRange).toHaveBeenCalledWith(range);
});

Expand All @@ -59,7 +62,12 @@ describe("CodeManager", () => {
describe("getCellsForBreakPoints", () => {
it("return cells(ranges) from array of points", () => {
const points = [[1, 2], [3, 4], [5, 6], [10, 5]].map(toPoint); // bp1 // bp2 // bp3 // bp4
const cellsExpected = [[[0, 0], [1, 2]], [[2, 0], [3, 4]], [[4, 0], [5, 6]], [[6, 0], [10, 5]]].map(toRange); // zero-to-bp1 // nextRow of bp1 to bp2 // nextRow of bp2 to bp3 // nextRow of bp3 to bp4
const cellsExpected = [
[[0, 0], [1, 2]],
[[2, 0], [3, 4]],
[[4, 0], [5, 6]],
[[6, 0], [10, 5]]
].map(toRange); // zero-to-bp1 // nextRow of bp1 to bp2 // nextRow of bp2 to bp3 // nextRow of bp3 to bp4

expect(CM.getCellsForBreakPoints(points)).toEqual(cellsExpected);
});
Expand All @@ -75,23 +83,33 @@ describe("CodeManager", () => {
});
};
}
beforeEach(waitAsync(async () => {
beforeEach(
waitAsync(async () => {
await atom.packages.activatePackage("language-python");
editor.setGrammar(atom.grammars.grammarForScopeName("source.python"));
const code = ["v0 = 0 # %%", "v1 = 1", "v2 = 2 # %%", "v3 = 3"]; // row0:bp // row1 // row2:bp // row3
editor.setText(code.join("\n") + "\n");
}));
})
);
describe("no arg", () => {
it("return cell(range) by detecting breakpoints in comment", () => {
// EOF is always treated as implicit breakpoints
const cellsExpected = [[[0, 0], [0, 7]], [[1, 0], [2, 7]], [[3, 0], [4, 0]]].map(toRange); // zero-to-row0:bp // nextRow of row0:bp to row2:bp // nextRow of row2:bp to EOF(= implicit bp)
const cellsExpected = [
[[0, 0], [0, 7]],
[[1, 0], [2, 7]],
[[3, 0], [4, 0]]
].map(toRange); // zero-to-row0:bp // nextRow of row0:bp to row2:bp // nextRow of row2:bp to EOF(= implicit bp)
expect(CM.getCells(editor)).toEqual(cellsExpected);
});
});
describe("with arg(= breakpoints)", () => {
it("return cells(range) from passed breakpoints(with auto-sort-by-position)", () => {
breakpoints = [[0, 11], [2, 11], [1, 6]].map(toPoint); // row0:bp // row2:bp // row1:bp
const cellsExpected = [[[0, 0], [0, 11]], [[1, 0], [1, 6]], [[2, 0], [2, 11]]].map(toRange); // zero to row0:bp // nextRow of row0:bp to row1:bp // nextRow of row1:bp to row2:bp
const cellsExpected = [
[[0, 0], [0, 11]],
[[1, 0], [1, 6]],
[[2, 0], [2, 11]]
].map(toRange); // zero to row0:bp // nextRow of row0:bp to row1:bp // nextRow of row1:bp to row2:bp

expect(CM.getCells(editor, breakpoints)).toEqual(cellsExpected);
});
Expand Down
28 changes: 22 additions & 6 deletions spec/components/status-bar-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ import StatusBar from "../../lib/components/status-bar";

describe("Status Bar", () => {
it("should render status bar and call onClick if clicked", () => {
const mockStore = { kernel: { displayName: "Foo Kernel", executionState: "idle" } };
const mockStore = {
kernel: { displayName: "Foo Kernel", executionState: "idle" }
};
const onClick = jasmine.createSpy("onClick");
const component = shallow(<StatusBar store={mockStore} onClick={onClick} />);
const component = shallow(
<StatusBar store={mockStore} onClick={onClick} />
);
component.find("a").simulate("click");
expect(component.type()).not.toBeNull();
expect(component.text()).toBe("Foo Kernel | idle");
Expand All @@ -19,7 +23,9 @@ describe("Status Bar", () => {

it("should return empty if kernel is undefined", () => {
const mockStore = { kernel: undefined };
const component = shallow(<StatusBar store={mockStore} onClick={() => {}} />);
const component = shallow(
<StatusBar store={mockStore} onClick={() => {}} />
);
expect(component.type()).toBeNull();
expect(component.text()).toBe("");
});
Expand All @@ -41,12 +47,22 @@ describe("Status Bar", () => {
const grammar = editor.getGrammar();
expect(grammar.name).toBe("Null Grammar");

const kernelSpec = { language: "null grammar", display_name: "Null Kernel" };
const kernel = { kernelSpec: kernelSpec, language: kernelSpec.language.toLowerCase(), displayName: kernelSpec.display_name, executionState: "starting" };
const kernelSpec = {
language: "null grammar",
display_name: "Null Kernel"
};
const kernel = {
kernelSpec: kernelSpec,
language: kernelSpec.language.toLowerCase(),
displayName: kernelSpec.display_name,
executionState: "starting"
};
store.newKernel(kernel);
expect(store.runningKernels.toJS()["null grammar"]).toEqual(kernel);
expect(store.kernel.kernelSpec.language).toBe(kernel.kernelSpec.language);
expect(store.kernel.kernelSpec.display_name).toBe(kernel.kernelSpec.display_name);
expect(store.kernel.kernelSpec.display_name).toBe(
kernel.kernelSpec.display_name
);
expect(store.kernel.language).toBe(kernel.language);
expect(store.kernel.displayName).toBe(kernel.displayName);
expect(store.kernel.executionState).toBe(kernel.executionState);
Expand Down
3 changes: 2 additions & 1 deletion spec/kernel-manager-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ describe("Kernel manager", () => {
});
});

describe("mergeKernelSpecs", () => it("should merge kernelspecs", () => {
describe("mergeKernelSpecs", () =>
it("should merge kernelspecs", () => {
kernelManager._kernelSpecs = firstKernelSpec.kernelspecs;
kernelManager.mergeKernelSpecs(secondKernelSpec.kernelspecs);

Expand Down
62 changes: 48 additions & 14 deletions spec/store/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,20 @@ describe("Store", () => {
const currentKernel = { kernelSpec: { language: "null grammar" } };
const notCurrentKernel = { kernelSpec: { language: "mock grammar" } };

const runningKernels = { "current kernel": currentKernel, "not current kernel": notCurrentKernel };
const runningKernels = {
"current kernel": currentKernel,
"not current kernel": notCurrentKernel
};
for (let kernelLanguage of Object.keys(runningKernels)) {
const kernel = runningKernels[kernelLanguage];
store.runningKernels.set(kernelLanguage, kernel);
}
expect(Object.keys(store.runningKernels.toJS()).sort()).toEqual(Object.keys(runningKernels).sort());
expect(store.kernel.kernelSpec.language).toBe(currentKernel.kernelSpec.language);
expect(Object.keys(store.runningKernels.toJS()).sort()).toEqual(
Object.keys(runningKernels).sort()
);
expect(store.kernel.kernelSpec.language).toBe(
currentKernel.kernelSpec.language
);
});

it("should set grammar to null if editor is null", () => {
Expand All @@ -65,14 +72,26 @@ describe("Store", () => {
});

it("should set multi language grammar inside code block", () => {
const editor = { getGrammar: () => {
const editor = {
getGrammar: () => {
return { scopeName: "source.gfm", name: "GitHub Markdown" };
}, getCursorBufferPosition: () => {}, scopeDescriptorForBufferPosition: () => {
return { getScopesArray: () => ["source.gfm", "markup.code.python.gfm", "source.embedded.python"] };
} };
},
getCursorBufferPosition: () => {},
scopeDescriptorForBufferPosition: () => {
return {
getScopesArray: () => [
"source.gfm",
"markup.code.python.gfm",
"source.embedded.python"
]
};
}
};

const pythonGrammar = { scopeName: "source.python", name: "Python" };
spyOn(atom.grammars, "grammarForScopeName").and.returnValue(pythonGrammar);
spyOn(atom.grammars, "grammarForScopeName").and.returnValue(
pythonGrammar
);

store.setGrammar(editor);
expect(store.grammar).toEqual(pythonGrammar);
Expand All @@ -81,9 +100,15 @@ describe("Store", () => {

it("should set multi language grammar outside code block", () => {
const grammar = { scopeName: "source.gfm", name: "GitHub Markdown" };
const editor = { getGrammar: () => grammar, getCursorBufferPosition: () => {}, scopeDescriptorForBufferPosition: () => {
return { getScopesArray: () => ["source.gfm", "markup.code.python.gfm"] };
} };
const editor = {
getGrammar: () => grammar,
getCursorBufferPosition: () => {},
scopeDescriptorForBufferPosition: () => {
return {
getScopesArray: () => ["source.gfm", "markup.code.python.gfm"]
};
}
};

store.setGrammar(editor);
expect(store.grammar).toEqual(grammar);
Expand All @@ -92,8 +117,15 @@ describe("Store", () => {
});

it("should add new kernel and reset starting kernel indicator", () => {
const kernelSpec = { language: "null grammar", display_name: "null grammar" };
const kernel = { language: "null grammar", foo: "bar", kernelSpec: kernelSpec };
const kernelSpec = {
language: "null grammar",
display_name: "null grammar"
};
const kernel = {
language: "null grammar",
foo: "bar",
kernelSpec: kernelSpec
};
const { display_name } = kernelSpec;

store.startKernel(display_name);
Expand All @@ -103,7 +135,9 @@ describe("Store", () => {
expect(store.startingKernels.get(display_name)).toBeUndefined();

expect(store.runningKernels.size).toBe(1);
expect(store.runningKernels.get("null grammar").language).toBe("null grammar");
expect(store.runningKernels.get("null grammar").language).toBe(
"null grammar"
);
expect(store.runningKernels.get("null grammar").foo).toBe("bar");
});

Expand Down
4 changes: 3 additions & 1 deletion spec/store/markers-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ describe("MarkerStore", () => {
});

it("clears bubble on row", () => {
const bubble = { marker: { getBufferRange: () => new Range([5, 1], [5, 3]) } };
const bubble = {
marker: { getBufferRange: () => new Range([5, 1], [5, 3]) }
};

spyOn(store, "delete");

Expand Down
18 changes: 14 additions & 4 deletions spec/store/output-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import OutputStore, {
// Adapted from https://github.com/nteract/nteract/blob/master/test/renderer/reducers/document-spec.js#L33
describe("reduceOutputs", () => {
it("puts new outputs at the end by default", () => {
const outputs = [{ output_type: "stream", name: "stdout", text: "Woo" }, { output_type: "error", ename: "well", evalue: "actually", traceback: [] }];
const outputs = [
{ output_type: "stream", name: "stdout", text: "Woo" },
{ output_type: "error", ename: "well", evalue: "actually", traceback: [] }
];
const newOutputs = reduceOutputs(outputs, {
output_type: "display_data",
data: {},
Expand Down Expand Up @@ -75,7 +78,10 @@ describe("reduceOutputs", () => {
});

it("keeps respective streams together", () => {
const outputs = [{ name: "stdout", text: "hello", output_type: "stream" }, { name: "stderr", text: "errors are", output_type: "stream" }];
const outputs = [
{ name: "stdout", text: "hello", output_type: "stream" },
{ name: "stderr", text: "errors are", output_type: "stream" }
];
const newOutputs = reduceOutputs(outputs, {
name: "stdout",
text: " world",
Expand Down Expand Up @@ -128,8 +134,12 @@ describe("isSingeLine", () => {
});
it("checks for single line output with line break at the end ", () => {
const textEndlinebreak = "hello world \n";
expect(isSingeLine(textEndlinebreak, textEndlinebreak.length + 1)).toEqual(true);
expect(isSingeLine(textEndlinebreak, textEndlinebreak.length)).toEqual(false);
expect(isSingeLine(textEndlinebreak, textEndlinebreak.length + 1)).toEqual(
true
);
expect(isSingeLine(textEndlinebreak, textEndlinebreak.length)).toEqual(
false
);
});
});

Expand Down
5 changes: 4 additions & 1 deletion spec/store/watch-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ describe("WatchStore", () => {
spyOn(store.kernel, "executeWatch").and.callThrough();
spyOn(store.outputStore, "appendOutput");
store.run();
expect(store.kernel.executeWatch).toHaveBeenCalledWith("foo", jasmine.any(Function));
expect(store.kernel.executeWatch).toHaveBeenCalledWith(
"foo",
jasmine.any(Function)
);
expect(store.outputStore.appendOutput).toHaveBeenCalledWith("result");
});
it("checks for empty string function", () => {
Expand Down
46 changes: 33 additions & 13 deletions spec/utils-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,20 @@ describe("utils", () => {
});

it("should return respect languageMappings", () => {
atom.config.set("Hydrogen.languageMappings", `{"Kernel Language": "Grammar Language"}`);
expect(grammarToLanguage({
atom.config.set(
"Hydrogen.languageMappings",
`{"Kernel Language": "Grammar Language"}`
);
expect(
grammarToLanguage({
name: "Grammar Language"
})).toEqual("kernel language");
expect(grammarToLanguage({
})
).toEqual("kernel language");
expect(
grammarToLanguage({
name: "Kernel Language"
})).toEqual("kernel language");
})
).toEqual("kernel language");
atom.config.set("Hydrogen.languageMappings", "");
});
});
Expand All @@ -58,9 +65,9 @@ describe("utils", () => {
});

it("isMultilanguageGrammar", () => {
expect(isMultilanguageGrammar(atom.workspace
.buildTextEditor()
.getGrammar())).toBe(false);
expect(
isMultilanguageGrammar(atom.workspace.buildTextEditor().getGrammar())
).toBe(false);
expect(isMultilanguageGrammar({ scopeName: "source.gfm" })).toBe(true);
expect(isMultilanguageGrammar({ scopeName: "source.asciidoc" })).toBe(true);
});
Expand All @@ -79,18 +86,31 @@ describe("utils", () => {
});

it("getEmbeddedScope", () => {
const editor = { scopeDescriptorForBufferPosition: () => {
return { getScopesArray: () => ["text.md", "fenced.code.md", "source.embedded.python"] };
} };
const editor = {
scopeDescriptorForBufferPosition: () => {
return {
getScopesArray: () => [
"text.md",
"fenced.code.md",
"source.embedded.python"
]
};
}
};
spyOn(editor, "scopeDescriptorForBufferPosition").and.callThrough();
const scope = getEmbeddedScope(editor, "position");
expect(scope).toEqual("source.embedded.python");
expect(editor.scopeDescriptorForBufferPosition).toHaveBeenCalledWith("position");
expect(editor.scopeDescriptorForBufferPosition).toHaveBeenCalledWith(
"position"
);
});

describe("msgSpecToNotebookFormat", () => {
it("converts a message to the notebook format", () => {
const msg = { content: { data: "test" }, header: { msg_type: "test_header" } };
const msg = {
content: { data: "test" },
header: { msg_type: "test_header" }
};
const notebookSpecMsg = msgSpecToNotebookFormat(msg);

expect(notebookSpecMsg.output_type).toEqual("test_header");
Expand Down