1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var bundle = require("./bundle");
|
4 | var webpack = require("./webpack");
|
5 | var Constants = require("./util/constants");
|
6 | describe('bundle task', function () {
|
7 | describe('bundle', function () {
|
8 | it('should return the value webpack task returns', function () {
|
9 |
|
10 | spyOn(webpack, webpack.webpack.name).and.returnValue(Promise.resolve());
|
11 | var context = { bundler: Constants.BUNDLER_WEBPACK };
|
12 |
|
13 | return bundle.bundle(context).then(function () {
|
14 |
|
15 | expect(webpack.webpack).toHaveBeenCalled();
|
16 | });
|
17 | });
|
18 | it('should throw when webpack throws', function () {
|
19 | var errorText = 'simulating an error';
|
20 |
|
21 | spyOn(webpack, webpack.webpack.name).and.returnValue(Promise.reject(new Error(errorText)));
|
22 | var context = { bundler: Constants.BUNDLER_WEBPACK };
|
23 |
|
24 | return bundle.bundle(context).then(function () {
|
25 | throw new Error('Should never happen');
|
26 | }).catch(function (err) {
|
27 |
|
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 |
|
36 | spyOn(webpack, webpack.webpackUpdate.name).and.returnValue(Promise.resolve());
|
37 | var context = { bundler: Constants.BUNDLER_WEBPACK };
|
38 | var changedFiles = [];
|
39 |
|
40 | return bundle.bundleUpdate(changedFiles, context).then(function () {
|
41 |
|
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 |
|
49 | spyOn(webpack, webpack.webpackUpdate.name).and.returnValue(Promise.reject(new Error(errorText)));
|
50 | var context = { bundler: Constants.BUNDLER_WEBPACK };
|
51 | var changedFiles = [];
|
52 |
|
53 | return bundle.bundleUpdate(changedFiles, context).then(function () {
|
54 | throw new Error('Should never happen');
|
55 | }).catch(function (err) {
|
56 |
|
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 |
|
68 | var config = {};
|
69 | spyOn(webpack, webpack.getWebpackConfig.name).and.returnValue(config);
|
70 | var context = { bundler: Constants.BUNDLER_WEBPACK };
|
71 |
|
72 | var result = bundle.buildJsSourceMaps(context);
|
73 |
|
74 | expect(webpack.getWebpackConfig).toHaveBeenCalledWith(context, null);
|
75 | expect(result).toEqual(false);
|
76 | });
|
77 | it('should get false when devtool is valid', function () {
|
78 |
|
79 | var config = { devtool: 'someValue' };
|
80 | spyOn(webpack, webpack.getWebpackConfig.name).and.returnValue(config);
|
81 | var context = { bundler: Constants.BUNDLER_WEBPACK };
|
82 |
|
83 | var result = bundle.buildJsSourceMaps(context);
|
84 |
|
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 |
|
92 | var returnValue = 'someString';
|
93 | spyOn(webpack, webpack.getOutputDest.name).and.returnValue(returnValue);
|
94 | var context = { bundler: Constants.BUNDLER_WEBPACK };
|
95 |
|
96 | var result = bundle.getJsOutputDest(context);
|
97 |
|
98 | expect(webpack.getOutputDest).toHaveBeenCalledWith(context);
|
99 | expect(result).toEqual(returnValue);
|
100 | });
|
101 | });
|
102 | });
|