From 5a5cc924cf2b248a3ec964399c208a20e0fde6c7 Mon Sep 17 00:00:00 2001 From: Nicolas Martinez <17040442+nicomt@users.noreply.github.com> Date: Sun, 11 Oct 2020 18:10:20 -0400 Subject: [PATCH] Adding test for strip ansi before notify --- test/job.js | 14 ++++++++++++++ test/mock/tasks/fail-task.js | 5 +++-- test/mock/tasks/task.js | 5 +++-- 3 files changed, 20 insertions(+), 4 deletions(-) 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 }; } }