1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | return new (P || (P = Promise))(function (resolve, reject) {
|
4 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
7 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8 | });
|
9 | };
|
10 | var __generator = (this && this.__generator) || function (thisArg, body) {
|
11 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
12 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
13 | function verb(n) { return function (v) { return step([n, v]); }; }
|
14 | function step(op) {
|
15 | if (f) throw new TypeError("Generator is already executing.");
|
16 | while (_) try {
|
17 | if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
|
18 | if (y = 0, t) op = [0, t.value];
|
19 | switch (op[0]) {
|
20 | case 0: case 1: t = op; break;
|
21 | case 4: _.label++; return { value: op[1], done: false };
|
22 | case 5: _.label++; y = op[1]; op = [0]; continue;
|
23 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
24 | default:
|
25 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
26 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
27 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
28 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
29 | if (t[2]) _.ops.pop();
|
30 | _.trys.pop(); continue;
|
31 | }
|
32 | op = body.call(thisArg, _);
|
33 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
34 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
35 | }
|
36 | };
|
37 | var _this = this;
|
38 | Object.defineProperty(exports, "__esModule", { value: true });
|
39 | var path_1 = require("path");
|
40 | var Constants = require("./constants");
|
41 | var sourceMaps = require("./source-maps");
|
42 | var helpers = require("./helpers");
|
43 | describe('source maps', function () {
|
44 | describe('purgeSourceMapsIfNeeded', function () {
|
45 | it('should copy files first, then purge the files', function () { return __awaiter(_this, void 0, void 0, function () {
|
46 | var knownFileNames, context, copyFileSpy, unlinkFileSpy, result;
|
47 | return __generator(this, function (_a) {
|
48 | switch (_a.label) {
|
49 | case 0:
|
50 | spyOn(helpers, helpers.getBooleanPropertyValue.name).and.callFake(function (argument) {
|
51 | if (argument === Constants.ENV_VAR_MOVE_SOURCE_MAPS) {
|
52 | return true;
|
53 | }
|
54 | });
|
55 | spyOn(helpers, helpers.mkDirpAsync.name).and.returnValue(Promise.resolve());
|
56 | knownFileNames = ['0.js', '0.js.map', '1.js', '1.js.map', 'main.js', 'main.js.map', 'vendor.js', 'vendor.js.map', 'main.css', 'polyfills.js', 'sw-toolbox.js', 'main.css', 'main.css.map'];
|
57 | spyOn(helpers, helpers.readDirAsync.name).and.returnValue(Promise.resolve(knownFileNames));
|
58 | context = {
|
59 | sourcemapDir: path_1.join(process.cwd(), 'sourceMapDir'),
|
60 | buildDir: path_1.join(process.cwd(), 'www', 'build')
|
61 | };
|
62 | copyFileSpy = spyOn(helpers, helpers.copyFileAsync.name).and.returnValue(Promise.resolve());
|
63 | unlinkFileSpy = spyOn(helpers, helpers.unlinkAsync.name).and.returnValue(Promise.resolve());
|
64 | return [4 , sourceMaps.copySourcemaps(context, true)];
|
65 | case 1:
|
66 | result = _a.sent();
|
67 | expect(helpers.mkDirpAsync).toHaveBeenCalledTimes(1);
|
68 | expect(helpers.mkDirpAsync).toHaveBeenCalledWith(context.sourcemapDir);
|
69 | expect(helpers.readDirAsync).toHaveBeenCalledTimes(1);
|
70 | expect(helpers.readDirAsync).toHaveBeenLastCalledWith(context.buildDir);
|
71 | expect(helpers.copyFileAsync).toHaveBeenCalledTimes(3);
|
72 | expect(copyFileSpy.calls.all()[0].args[0]).toEqual(path_1.join(context.buildDir, '0.js.map'));
|
73 | expect(copyFileSpy.calls.all()[0].args[1]).toEqual(path_1.join(context.sourcemapDir, '0.js.map'));
|
74 | expect(copyFileSpy.calls.all()[1].args[0]).toEqual(path_1.join(context.buildDir, '1.js.map'));
|
75 | expect(copyFileSpy.calls.all()[1].args[1]).toEqual(path_1.join(context.sourcemapDir, '1.js.map'));
|
76 | expect(copyFileSpy.calls.all()[2].args[0]).toEqual(path_1.join(context.buildDir, 'main.js.map'));
|
77 | expect(copyFileSpy.calls.all()[2].args[1]).toEqual(path_1.join(context.sourcemapDir, 'main.js.map'));
|
78 | expect(helpers.unlinkAsync).toHaveBeenCalledTimes(5);
|
79 | expect(unlinkFileSpy.calls.all()[0].args[0]).toEqual(path_1.join(context.buildDir, '0.js.map'));
|
80 | expect(unlinkFileSpy.calls.all()[1].args[0]).toEqual(path_1.join(context.buildDir, '1.js.map'));
|
81 | expect(unlinkFileSpy.calls.all()[2].args[0]).toEqual(path_1.join(context.buildDir, 'main.js.map'));
|
82 | expect(unlinkFileSpy.calls.all()[3].args[0]).toEqual(path_1.join(context.buildDir, 'vendor.js.map'));
|
83 | expect(unlinkFileSpy.calls.all()[4].args[0]).toEqual(path_1.join(context.buildDir, 'main.css.map'));
|
84 | return [2 ];
|
85 | }
|
86 | });
|
87 | }); });
|
88 | it('should copy the files but not purge them after', function () { return __awaiter(_this, void 0, void 0, function () {
|
89 | var knownFileNames, context, copyFileSpy, unlinkFileSpy, result;
|
90 | return __generator(this, function (_a) {
|
91 | switch (_a.label) {
|
92 | case 0:
|
93 | spyOn(helpers, helpers.getBooleanPropertyValue.name).and.callFake(function (argument) {
|
94 | if (argument === Constants.ENV_VAR_MOVE_SOURCE_MAPS) {
|
95 | return true;
|
96 | }
|
97 | });
|
98 | spyOn(helpers, helpers.mkDirpAsync.name).and.returnValue(Promise.resolve());
|
99 | knownFileNames = ['0.js', '0.js.map', '1.js', '1.js.map', 'main.js', 'main.js.map', 'vendor.js', 'vendor.js.map', 'main.css', 'polyfills.js', 'sw-toolbox.js', 'main.css', 'main.css.map'];
|
100 | spyOn(helpers, helpers.readDirAsync.name).and.returnValue(Promise.resolve(knownFileNames));
|
101 | context = {
|
102 | sourcemapDir: path_1.join(process.cwd(), 'sourceMapDir'),
|
103 | buildDir: path_1.join(process.cwd(), 'www', 'build')
|
104 | };
|
105 | copyFileSpy = spyOn(helpers, helpers.copyFileAsync.name).and.returnValue(Promise.resolve());
|
106 | unlinkFileSpy = spyOn(helpers, helpers.unlinkAsync.name).and.returnValue(Promise.resolve());
|
107 | return [4 , sourceMaps.copySourcemaps(context, false)];
|
108 | case 1:
|
109 | result = _a.sent();
|
110 | expect(helpers.mkDirpAsync).toHaveBeenCalledTimes(1);
|
111 | expect(helpers.mkDirpAsync).toHaveBeenCalledWith(context.sourcemapDir);
|
112 | expect(helpers.readDirAsync).toHaveBeenCalledTimes(1);
|
113 | expect(helpers.readDirAsync).toHaveBeenLastCalledWith(context.buildDir);
|
114 | expect(helpers.copyFileAsync).toHaveBeenCalledTimes(3);
|
115 | expect(copyFileSpy.calls.all()[0].args[0]).toEqual(path_1.join(context.buildDir, '0.js.map'));
|
116 | expect(copyFileSpy.calls.all()[0].args[1]).toEqual(path_1.join(context.sourcemapDir, '0.js.map'));
|
117 | expect(copyFileSpy.calls.all()[1].args[0]).toEqual(path_1.join(context.buildDir, '1.js.map'));
|
118 | expect(copyFileSpy.calls.all()[1].args[1]).toEqual(path_1.join(context.sourcemapDir, '1.js.map'));
|
119 | expect(copyFileSpy.calls.all()[2].args[0]).toEqual(path_1.join(context.buildDir, 'main.js.map'));
|
120 | expect(copyFileSpy.calls.all()[2].args[1]).toEqual(path_1.join(context.sourcemapDir, 'main.js.map'));
|
121 | expect(helpers.unlinkAsync).toHaveBeenCalledTimes(0);
|
122 | return [2 ];
|
123 | }
|
124 | });
|
125 | }); });
|
126 | });
|
127 | });
|