Stone, Avi (as206k) | 9b2ceb3 | 2018-04-12 16:36:39 +0300 | [diff] [blame] | 1 | var wallabyWebpack = require('wallaby-webpack'); |
| 2 | var path = require('path'); |
| 3 | |
| 4 | var compilerOptions = Object.assign( |
| 5 | require('./tsconfig.json').compilerOptions, |
| 6 | require('./src/tsconfig.spec.json').compilerOptions |
| 7 | ); |
| 8 | |
| 9 | compilerOptions.module = 'CommonJs'; |
| 10 | |
| 11 | module.exports = function(wallaby) { |
| 12 | var webpackPostprocessor = wallabyWebpack({ |
| 13 | entryPatterns: ['src/wallabyTest.js', 'src/**/*spec.js'], |
| 14 | |
| 15 | module: { |
| 16 | rules: [ |
| 17 | { test: /\.css$/, loader: ['raw-loader', 'css-loader'] }, |
| 18 | { test: /\.html$/, loader: 'raw-loader' }, |
| 19 | { |
| 20 | test: /\.ts$/, |
| 21 | loader: '@ngtools/webpack', |
| 22 | include: /node_modules/, |
| 23 | query: { tsConfigPath: 'tsconfig.json' } |
| 24 | }, |
| 25 | { |
| 26 | test: /\.js$/, |
| 27 | loader: 'angular2-template-loader', |
| 28 | exclude: /node_modules/ |
| 29 | }, |
| 30 | { test: /\.json$/, loader: 'json-loader' }, |
| 31 | { test: /\.styl$/, loaders: ['raw-loader', 'stylus-loader'] }, |
| 32 | { test: /\.less$/, loaders: ['raw-loader', 'less-loader'] }, |
| 33 | { test: /\.scss$|\.sass$/, loaders: ['raw-loader', 'sass-loader'] }, |
| 34 | { test: /\.(jpg|png)$/, loader: 'url-loader?limit=128000' } |
| 35 | ] |
| 36 | }, |
| 37 | |
| 38 | resolve: { |
| 39 | extensions: ['.js', '.ts'], |
| 40 | modules: [ |
| 41 | path.join(wallaby.projectCacheDir, 'src/app'), |
| 42 | path.join(wallaby.projectCacheDir, 'src'), |
| 43 | 'node_modules' |
| 44 | ] |
| 45 | }, |
| 46 | node: { |
| 47 | fs: 'empty', |
| 48 | net: 'empty', |
| 49 | tls: 'empty', |
| 50 | dns: 'empty' |
| 51 | } |
| 52 | }); |
| 53 | |
| 54 | return { |
| 55 | files: [ |
| 56 | 'src/setupJest.ts', |
| 57 | 'src/**/*.ts', |
| 58 | '!src/**/*.spec.ts', |
| 59 | '!src/**/*.d.ts', |
| 60 | 'src/**/*.json' |
| 61 | ], |
| 62 | |
| 63 | tests: ['src/**/*.spec.ts'], |
| 64 | |
| 65 | testFramework: 'jest', |
| 66 | |
| 67 | compilers: { |
| 68 | '**/*.ts': wallaby.compilers.typeScript(compilerOptions) |
| 69 | }, |
| 70 | |
| 71 | env: { |
| 72 | type: 'node', |
| 73 | runner: 'node', |
| 74 | kind: 'chrome' |
| 75 | }, |
| 76 | |
| 77 | setup: function(wallaby) { |
| 78 | //Use the configured jest file for testing |
| 79 | const jestConfig = { |
| 80 | mapCoverage: true, |
| 81 | globals: { |
| 82 | __TS_CONFIG__: { |
| 83 | target: 'es6', |
| 84 | module: 'commonjs', |
| 85 | moduleResolution: 'node' |
| 86 | }, |
| 87 | 'ts-jest': { |
| 88 | tsConfigFile: 'src/tsconfig.spec.json' |
| 89 | }, |
| 90 | __TRANSFORM_HTML__: true |
| 91 | }, |
| 92 | testRegex: '(/__tests__/.*|\\.(test|spec))\\.(ts|js)$', |
| 93 | setupTestFrameworkScriptFile: '<rootDir>/src/setupJest.ts', |
| 94 | transform: { |
| 95 | '^.+\\.(ts|html)$': |
| 96 | '<rootDir>/node_modules/jest-preset-angular/preprocessor.js' |
| 97 | }, |
| 98 | transformIgnorePatterns: ['node_modules/(?!@ngrx)'], |
| 99 | collectCoverageFrom: [ |
| 100 | 'src/app/module/**/*.{ts}', |
| 101 | '!src/app/*.{ts}', |
| 102 | '!src/app/**/*.{js}', |
| 103 | '!src/app/environment/*.{ts}', |
| 104 | '!src/app/language/*.{ts}', |
| 105 | '!src/app/**/*.module.{ts}', |
| 106 | '!src/app/**/*.interface.{ts}', |
| 107 | '!src/app/**/*.state.{ts}', |
| 108 | '!src/app/**/*.entity.{ts}' |
| 109 | ], |
| 110 | moduleFileExtensions: ['ts', 'tsx', 'js', 'json'], |
| 111 | testPathIgnorePatterns: ['/node_modules/', '/dist/', 'src/app/*.{js}'], |
| 112 | testResultsProcessor: 'jest-sonar-reporter', |
| 113 | moduleNameMapper: { |
| 114 | 'app/(.*)': '<rootDir>/src/app/$1', |
| 115 | '@common/(.*)': '<rootDir>/src/app/common/$1' |
| 116 | } |
| 117 | }; |
| 118 | wallaby.testFramework.configure(jestConfig); |
| 119 | }, |
| 120 | |
| 121 | debug: true |
| 122 | }; |
| 123 | }; |