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

Take a screenshot on each failed expect #154

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
add tests for css inline option
  • Loading branch information
miller45 committed Jun 6, 2019
commit 0671c3978f0b16a90319afaaadf154f6b30909a5
63 changes: 63 additions & 0 deletions tests/reporter/util_metadata_test.js
Original file line number Diff line number Diff line change
@@ -850,6 +850,69 @@ describe('unit tests', () => {
const jsContentsWoLF = jsContents.replace(/\r\n/g, "").replace(/\n/g, "");
expect(jsContentsWoLF).toEqual(' var clientDefaults = { "searchSettings": {}, "columnSettings": {}}; ');
});

it('adds customCssInline if configured so', () => {
const htmlTemplate = '<!-- Here will be CSS placed -->';
const errorMsg = "mock case not expected: ";
const fakePath = "./not/existing/path/" + util.generateGuid() + "/subdir";

//region mocks

// for addMetaData
spyOn(fse, "ensureFileSync").and.stub();
spyOn(fs, "rmdirSync").and.stub();
spyOn(fs, "mkdirSync").and.stub();
spyOn(fse, "readJsonSync").and.callFake(() => {
return "[]";
});
spyOn(fse, "outputJsonSync").and.stub();

spyOn(fse, 'pathExistsSync').and.callFake((fpath) => {
if (fpath.endsWith("combined.json")) {
return true;
}
throw new Error(errorMsg + fpath);
});

// for addHTMLReport
spyOn(fse, 'copySync').and.stub();
spyOn(fs, 'readFileSync').and.callFake(() => {
return Buffer.from(htmlTemplate);
});

let htmlContents;
spyOn(fs, 'createWriteStream').and.callFake((wfile) => {
if (wfile.endsWith(".html")) {
return {
write: function (txt) {
htmlContents = txt;
},
end: jasmine.createSpy('end')
};
}
return {
write: jasmine.createSpy('write'),
end: jasmine.createSpy('end')
};

});

// misc
spyOn(console, 'error').and.stub();
//end region mocks

const metaData = {};
const options = {
docName: "report.html",
sortFunction: defaultSortFunction,
customCssInline: ".myspecial-custom-class { font-face: bold; }",
prepareAssets: true
};
util.addMetaData(metaData, fakePath, options);

expect(console.error).not.toHaveBeenCalled();
expect(htmlContents).toEqual('<link rel="stylesheet" href="assets/bootstrap.css"> <style type="text/css">.myspecial-custom-class { font-face: bold; }</style>');
});
});

});