Skip to content

Commit 6b21518

Browse files
author
Bobby Earl
authored
Unit test assets (blackbaud#214)
* Updated configuration to point to assets. * Removed leading slash (for Windows) * Added test. * Added test to bring branch coverage to 100% * Fix windows test. * Added comment and adjusted test for Windows.
1 parent d190672 commit 6b21518

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed

config/karma/shared.karma.conf.js

+12
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ function getConfig(config) {
4343
const specStyles = `${__dirname}/../../utils/spec-styles.js`;
4444
const polyfillsBundle = `${__dirname}/../../src/polyfills.ts`;
4545

46+
// Used in conjunction with `proxies` property to remove 404 and correctly serve assets
47+
// Karma normalizes the pattern before glob, so no need to accomodate different OSes.
48+
const assetsPattern = `${srcPath}/assets/**`;
49+
4650
const preprocessors = {};
4751

4852
preprocessors[polyfillsBundle] = ['webpack'];
@@ -67,8 +71,16 @@ function getConfig(config) {
6771
{
6872
pattern: specStyles,
6973
watched: false
74+
},
75+
{
76+
pattern: assetsPattern,
77+
included: false,
78+
served: true,
7079
}
7180
],
81+
proxies: {
82+
'/~/': `/absolute${srcPath}`
83+
},
7284
preprocessors: preprocessors,
7385
skyPagesConfig: skyPagesConfig,
7486
webpack: testWebpackConfig.getWebpackConfig(skyPagesConfig, argv),

test/config-karma-shared.spec.js

+17
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,23 @@ describe('config karma shared', () => {
6767
});
6868
});
6969

70+
it('should serve and proxy assets', (done) => {
71+
const cwd = 'custom-cwd';
72+
spyOn(process, 'cwd').and.returnValue(cwd);
73+
74+
mock.reRequire('../config/karma/shared.karma.conf')({
75+
set: (config) => {
76+
expect(config.files.pop()).toEqual({
77+
pattern: path.join(cwd, 'src') + '/assets/**',
78+
included: false,
79+
served: true
80+
});
81+
expect(config.proxies['/~/']).toContain(`/absolute${cwd}`);
82+
done();
83+
}
84+
});
85+
});
86+
7087
it('should ignore anything outside the src directory in webpackMiddleware', (done) => {
7188
mock('../config/sky-pages/sky-pages.config.js', {
7289
getSkyPagesConfig: () => ({

test/config-karma-test.spec.js

+23-6
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('config karma test', () => {
2323
});
2424

2525
it('should load the shared config', (done) => {
26-
require('../config/karma/test.karma.conf')({
26+
mock.reRequire('../config/karma/test.karma.conf')({
2727
set: (config) => {
2828
expect(config.browsers).toBeDefined();
2929
expect(called).toEqual(true);
@@ -34,7 +34,7 @@ describe('config karma test', () => {
3434

3535
it('should use a custom launcher for Travis', (done) => {
3636
process.env.TRAVIS = true;
37-
require('../config/karma/test.karma.conf')({
37+
mock.reRequire('../config/karma/test.karma.conf')({
3838
set: (config) => {
3939
expect(config.browsers[0]).toBe('Chrome_travis_ci');
4040
delete process.env.TRAVIS;
@@ -48,33 +48,50 @@ describe('config karma test', () => {
4848
headless: true
4949
};
5050

51-
require('../config/karma/test.karma.conf')({
51+
mock.reRequire('../config/karma/test.karma.conf')({
5252
set: (config) => {
5353
expect(config.browsers[0]).toBe('ChromeHeadless');
5454
done();
5555
}
5656
});
5757
});
5858

59-
it('should include the desktop notifications reporter if --enableDesktopNotifications flag set', (done) => {
59+
it('should include the desktop notifications reporter if --enableDesktopNotifications flag set without other reporters', (done) => {
6060
mockArgv = {
6161
enableDesktopNotifications: true
6262
};
6363

64-
require('../config/karma/test.karma.conf')({
64+
mock.reRequire('../config/karma/test.karma.conf')({
6565
set: (config) => {
6666
expect(config.reporters).toContain('notify');
6767
done();
6868
}
6969
});
7070
});
7171

72+
it('should include the desktop notifications reporter if --enableDesktopNotifications flag set with other reporters', (done) => {
73+
mockArgv = {
74+
enableDesktopNotifications: true
75+
};
76+
77+
mock(path, (config) => {
78+
config.reporters = ['custom'];
79+
});
80+
81+
mock.reRequire('../config/karma/test.karma.conf')({
82+
set: (config) => {
83+
expect(config.reporters).toEqual(['custom', 'notify']);
84+
done();
85+
}
86+
});
87+
});
88+
7289
it('should configure the mochaReporter to ignoreSkipped if --suppressUnfocusedTestOutput flag set', (done) => {
7390
mockArgv = {
7491
suppressUnfocusedTestOutput: true
7592
};
7693

77-
require('../config/karma/test.karma.conf')({
94+
mock.reRequire('../config/karma/test.karma.conf')({
7895
set: (config) => {
7996
expect(config.mochaReporter).toEqual({ ignoreSkipped: true });
8097
done();

0 commit comments

Comments
 (0)