diff --git a/test/job.js b/test/job.js index bb7802b..57573df 100644 --- a/test/job.js +++ b/test/job.js @@ -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'); +}); + diff --git a/test/mock/tasks/fail-task.js b/test/mock/tasks/fail-task.js index 3c069d4..27c4345 100644 --- a/test/mock/tasks/fail-task.js +++ b/test/mock/tasks/fail-task.js @@ -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); } } diff --git a/test/mock/tasks/task.js b/test/mock/tasks/task.js index bd0ce5d..26aee07 100644 --- a/test/mock/tasks/task.js +++ b/test/mock/tasks/task.js @@ -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 }; } }