|
3 | 3 |
|
4 | 4 | // Karma configuration
|
5 | 5 | const { readFileSync } = require('fs')
|
| 6 | +const credentialsPromise = |
| 7 | + require('@aws-sdk/credential-provider-node').defaultProvider()() |
6 | 8 | const webpack = require('webpack')
|
7 | 9 |
|
8 | 10 | module.exports = function (config) {
|
@@ -66,8 +68,10 @@ module.exports = function (config) {
|
66 | 68 | },
|
67 | 69 | },
|
68 | 70 | plugins: [
|
| 71 | + { |
| 72 | + 'preprocessor:credentials': ['factory', createCredentialPreprocessor], |
| 73 | + }, |
69 | 74 | 'karma-parallel',
|
70 |
| - '@aws-sdk/karma-credential-loader', |
71 | 75 | 'karma-webpack',
|
72 | 76 | 'karma-json-fixtures-preprocessor',
|
73 | 77 | 'karma-chrome-launcher',
|
@@ -99,3 +103,30 @@ module.exports = function (config) {
|
99 | 103 | },
|
100 | 104 | })
|
101 | 105 | }
|
| 106 | + |
| 107 | +function createCredentialPreprocessor() { |
| 108 | + return async function (content, file, done) { |
| 109 | + // strip the extension from the file since it won't match the preprocessor pattern |
| 110 | + const fileName = file.originalPath |
| 111 | + // add region and credentials to each file |
| 112 | + const region = process.env.AWS_SMOKE_TEST_REGION || '' |
| 113 | + const credentials = await credentialsPromise |
| 114 | + // This will affect the generated (ES5) JS |
| 115 | + const regionCode = `var defaultRegion = '${region}';` |
| 116 | + const credentialsCode = `var credentials = ${JSON.stringify(credentials)};` |
| 117 | + // See: https://github.com/aws/aws-sdk-js-v3/issues/5890 |
| 118 | + const expirationNeedsToBeDate = `credentials.expiration = new Date(credentials.expiration);` |
| 119 | + const isBrowser = `var isBrowser = true;` |
| 120 | + const contents = content.split('\n') |
| 121 | + let idx = -1 |
| 122 | + for (let i = 0; i < contents.length; i++) { |
| 123 | + const line = contents[i] |
| 124 | + if (line.indexOf(fileName) !== -1) { |
| 125 | + idx = i |
| 126 | + break |
| 127 | + } |
| 128 | + } |
| 129 | + contents.splice(idx + 1, 0, regionCode, credentialsCode, expirationNeedsToBeDate, isBrowser) |
| 130 | + done(contents.join('\n')) |
| 131 | + } |
| 132 | +} |
0 commit comments