UNPKG

4.44 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var bundle = require("./bundle");
4var webpack = require("./webpack");
5var Constants = require("./util/constants");
6describe('bundle task', function () {
7 describe('bundle', function () {
8 it('should return the value webpack task returns', function () {
9 // arrange
10 spyOn(webpack, webpack.webpack.name).and.returnValue(Promise.resolve());
11 var context = { bundler: Constants.BUNDLER_WEBPACK };
12 // act
13 return bundle.bundle(context).then(function () {
14 // assert
15 expect(webpack.webpack).toHaveBeenCalled();
16 });
17 });
18 it('should throw when webpack throws', function () {
19 var errorText = 'simulating an error';
20 // arrange
21 spyOn(webpack, webpack.webpack.name).and.returnValue(Promise.reject(new Error(errorText)));
22 var context = { bundler: Constants.BUNDLER_WEBPACK };
23 // act
24 return bundle.bundle(context).then(function () {
25 throw new Error('Should never happen');
26 }).catch(function (err) {
27 // assert
28 expect(webpack.webpack).toHaveBeenCalled();
29 expect(err.message).toBe(errorText);
30 });
31 });
32 });
33 describe('bundleUpdate', function () {
34 it('should return the value webpack returns', function () {
35 // arrange
36 spyOn(webpack, webpack.webpackUpdate.name).and.returnValue(Promise.resolve());
37 var context = { bundler: Constants.BUNDLER_WEBPACK };
38 var changedFiles = [];
39 // act
40 return bundle.bundleUpdate(changedFiles, context).then(function () {
41 // assert
42 expect(webpack.webpackUpdate).toHaveBeenCalledWith(changedFiles, context);
43 });
44 });
45 it('should throw when webpack throws', function () {
46 var errorText = 'simulating an error';
47 try {
48 // arrange
49 spyOn(webpack, webpack.webpackUpdate.name).and.returnValue(Promise.reject(new Error(errorText)));
50 var context = { bundler: Constants.BUNDLER_WEBPACK };
51 var changedFiles = [];
52 // act
53 return bundle.bundleUpdate(changedFiles, context).then(function () {
54 throw new Error('Should never happen');
55 }).catch(function (err) {
56 // assert
57 expect(webpack.webpackUpdate).toHaveBeenCalled();
58 expect(err.message).toBe(errorText);
59 });
60 }
61 catch (ex) {
62 }
63 });
64 });
65 describe('buildJsSourceMaps', function () {
66 it('should get false when devtool is null for webpack', function () {
67 // arrange
68 var config = {};
69 spyOn(webpack, webpack.getWebpackConfig.name).and.returnValue(config);
70 var context = { bundler: Constants.BUNDLER_WEBPACK };
71 // act
72 var result = bundle.buildJsSourceMaps(context);
73 // assert
74 expect(webpack.getWebpackConfig).toHaveBeenCalledWith(context, null);
75 expect(result).toEqual(false);
76 });
77 it('should get false when devtool is valid', function () {
78 // arrange
79 var config = { devtool: 'someValue' };
80 spyOn(webpack, webpack.getWebpackConfig.name).and.returnValue(config);
81 var context = { bundler: Constants.BUNDLER_WEBPACK };
82 // act
83 var result = bundle.buildJsSourceMaps(context);
84 // assert
85 expect(webpack.getWebpackConfig).toHaveBeenCalledWith(context, null);
86 expect(result).toEqual(true);
87 });
88 });
89 describe('getJsOutputDest', function () {
90 it('should get the value from webpack', function () {
91 // arrange
92 var returnValue = 'someString';
93 spyOn(webpack, webpack.getOutputDest.name).and.returnValue(returnValue);
94 var context = { bundler: Constants.BUNDLER_WEBPACK };
95 // act
96 var result = bundle.getJsOutputDest(context);
97 // assert
98 expect(webpack.getOutputDest).toHaveBeenCalledWith(context);
99 expect(result).toEqual(returnValue);
100 });
101 });
102});