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

Using different technique to ignore changes. #492

Merged
merged 10 commits into from
Oct 31, 2018
22 changes: 10 additions & 12 deletions cli/utils/ts-linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarification, this was incorrectly added in a previous PR due to a misconfigured unit test.

if (buffer === null) {
return;
}

const str = buffer.toString().trim();
if (str) {
output.push(str);
}
});

// Convert multi-line errors into single errors.
let errors = [];
Expand Down
15 changes: 11 additions & 4 deletions config/karma/shared.karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to resolve the path because Webpack will provide both of these values:

C:\Users\stevebr\Projects\github\blackbaud\skyux-i18n\src\app\app-extras.module.ts
C:/Users/stevebr/Projects/github/blackbaud/skyux-i18n/src/app/app-extras.module.ts

const ignore = (resolvedPath.indexOf(srcPath) === -1);
return ignore;
}
}
},

Expand Down
24 changes: 24 additions & 0 deletions test/config-karma-shared.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*jshint jasmine: true, node: true */
'use strict';

const path = require('path');
const mock = require('mock-require');

describe('config karma shared', () => {
Expand Down Expand Up @@ -125,4 +126,27 @@ 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: () => {}
});

mock.reRequire('../config/karma/shared.karma.conf')({
set: (config) => {
const filter = config.webpackMiddleware.watchOptions.ignored;
expect(filter).toBeDefined();
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);
}
});
});

});