diff --git a/cli/utils/ts-linter.js b/cli/utils/ts-linter.js index c486ecdc..da6f353b 100644 --- a/cli/utils/ts-linter.js +++ b/cli/utils/ts-linter.js @@ -22,18 +22,16 @@ function lintSync() { // Convert buffers to strings. let output = []; - if (spawnResult.output) { - spawnResult.output.forEach((buffer) => { - if (buffer === null) { - return; - } - - const str = buffer.toString().trim(); - if (str) { - output.push(str); - } - }); - } + spawnResult.output.forEach((buffer) => { + if (buffer === null) { + return; + } + + const str = buffer.toString().trim(); + if (str) { + output.push(str); + } + }); // Convert multi-line errors into single errors. let errors = []; diff --git a/config/karma/shared.karma.conf.js b/config/karma/shared.karma.conf.js index a780cbf2..c6556a7c 100644 --- a/config/karma/shared.karma.conf.js +++ b/config/karma/shared.karma.conf.js @@ -42,6 +42,8 @@ function getConfig(config) { const minimist = require('minimist'); const argv = minimist(process.argv.slice(2)); const path = require('path'); + const srcPath = path.join(process.cwd(), 'src'); + let testWebpackConfig = require('../webpack/test.webpack.config'); let remapIstanbul = require('remap-istanbul'); @@ -96,12 +98,17 @@ function getConfig(config) { // trigger the `invalid` event, causing karma to constantly re-rerun // the tests. This is a by-product of using `require.context`. // https://github.com/webpack-contrib/karma-webpack/issues/253#issuecomment-335545430 + // By using require.context in our @skyux/i18n library ALL project files are watched by default. + // The function below ignores all files execpt the `src` directory. webpackMiddleware: { watchOptions: { - ignored: [ - '**/coverage/**', - '**/.skypageslocales/**' - ] + // Returning `true` means the file should be ignored. + // Fat-Arrow functions do not work as chokidar will inspect this method. + ignored: function (item) { + const resolvedPath = path.resolve(item); + const ignore = (resolvedPath.indexOf(srcPath) === -1); + return ignore; + } } }, diff --git a/test/config-karma-shared.spec.js b/test/config-karma-shared.spec.js index f1f50d6e..1836b11d 100644 --- a/test/config-karma-shared.spec.js +++ b/test/config-karma-shared.spec.js @@ -1,6 +1,7 @@ /*jshint jasmine: true, node: true */ 'use strict'; +const path = require('path'); const mock = require('mock-require'); describe('config karma shared', () => { @@ -125,4 +126,31 @@ describe('config karma shared', () => { }); }); + it('should ignore anything outside the src directory in webpackMiddleware', () => { + mock('../config/sky-pages/sky-pages.config.js', { + getSkyPagesConfig: () => ({ + skyux: {} + }) + }); + + mock(testConfigFilename, { + getWebpackConfig: () => {} + }); + + spyOn(path, 'resolve').and.callThrough(); + + mock.reRequire('../config/karma/shared.karma.conf')({ + set: (config) => { + const filter = config.webpackMiddleware.watchOptions.ignored; + expect(filter).toBeDefined(); + + expect(path.resolve).toHaveBeenCalled(); + expect(filter(path.join(process.cwd(), 'src'))).toBe(false); + expect(filter(path.join(process.cwd(), 'node_modules'))).toBe(true); + expect(filter(path.join(process.cwd(), '.skypageslocales'))).toBe(true); + expect(filter(path.join(process.cwd(), 'coverage'))).toBe(true); + } + }); + }); + });