|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright 2019 Google LLC. All Rights Reserved. |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * ============================================================================= |
| 16 | + */ |
| 17 | + |
| 18 | +const karmaTypescriptConfig = { |
| 19 | + tsconfig: 'tsconfig.json', |
| 20 | + compilerOptions: {allowJs: true, declaration: false}, |
| 21 | + bundlerOptions: { |
| 22 | + sourceMap: true, |
| 23 | + // Ignore the import of the `worker_threads` package used in a core test |
| 24 | + // meant to run in node. |
| 25 | + exclude: ['worker_threads'] |
| 26 | + }, |
| 27 | + // Disable coverage reports and instrumentation by default for tests |
| 28 | + coverageOptions: {instrumentation: false}, |
| 29 | + reports: {}, |
| 30 | + include: ['src/', 'wasm-out/'] |
| 31 | +}; |
| 32 | + |
| 33 | +module.exports = function(config) { |
| 34 | + const args = []; |
| 35 | + if (config.grep) { |
| 36 | + args.push('--grep', config.grep); |
| 37 | + } |
| 38 | + if (config.flags) { |
| 39 | + args.push('--flags', config.flags); |
| 40 | + } |
| 41 | + config.set({ |
| 42 | + basePath: '', |
| 43 | + frameworks: ['jasmine', 'karma-typescript'], |
| 44 | + files: [ |
| 45 | + // Setup the environment for the tests. |
| 46 | + 'src/setup_test.ts', |
| 47 | + // Serve the wasm file as a static resource. |
| 48 | + {pattern: 'wasm-out/**/*.wasm', included: false}, |
| 49 | + // Import the generated js library from emscripten. |
| 50 | + {pattern: 'wasm-out/**/*.js'}, |
| 51 | + // Import the rest of the sources. |
| 52 | + {pattern: 'src/**/*.ts'}, |
| 53 | + ], |
| 54 | + preprocessors: { |
| 55 | + 'wasm-out/**/*.js': ['karma-typescript'], |
| 56 | + '**/*.ts': ['karma-typescript'] |
| 57 | + }, |
| 58 | + karmaTypescriptConfig, |
| 59 | + // Redirect the request for the wasm file so karma can find it. |
| 60 | + proxies: { |
| 61 | + '/base/node_modules/karma-typescript/dist/client/tfjs-backend-wasm.wasm': |
| 62 | + '/base/wasm-out/tfjs-backend-wasm.wasm', |
| 63 | + }, |
| 64 | + reporters: ['progress', 'karma-typescript'], |
| 65 | + port: 9876, |
| 66 | + colors: true, |
| 67 | + autoWatch: true, |
| 68 | + browsers: ['Chrome'], |
| 69 | + singleRun: false, |
| 70 | + client: {jasmine: {random: false}, args: args} |
| 71 | + }) |
| 72 | +} |
0 commit comments