-
Notifications
You must be signed in to change notification settings - Fork 65
/
karma.conf.js
145 lines (140 loc) · 4.47 KB
/
karma.conf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// Karma configuration
const credentialsPromise =
require('@aws-sdk/credential-provider-node').defaultProvider()()
const webpack = require('webpack')
module.exports = function (config) {
process.on('infrastructure_error', (error) => {
/* @aws-sdk/karma-credential-loader get credential
* as configured by the AWS SDK.
* These credentials are used to test KMS integration
* with the Encryption SDK.
* If they do not exist, then karma will exit with an `UnhandledRejection`.
* The following will log errors link this,
* but still let the karma-server shut down.
*/
console.error('infrastructure_error', error)
})
config.set({
basePath: '',
frameworks: [ 'mocha', 'chai', 'webpack'],
files: [
'modules/*-browser/build/module/test/*.js',
'modules/material-management/build/module/test/*.js',
'modules/raw-keyring/build/module/test/*.js',
'modules/kms-keyring/build/module/test/*.js',
// 'modules/cache-material/build/module/test/*.js',
'modules/serialize/build/module/test/*.js',
'modules/web-crypto-backend/build/module/test/*.js',
],
preprocessors: {
'modules/**/build/module/test/*.js': ['webpack', 'credentials'],
},
webpack: {
mode: 'development',
module: {
rules: [
{
// yauzl is only used in the node cli for browser integration
test: /yauzl/,
use: 'null-loader',
},
{
test: /\.js/,
// msrcrypto.js is are outside dependances
// and should not be intremented or impact code coverage.
// fixtures.js is a test file, not an entry point
exclude: /(node_modules)|(msrcrypto.js)|(fixtures.js)/,
use: {
loader: "@jsdevtools/coverage-istanbul-loader",
options: {
// produceSourceMap: true
}
}
}
],
},
plugins: [
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
],
stats: {
colors: true,
modules: true,
reasons: true,
errorDetails: true,
},
devtool: 'source-map',
resolve: {
extensions: ['.js'],
fallback: {
fs: false,
crypto: false,
util: false
},
},
},
coverageIstanbulReporter: {
reports: ['json'],
combineBrowserReports: true,
fixWebpackSourcePaths: true,
dir: '.karma_output',
skipFilesWithNoCoverage: true,
// verbose: true,
},
plugins: [
{
'preprocessor:credentials': ['factory', createCredentialPreprocessor],
},
'karma-chrome-launcher',
'karma-mocha',
'karma-chai',
'karma-webpack',
'karma-coverage-istanbul-reporter',
'karma-json-fixtures-preprocessor',
],
reporters: ['progress', 'coverage-istanbul'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: ['ChromeHeadlessDisableCors'],
customLaunchers: {
ChromeHeadlessDisableCors: {
base: 'ChromeHeadless',
flags: ['--disable-web-security', '--no-sandbox'],
},
},
singleRun: true,
concurrency: Infinity,
exclude: ['**/*.d.ts'],
})
}
function createCredentialPreprocessor() {
return async function (content, file, done) {
// strip the extension from the file since it won't match the preprocessor pattern
const fileName = file.originalPath
// add region and credentials to each file
const region = process.env.AWS_SMOKE_TEST_REGION || ''
const credentials = await credentialsPromise
// This will affect the generated (ES5) JS
const regionCode = `var defaultRegion = '${region}';`
const credentialsCode = `var credentials = ${JSON.stringify(credentials)};`
// See: https://github.com/aws/aws-sdk-js-v3/issues/5890
const expirationNeedsToBeDate = `credentials.expiration = new Date(credentials.expiration);`
const isBrowser = `var isBrowser = true;`
const contents = content.split('\n')
let idx = -1
for (let i = 0; i < contents.length; i++) {
const line = contents[i]
if (line.indexOf(fileName) !== -1) {
idx = i
break
}
}
contents.splice(idx + 1, 0, regionCode, credentialsCode, expirationNeedsToBeDate, isBrowser)
done(contents.join('\n'))
}
}