Skip to content

Commit

Permalink
Adding test for strip ansi before notify
Browse files Browse the repository at this point in the history
  • Loading branch information
nicomt committed Oct 11, 2020
1 parent 7204a82 commit 5a5cc92
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
14 changes: 14 additions & 0 deletions test/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,19 @@ test('job: failure notifier', async (t) => {
t.is(notifier1.notifyBody, 'expected fail');
});

test('job: strip ansi before notify', async (t) => {
const task1 = new MockFailTask('task1', '\u001b[31mtest\u001b[39m');
const notifier1 = new MockNotifier('notifier1');
const job = new Job('test', {
schedule: '* * * * *',
tasks: ['task1'],
on_error: ['notifier1']
}, { task1 }, { notifier1 });

const success = await job.run();
t.assert(!success);
t.is(notifier1.notifyBody, 'test');
});



5 changes: 3 additions & 2 deletions test/mock/tasks/fail-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
/* eslint-disable no-unused-vars */

class MockFailTask {
constructor(name) {
constructor(name, message = 'expected fail') {
this.name = name;
this.message = message;
this.executionTimes = 0;
}

async execute(log) {
this.executionTimes++;
throw new Error('expected fail');
throw new Error(this.message);
}
}

Expand Down
5 changes: 3 additions & 2 deletions test/mock/tasks/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
/* eslint-disable no-unused-vars */

class MockTask {
constructor(name) {
constructor(name, output = 'success') {
this.name = name;
this.output = output;
this.executionTimes = 0;
}

async execute(log) {
this.executionTimes++;
return { name: this.name, output: 'success' };
return { name: this.name, output: this.output };
}
}

Expand Down

0 comments on commit 5a5cc92

Please # to comment.