All files / builder/karma index.ts

40% Statements 8/20
100% Branches 0/0
0% Functions 0/5
40% Lines 8/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 901x         1x 1x 1x 1x         1x   1x                         1x                                                                                                                          
import { BuilderContext, createBuilder } from '@angular-devkit/architect';
import {
  AssetPattern,
  KarmaBuilderOptions,
} from '@angular-devkit/build-angular';
import { Injector } from 'static-injector';
import * as webpack from 'webpack';
import { WebpackConfigurationChangeService } from '../application/webpack-configuration-change.service';
import {
  BuildPlatform,
  PlatformType,
  getBuildPlatformInjectConfig,
} from '../platform';
import { execute } from './index.origin';
 
export default createBuilder(
  (
    angularOptions: KarmaBuilderOptions & {
      pages: AssetPattern[];
      components: AssetPattern[];
      platform: PlatformType;
    },
    context: BuilderContext
  ): ReturnType<typeof execute> => {
    return runBuilder(angularOptions, context);
  }
);
 
export function runBuilder(
  angularOptions: KarmaBuilderOptions & {
    pages: AssetPattern[];
    components: AssetPattern[];
    platform: PlatformType;
  },
  context: BuilderContext
): ReturnType<typeof execute> {
  return execute(angularOptions, context, {
    webpackConfiguration: async (options: webpack.Configuration) => {
      const injector = Injector.create({
        providers: [
          ...getBuildPlatformInjectConfig(PlatformType.wx),
          {
            provide: WebpackConfigurationChangeService,
            useFactory: (injector: Injector) => {
              return new WebpackConfigurationChangeService(
                angularOptions,
                context,
                options,
                injector
              );
            },
            deps: [Injector],
          },
        ],
      });
      const config = injector.get(WebpackConfigurationChangeService);
      config.init();
      await config.change();
      const buildPlatform = injector.get(BuildPlatform);
      options.plugins!.push(
        new webpack.DefinePlugin({
          describe: `${buildPlatform.globalVariablePrefix}.describe`,
          xdescribe: `${buildPlatform.globalVariablePrefix}.xdescribe`,
          fdescribe: `${buildPlatform.globalVariablePrefix}.fdescribe`,
          it: `${buildPlatform.globalVariablePrefix}.it`,
          xit: `${buildPlatform.globalVariablePrefix}.xit`,
          fit: `${buildPlatform.globalVariablePrefix}.fit`,
          beforeEach: `${buildPlatform.globalVariablePrefix}.beforeEach`,
          afterEach: `${buildPlatform.globalVariablePrefix}.afterEach`,
          beforeAll: `${buildPlatform.globalVariablePrefix}.beforeAll`,
          afterAll: `${buildPlatform.globalVariablePrefix}.afterAll`,
          setSpecProperty: `${buildPlatform.globalVariablePrefix}.setSpecProperty`,
          setSuiteProperty: `${buildPlatform.globalVariablePrefix}.setSuiteProperty`,
          expect: `${buildPlatform.globalVariablePrefix}.expect`,
          expectAsync: `${buildPlatform.globalVariablePrefix}.expectAsync`,
          pending: `${buildPlatform.globalVariablePrefix}.pending`,
          fail: `${buildPlatform.globalVariablePrefix}.fail`,
          spyOn: `${buildPlatform.globalVariablePrefix}.spyOn`,
          spyOnProperty: `${buildPlatform.globalVariablePrefix}.spyOnProperty`,
          spyOnAllFunctions: `${buildPlatform.globalVariablePrefix}.spyOnAllFunctions`,
          jsApiReporter: `${buildPlatform.globalVariablePrefix}.jsApiReporter`,
          jasmine: `${buildPlatform.globalVariablePrefix}.jasmine`,
        })
      );
      options.output!.path += '/dist';
      return options;
    },
  });
}