From 592e3101f0055a23daeb67c45ed7f69f8b3b21c7 Mon Sep 17 00:00:00 2001 From: Carlos Date: Sat, 4 Nov 2017 04:09:26 +0000 Subject: [PATCH] refactor: use path to generate the suite msg --- src/TapReporter.js | 7 +++---- test/TapReporter.spec.js | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/TapReporter.js b/src/TapReporter.js index dccb96f..f484478 100755 --- a/src/TapReporter.js +++ b/src/TapReporter.js @@ -1,4 +1,5 @@ /* eslint-disable id-match, class-methods-use-this, no-console */ +const path = require('path'); const chalk = require('chalk'); const ms = require('ms'); const Logger = require('./helpers/Logger'); @@ -22,11 +23,9 @@ class TapReporter { const {testResults, testFilePath} = suite; if (testFilePath) { - const filePathParts = testFilePath.split('/'); - const filePath = filePathParts.slice(0, filePathParts.length - 2).join('/'); - const fileName = filePathParts[filePathParts.length - 1]; + const {dir, base} = path.parse(testFilePath); - this.logger.info(`\n${chalk.grey('#')}${chalk.bgBlue(' SUITE ')} ${chalk.grey(`${filePath}/`)}${fileName}`); + this.logger.info(`\n${chalk.grey('#')}${chalk.bgBlue(' SUITE ')} ${chalk.grey(`${dir}${path.sep}`)}${base}`); } testResults.forEach((test) => { diff --git a/test/TapReporter.spec.js b/test/TapReporter.spec.js index 585eab2..b771eda 100644 --- a/test/TapReporter.spec.js +++ b/test/TapReporter.spec.js @@ -151,7 +151,7 @@ test('TapReporter must output a Suite log with the Suites filePath if possible', tapReporter.onTestResult({}, passingTestSuite); - expect(console.log.mock.calls[0][0]).toBe('\n# SUITE /Users/carlospastor/dev/mailonline/TapReporter.spec.js'); + expect(console.log.mock.calls[0][0]).toBe('\n# SUITE /Users/carlospastor/dev/mailonline/jest-tap-reporter/TapReporter.spec.js'); tapReporter = new TapReporter(); console.log.mockClear();