Skip to content
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
4 changes: 2 additions & 2 deletions src/reporters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ function getReporterDefinition(rawReporter, parser) {
return { type: null, path: null };
}

const { type, path } = parser(rawReporter);
const { type, path, append } = parser(rawReporter);

if (!type) {
const strRawReporter = typeof rawReporter !== "string" ? JSON.stringify(rawReporter) : rawReporter;
throw new Error(`Failed to find required "type" field in reporter definition: "${strRawReporter}"`);
}

return { type, path };
return { type, path, append };
}

function validateReporter(Reporter) {
Expand Down
2 changes: 1 addition & 1 deletion src/reporters/informers/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = class FileInformer extends BaseInformer {
constructor(opts) {
super(opts);

this._fileStream = fs.createWriteStream(opts.path);
this._fileStream = fs.createWriteStream(opts.path, { flags: opts.append === true ? "a" : "w" });
this._reporterType = opts.type;

logger.log(`Information with test results for report: "${opts.type}" will be saved to a file: "${opts.path}"`);
Expand Down
4 changes: 2 additions & 2 deletions test/src/reporters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('"initReporters" method', () => {

it("should create reporter with correct args", async () => {
sinon.spy(Reporter, "create");
const jsonReporter = JSON.stringify({ type: "reporter", path: "./foo/bar.txt" });
const jsonReporter = JSON.stringify({ type: "reporter", path: "./foo/bar.txt", append: true });

await initReporters([jsonReporter], runner);

Expand Down Expand Up @@ -121,7 +121,7 @@ describe('"initReporters" method', () => {

it("should create reporter with correct args", async () => {
sinon.spy(Reporter, "create");
const objReporter = { type: "reporter", path: "./foo/bar.txt" };
const objReporter = { type: "reporter", path: "./foo/bar.txt", append: true };

await initReporters([objReporter], runner);

Expand Down
10 changes: 8 additions & 2 deletions test/src/reporters/informers/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ describe("reporter/informers/file", () => {

afterEach(() => sandbox.restore());

it("should create write stream to passed file path", () => {
it("should overwrite the file by default", () => {
FileInformer.create({ path: "./some-path/file.txt" });

assert.calledOnceWith(fs.createWriteStream, "./some-path/file.txt");
assert.calledOnceWith(fs.createWriteStream, "./some-path/file.txt", { flags: "w" });
});

it("should append to the file when requested", () => {
FileInformer.create({ path: "./some-path/file.txt", append: true });

assert.calledOnceWith(fs.createWriteStream, "./some-path/file.txt", { flags: "a" });
});

it("should inform user that test results will be saved to a file", () => {
Expand Down
Loading