Skip to content
New issue

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

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

Already on GitHub? # to your account

improve error feedback #24

Merged
merged 8 commits into from
Mar 16, 2018
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 dist/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ exports.removeAutoWidth = removeAutoWidth;
function render(pOptions) {
return readFromStream_1.readFromStream(fileNameToStream_1.getInStream(pOptions.inputFrom))
.then((pInput) => getAST(pInput, pOptions))
.then((pAST) => render_1.renderTheShizzle(removeAutoWidth(pAST, pOptions.outputType), pOptions));
.then((pAST) => render_1.renderWithChromeHeadless(removeAutoWidth(pAST, pOptions.outputType), pOptions));
}
function transpile(pOptions) {
return readFromStream_1.readFromStream(fileNameToStream_1.getInStream(pOptions.inputFrom))
Expand Down
15 changes: 9 additions & 6 deletions dist/actions/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function getPuppeteerLaunchOptions(pPuppeteerLaunchOptions) {
headless: true,
}, pPuppeteerLaunchOptions || {});
}
function renderTheShizzle(pAST, pOptions) {
function renderWithChromeHeadless(pAST, pOptions) {
return __awaiter(this, void 0, void 0, function* () {
let browser = {};
try {
Expand All @@ -38,8 +38,14 @@ function renderTheShizzle(pAST, pOptions) {
yield page.addScriptTag({
path: require.resolve("mscgenjs-inpage"),
});
yield page.waitFor("mscgen#replaceme[data-renderedby='mscgen_js']", { timeout: 10000 });
yield page.waitFor("mscgen#replaceme[data-renderedby='mscgen_js']");
if (pOptions.outputType === "svg") {
/* the istanbul ignore thing is so istanbul won't instrument code
that is meant to be run in browser context. If it does,
you'll get errors like 'Error: Evaluation failed: ReferenceError: cov_'
- which is chrome (not node) telling us something is foobar
*/
/* istanbul ignore next */
return yield page.evaluate(() => {
const lSVGElement = document.getElementById("mscgenjsreplaceme");
if (lSVGElement) {
Expand All @@ -62,17 +68,14 @@ function renderTheShizzle(pAST, pOptions) {
});
}
}
catch (pError) {
return pError;
}
finally {
if (Boolean(browser) && typeof browser.close === "function") {
browser.close();
}
}
});
}
exports.renderTheShizzle = renderTheShizzle;
exports.renderWithChromeHeadless = renderWithChromeHeadless;
/*
This file is part of mscgenjs-cli.
mscgenjs-cli is free software: you can redistribute it and/or modify
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"npm-check-updates": "ncu --upgrade",
"npm-install": "npm install",
"nsp": "nsp check --warn-only",
"test": "mocha --require ts-node/register --timeout 10000 --reporter dot --recursive test/*.ts test/**/*.ts",
"test": "mocha --require ts-node/register --timeout 10000 --recursive test/*.ts test/**/*.ts",
"test:cover": "nyc --extension .ts --check-coverage npm test",
"update-dependencies": "npm-run-all npm-check-updates npm-install lint:fix depcruise build test",
"watch": "tsc --project src --watch"
Expand Down Expand Up @@ -85,7 +85,10 @@
"typescript": "2.7.2"
},
"nyc": {
"lines": 85,
"statements": 95.95,
"branches": 95.77,
"functions": 90.74,
"lines": 95.91,
"reporter": [
"text-summary",
"html"
Expand Down
4 changes: 2 additions & 2 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as pify from "pify";
import { INormalizedOptions, OutputType } from "../types";
import { getInStream, getOutStream } from "./fileNameToStream";
import { readFromStream } from "./readFromStream";
import { renderTheShizzle } from "./render";
import { renderWithChromeHeadless } from "./render";

const translate = pify(translateMsc);

Expand Down Expand Up @@ -37,7 +37,7 @@ function render(pOptions: INormalizedOptions): Promise<any> {
return readFromStream(getInStream(pOptions.inputFrom))
.then((pInput) => getAST(pInput, pOptions))
.then((pAST) =>
renderTheShizzle(
renderWithChromeHeadless(
removeAutoWidth(pAST, pOptions.outputType),
pOptions,
),
Expand Down
12 changes: 8 additions & 4 deletions src/actions/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function getPuppeteerLaunchOptions(pPuppeteerLaunchOptions: IPuppeteerOptions) {
);
}

export async function renderTheShizzle(pAST: any, pOptions: INormalizedOptions) {
export async function renderWithChromeHeadless(pAST: any, pOptions: INormalizedOptions) {

let browser: puppeteer.Browser = {} as puppeteer.Browser;

Expand All @@ -45,9 +45,15 @@ export async function renderTheShizzle(pAST: any, pOptions: INormalizedOptions)
path: require.resolve("mscgenjs-inpage"),
});

await page.waitFor("mscgen#replaceme[data-renderedby='mscgen_js']", {timeout: 10000});
await page.waitFor("mscgen#replaceme[data-renderedby='mscgen_js']");

if (pOptions.outputType === "svg") {
/* the istanbul ignore thing is so istanbul won't instrument code
that is meant to be run in browser context. If it does,
you'll get errors like 'Error: Evaluation failed: ReferenceError: cov_'
- which is chrome (not node) telling us something is foobar
*/
/* istanbul ignore next */
return await page.evaluate(() => {
const lSVGElement = document.getElementById("mscgenjsreplaceme");
if (lSVGElement) {
Expand All @@ -68,8 +74,6 @@ export async function renderTheShizzle(pAST: any, pOptions: INormalizedOptions)
type: pOptions.outputType as any,
});
}
} catch (pError) {
return pError;
} finally {
if (Boolean(browser) && typeof browser.close === "function") {
browser.close();
Expand Down
24 changes: 21 additions & 3 deletions test/actions/render.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,43 @@ import { INormalizedOptions } from "../../src/types";
use(chaiAsPromised);

// tslint:disable-next-line: no-var-requires
const lAST = JSON.stringify(require("./fixtures/simplest.json"));
const lAST = require("./fixtures/simplest.json");

should();

describe("render()", () => {
it("should fail when passed a non-executable executablePath", (pDone) => {
render.renderWithChromeHeadless(
lAST,
{
outputType: "png",
puppeteerOptions: {
executablePath: "non/existing/path/to/chromium",
},
} as INormalizedOptions,
).should.be.rejected.and.notify(pDone);
});

it("coughs up something when passed an ast asked to output svg", (pDone) => {
render.renderTheShizzle(
render.renderWithChromeHeadless(
lAST,
{
outputType: "svg",
puppeteerOptions: {
args: ["--no-sandbox"], // ci server's docker/ linux does not support sandboxing yet
},
} as INormalizedOptions,
).should.be.fulfilled.and.notify(pDone);
});

it("coughs something when passed an ast asked to output png", (pDone) => {
render.renderTheShizzle(
render.renderWithChromeHeadless(
lAST,
{
outputType: "png",
puppeteerOptions: {
args: ["--no-sandbox"], // ci server's docker/ linux does not support sandboxing yet
},
} as INormalizedOptions,
).should.be.fulfilled.and.notify(pDone);
});
Expand Down