Skip to content

Commit

Permalink
Add CSP headers to the karma run
Browse files Browse the repository at this point in the history
  • Loading branch information
rajsite committed Mar 3, 2024
1 parent 30e4d6a commit 5130e6c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 4 deletions.
12 changes: 11 additions & 1 deletion angular-workspace/projects/example-client-app/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ module.exports = function (config) {
autoWatch: true,
browsers: ['ChromeHeadless'],
singleRun: false,
restartOnFileChange: true
restartOnFileChange: true,
customHeaders: [
// Add a Content-Security-Policy header for the tests
// Following: https://developer.chrome.com/docs/extensions/reference/manifest/content-security-policy
// Need 'unsafe-inline' to support karma behavior: https://github.com/karma-runner/karma/issues/3260
{
match: '\\.html',
name: 'Content-Security-Policy',
value: "script-src 'self' 'unsafe-inline'; object-src 'self';"
}
]
});
};
12 changes: 11 additions & 1 deletion angular-workspace/projects/ni/nimble-angular/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ module.exports = config => {
autoWatch: true,
browsers: ['ChromeHeadless'],
singleRun: false,
restartOnFileChange: true
restartOnFileChange: true,
customHeaders: [
// Add a Content-Security-Policy header for the tests
// Following: https://developer.chrome.com/docs/extensions/reference/manifest/content-security-policy
// Need 'unsafe-inline' to support karma behavior: https://github.com/karma-runner/karma/issues/3260
{
match: '\\.html',
name: 'Content-Security-Policy',
value: "script-src 'self' 'unsafe-inline'; object-src 'self';"
}
]
});
};
12 changes: 11 additions & 1 deletion packages/jasmine-parameterized/karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,17 @@ module.exports = config => {
captureConsole: true
},
// to disable the WARN 404 for image requests
logLevel: config.LOG_ERROR
logLevel: config.LOG_ERROR,
customHeaders: [
// Add a Content-Security-Policy header for the tests
// Following: https://developer.chrome.com/docs/extensions/reference/manifest/content-security-policy
// Need 'unsafe-inline' to support karma behavior: https://github.com/karma-runner/karma/issues/3260
{
match: '\\.html',
name: 'Content-Security-Policy',
value: "script-src 'self' 'unsafe-inline'; object-src 'self';"
}
]
};

config.set(options);
Expand Down
12 changes: 11 additions & 1 deletion packages/nimble-components/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,17 @@ module.exports = config => {
},
captureConsole: true
},
logLevel: config.LOG_ERROR // to disable the WARN 404 for image requests
logLevel: config.LOG_ERROR, // to disable the WARN 404 for image requests
customHeaders: [
// Add a Content-Security-Policy header for the tests
// Following: https://developer.chrome.com/docs/extensions/reference/manifest/content-security-policy
// Need 'unsafe-inline' to support karma behavior: https://github.com/karma-runner/karma/issues/3260
{
match: '\\.html',
name: 'Content-Security-Policy',
value: "script-src 'self' 'unsafe-inline'; object-src 'self';"
}
]
};

config.set(options);
Expand Down

0 comments on commit 5130e6c

Please sign in to comment.