From 8db815eb88b2775203aac741bfb73531cf99eaa3 Mon Sep 17 00:00:00 2001 From: Bobby Earl Date: Tue, 27 Mar 2018 19:01:11 -0400 Subject: [PATCH 1/2] Added test + logic to shortcircuit test command --- cli/test.js | 9 +++++++++ test/cli-test.spec.js | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/cli/test.js b/cli/test.js index a23f6e0e..d5848424 100644 --- a/cli/test.js +++ b/cli/test.js @@ -8,6 +8,8 @@ function test(command, argv) { const logger = require('@blackbaud/skyux-logger'); const Server = require('karma').Server; + const path = require('path'); + const glob = require('glob'); const tsLinter = require('./utils/ts-linter'); const configResolver = require('./utils/config-resolver'); @@ -17,6 +19,8 @@ function test(command, argv) { const karmaConfigUtil = require('karma').config; const karmaConfigPath = configResolver.resolve(command, argv); const karmaConfig = karmaConfigUtil.parseConfig(karmaConfigPath); + const specsPath = path.resolve(process.cwd(), 'src/app/**/*.spec.ts'); + const specsGlob = glob.sync(specsPath); let lintResult; @@ -46,6 +50,11 @@ function test(command, argv) { process.exit(exitCode); }; + if (specsGlob.length === 0) { + logger.info('No spec files located. Stopping command from running.'); + return onExit(0); + } + const server = new Server(karmaConfig, onExit); server.on('run_start', onRunStart); server.on('run_complete', onRunComplete); diff --git a/test/cli-test.spec.js b/test/cli-test.spec.js index 545243f5..ed965127 100644 --- a/test/cli-test.spec.js +++ b/test/cli-test.spec.js @@ -227,4 +227,16 @@ describe('cli test', () => { expect(process.exit).toHaveBeenCalledWith(0); }); + + it('should not continue if no e2e spec files exist', () => { + mock('glob', { + sync: path => [] + }); + + mock.reRequire('../cli/test')('test'); + expect(logger.info).toHaveBeenCalledWith( + 'No spec files located. Stopping command from running.' + ); + expect(process.exit).toHaveBeenCalledWith(0); + }); }); From d4747a20906db60147e719c126895abe281c07ce Mon Sep 17 00:00:00 2001 From: Bobby Earl Date: Thu, 29 Mar 2018 15:54:09 -0400 Subject: [PATCH 2/2] Incorporated feedback --- cli/e2e.js | 2 +- cli/test.js | 2 +- test/cli-e2e.spec.js | 2 +- test/cli-test.spec.js | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cli/e2e.js b/cli/e2e.js index 7b9f8151..6cd4fa8e 100644 --- a/cli/e2e.js +++ b/cli/e2e.js @@ -160,7 +160,7 @@ function e2e(command, argv, skyPagesConfig, webpack) { const configPath = configResolver.resolve(command, argv); if (specsGlob.length === 0) { - logger.info('No spec files located. Stopping command from running.'); + logger.info('No spec files located. Skipping e2e command.'); return killServers(0); } diff --git a/cli/test.js b/cli/test.js index d5848424..ebe7ea71 100644 --- a/cli/test.js +++ b/cli/test.js @@ -51,7 +51,7 @@ function test(command, argv) { }; if (specsGlob.length === 0) { - logger.info('No spec files located. Stopping command from running.'); + logger.info('No spec files located. Skipping test command.'); return onExit(0); } diff --git a/test/cli-e2e.spec.js b/test/cli-e2e.spec.js index 922032f3..2cb5074b 100644 --- a/test/cli-e2e.spec.js +++ b/test/cli-e2e.spec.js @@ -214,7 +214,7 @@ describe('cli e2e', () => { spyOn(process, 'exit').and.callFake(exitCode => { expect(exitCode).toEqual(0); - expect(logger.info).toHaveBeenCalledWith('No spec files located. Stopping command from running.'); + expect(logger.info).toHaveBeenCalledWith('No spec files located. Skipping e2e command.'); done(); }); diff --git a/test/cli-test.spec.js b/test/cli-test.spec.js index ed965127..84da67e9 100644 --- a/test/cli-test.spec.js +++ b/test/cli-test.spec.js @@ -228,14 +228,14 @@ describe('cli test', () => { expect(process.exit).toHaveBeenCalledWith(0); }); - it('should not continue if no e2e spec files exist', () => { + it('should not continue if no test spec files exist', () => { mock('glob', { sync: path => [] }); mock.reRequire('../cli/test')('test'); expect(logger.info).toHaveBeenCalledWith( - 'No spec files located. Stopping command from running.' + 'No spec files located. Skipping test command.' ); expect(process.exit).toHaveBeenCalledWith(0); });