Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Added test + logic to shortcircuit test command #381

Merged
merged 4 commits into from
Mar 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
9 changes: 9 additions & 0 deletions cli/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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;

Expand Down Expand Up @@ -46,6 +50,11 @@ function test(command, argv) {
process.exit(exitCode);
};

if (specsGlob.length === 0) {
logger.info('No spec files located. Skipping test command.');
return onExit(0);
}

const server = new Server(karmaConfig, onExit);
server.on('run_start', onRunStart);
server.on('run_complete', onRunComplete);
Expand Down
2 changes: 1 addition & 1 deletion test/cli-e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down
12 changes: 12 additions & 0 deletions test/cli-test.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,16 @@ describe('cli test', () => {

expect(process.exit).toHaveBeenCalledWith(0);
});

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. Skipping test command.'
);
expect(process.exit).toHaveBeenCalledWith(0);
});
});