@sasjs/cli 6.0.0 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/commands/build/build.js +20 -10
- package/build/commands/build/internal/mockSite/assets/intercept.js +172 -0
- package/build/commands/build/internal/mockSite/assets/md5.js +75 -0
- package/build/commands/build/internal/mockSite/assets/persist.js +215 -0
- package/build/commands/build/internal/mockSite/assets/runtime-core.js +616 -0
- package/build/commands/build/internal/mockSite/assets/sw.js +228 -0
- package/build/commands/build/internal/mockSite/mockSite.d.ts +27 -0
- package/build/commands/build/internal/mockSite/mockSite.js +408 -0
- package/build/commands/build/internal/mockSite/spec/intercept.spec.d.ts +1 -0
- package/build/commands/build/internal/mockSite/spec/intercept.spec.js +267 -0
- package/build/commands/build/internal/mockSite/spec/mockSite.spec.d.ts +1 -0
- package/build/commands/build/internal/mockSite/spec/mockSite.spec.js +405 -0
- package/build/commands/build/internal/mockSite/spec/persist.spec.d.ts +1 -0
- package/build/commands/build/internal/mockSite/spec/persist.spec.js +418 -0
- package/build/commands/build/internal/mockSite/spec/runtime-core.spec.d.ts +1 -0
- package/build/commands/build/internal/mockSite/spec/runtime-core.spec.js +296 -0
- package/build/commands/build/internal/mockSite/spec/sw.spec.d.ts +1 -0
- package/build/commands/build/internal/mockSite/spec/sw.spec.js +361 -0
- package/build/commands/index.d.ts +1 -0
- package/build/commands/index.js +3 -1
- package/package.json +8 -7
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var __values = (this && this.__values) || function(o) {
|
|
50
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
51
|
+
if (m) return m.call(o);
|
|
52
|
+
if (o && typeof o.length === "number") return {
|
|
53
|
+
next: function () {
|
|
54
|
+
if (o && i >= o.length) o = void 0;
|
|
55
|
+
return { value: o && o[i++], done: !o };
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
59
|
+
};
|
|
60
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
61
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
62
|
+
};
|
|
63
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
64
|
+
var fs_1 = __importDefault(require("fs"));
|
|
65
|
+
var path_1 = __importDefault(require("path"));
|
|
66
|
+
var mockSite_1 = require("../mockSite");
|
|
67
|
+
var appLoc = '/Public/app/test';
|
|
68
|
+
var write = function (file, contents) {
|
|
69
|
+
fs_1.default.mkdirSync(path_1.default.dirname(file), { recursive: true });
|
|
70
|
+
fs_1.default.writeFileSync(file, contents);
|
|
71
|
+
};
|
|
72
|
+
var createProject = function (root) {
|
|
73
|
+
// sasjsbuild is what `sasjs compile` leaves behind: every service folder
|
|
74
|
+
// copied in, then the sync folder's contents over the root.
|
|
75
|
+
var build = path_1.default.join(root, 'sasjsbuild');
|
|
76
|
+
write(path_1.default.join(build, 'services', 'public', 'getdata.js'), 'const a = 1\n');
|
|
77
|
+
write(path_1.default.join(build, 'services', 'public', 'viewtables.js'), 'const a = 2\n');
|
|
78
|
+
write(path_1.default.join(build, 'services', 'admin', 'makedata.js'), 'const a = 3\n');
|
|
79
|
+
write(path_1.default.join(build, 'mock-storage', 'licence.json'), '{"licenceKey":"invalid"}');
|
|
80
|
+
// root-level build artefacts must not reach the virtual drive
|
|
81
|
+
write(path_1.default.join(build, 'server-ci.sas'), '%put build pack;\n');
|
|
82
|
+
write(path_1.default.join(build, 'server-ci.json'), '{"members":[]}\n');
|
|
83
|
+
write(path_1.default.join(root, 'client', 'dist', 'index.html'), [
|
|
84
|
+
'<!doctype html><html><head><title>App</title></head><body>',
|
|
85
|
+
"<sasjs serverurl=\"https://sas.example.com\" apploc=\"".concat(appLoc, "\" servertype=\"SASJS\" loginmechanism=\"Redirected\"></sasjs>"),
|
|
86
|
+
'<script src="main.abc123.js" type="module"></script>',
|
|
87
|
+
'</body></html>'
|
|
88
|
+
].join('\n'));
|
|
89
|
+
write(path_1.default.join(root, 'client', 'dist', 'main.abc123.js'), 'console.log(1)\n');
|
|
90
|
+
};
|
|
91
|
+
describe('browser-hosted build', function () {
|
|
92
|
+
var root;
|
|
93
|
+
var out = function () { return path_1.default.join(root, 'sasjsbuild', 'mock'); };
|
|
94
|
+
var target = function (streamConfig) {
|
|
95
|
+
if (streamConfig === void 0) { streamConfig = {}; }
|
|
96
|
+
return ({
|
|
97
|
+
appLoc: appLoc,
|
|
98
|
+
streamConfig: __assign({ webSourcePath: './client/dist' }, streamConfig)
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
var readSeed = function () {
|
|
102
|
+
return JSON.parse(fs_1.default.readFileSync(path_1.default.join(out(), 'host', 'vfs-seed.json'), 'utf8'));
|
|
103
|
+
};
|
|
104
|
+
var readConfig = function () {
|
|
105
|
+
return JSON.parse(fs_1.default.readFileSync(path_1.default.join(out(), 'host', 'mock-config.json'), 'utf8'));
|
|
106
|
+
};
|
|
107
|
+
beforeEach(function () {
|
|
108
|
+
root = fs_1.default.mkdtempSync(path_1.default.join(require('os').tmpdir(), 'sasjs-mock-'));
|
|
109
|
+
createProject(root);
|
|
110
|
+
process.projectDir = root;
|
|
111
|
+
process.sasjsConfig = { syncFolder: 'sasjs' };
|
|
112
|
+
process.sasjsConstants = {
|
|
113
|
+
buildDestinationFolder: path_1.default.join(root, 'sasjsbuild')
|
|
114
|
+
};
|
|
115
|
+
process.logger = { warn: jest.fn(), info: jest.fn() };
|
|
116
|
+
});
|
|
117
|
+
afterEach(function () {
|
|
118
|
+
fs_1.default.rmSync(root, { recursive: true, force: true });
|
|
119
|
+
});
|
|
120
|
+
it('lays the compile output out on the virtual drive', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
121
|
+
var result, seed;
|
|
122
|
+
return __generator(this, function (_a) {
|
|
123
|
+
switch (_a.label) {
|
|
124
|
+
case 0: return [4 /*yield*/, (0, mockSite_1.buildMockSite)(target())];
|
|
125
|
+
case 1:
|
|
126
|
+
result = _a.sent();
|
|
127
|
+
expect(result.jsPrograms).toBe(3);
|
|
128
|
+
expect(result.driveEntries).toBe(4); // 3 programs + the licence store
|
|
129
|
+
seed = readSeed();
|
|
130
|
+
expect(seed.files["/sasjs/drive/files".concat(appLoc, "/services/public/getdata.js")]).toBe('const a = 1\n');
|
|
131
|
+
expect(seed.files["/sasjs/drive/files".concat(appLoc, "/mock-storage/licence.json")]).toContain('licenceKey');
|
|
132
|
+
// the service pack and its manifest stay out of the drive
|
|
133
|
+
expect(Object.keys(seed.files).some(function (k) { return k.endsWith('.sas'); })).toBe(false);
|
|
134
|
+
expect(Object.keys(seed.files).some(function (k) { return k.endsWith('server-ci.json'); })).toBe(false);
|
|
135
|
+
return [2 /*return*/];
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}); });
|
|
139
|
+
it('writes the runtime host and the worker at the site root', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
140
|
+
var _a, _b, asset;
|
|
141
|
+
var e_1, _c;
|
|
142
|
+
return __generator(this, function (_d) {
|
|
143
|
+
switch (_d.label) {
|
|
144
|
+
case 0: return [4 /*yield*/, (0, mockSite_1.buildMockSite)(target())];
|
|
145
|
+
case 1:
|
|
146
|
+
_d.sent();
|
|
147
|
+
try {
|
|
148
|
+
for (_a = __values([
|
|
149
|
+
'md5.js',
|
|
150
|
+
'runtime-core.js',
|
|
151
|
+
'persist.js',
|
|
152
|
+
'intercept.js'
|
|
153
|
+
]), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
154
|
+
asset = _b.value;
|
|
155
|
+
expect(fs_1.default.existsSync(path_1.default.join(out(), 'host', asset))).toBe(true);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
159
|
+
finally {
|
|
160
|
+
try {
|
|
161
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
162
|
+
}
|
|
163
|
+
finally { if (e_1) throw e_1.error; }
|
|
164
|
+
}
|
|
165
|
+
// a worker only controls the folder it is served from, so it has to sit at
|
|
166
|
+
// the root rather than under host/
|
|
167
|
+
expect(fs_1.default.existsSync(path_1.default.join(out(), 'sw.js'))).toBe(true);
|
|
168
|
+
expect(fs_1.default.existsSync(path_1.default.join(out(), 'host', 'sw.js'))).toBe(false);
|
|
169
|
+
expect(readConfig().appLoc).toBe(appLoc);
|
|
170
|
+
return [2 /*return*/];
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
}); });
|
|
174
|
+
it('points the app at itself and installs the boot loader', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
175
|
+
var html;
|
|
176
|
+
return __generator(this, function (_a) {
|
|
177
|
+
switch (_a.label) {
|
|
178
|
+
case 0: return [4 /*yield*/, (0, mockSite_1.buildMockSite)(target())];
|
|
179
|
+
case 1:
|
|
180
|
+
_a.sent();
|
|
181
|
+
html = fs_1.default.readFileSync(path_1.default.join(out(), 'index.html'), 'utf8');
|
|
182
|
+
expect(html).toContain('serverurl=""');
|
|
183
|
+
expect(html).toContain('loginmechanism="Default"');
|
|
184
|
+
expect(html).not.toContain('https://sas.example.com');
|
|
185
|
+
expect(html).toContain("register('/sw.js'");
|
|
186
|
+
expect(html).toContain('host/persist.js');
|
|
187
|
+
expect(html).toContain('main.abc123.js');
|
|
188
|
+
return [2 /*return*/];
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}); });
|
|
192
|
+
it('ships a captured drive snapshot when the project has one', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
193
|
+
var snapshot, result, shipped;
|
|
194
|
+
var _a;
|
|
195
|
+
return __generator(this, function (_b) {
|
|
196
|
+
switch (_b.label) {
|
|
197
|
+
case 0:
|
|
198
|
+
snapshot = {
|
|
199
|
+
files: (_a = {},
|
|
200
|
+
_a["/sasjs/drive/files".concat(appLoc, "/services/public/getdata.js")] = 'const a = 1\n',
|
|
201
|
+
_a["/sasjs/drive/files".concat(appLoc, "/data/DC_JSLIB/mpe_config.json")] = '{"rows":[]}',
|
|
202
|
+
_a)
|
|
203
|
+
};
|
|
204
|
+
write(path_1.default.join(root, 'sasjsbuild', 'mock-snapshot.json'), JSON.stringify(snapshot));
|
|
205
|
+
return [4 /*yield*/, (0, mockSite_1.buildMockSite)(target())];
|
|
206
|
+
case 1:
|
|
207
|
+
result = _b.sent();
|
|
208
|
+
expect(result.snapshot).toBe(true);
|
|
209
|
+
shipped = JSON.parse(fs_1.default.readFileSync(path_1.default.join(out(), 'host', 'vfs-snapshot.json'), 'utf8'));
|
|
210
|
+
expect(Object.keys(shipped.files).length).toBe(2);
|
|
211
|
+
// the runtime prefers a snapshot over the seed, so it must not be mistaken
|
|
212
|
+
// for one of the seeded folders
|
|
213
|
+
expect(readConfig().snapshot).toBe(true);
|
|
214
|
+
return [2 /*return*/];
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}); });
|
|
218
|
+
it('ships no snapshot when the project has none', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
219
|
+
var result;
|
|
220
|
+
return __generator(this, function (_a) {
|
|
221
|
+
switch (_a.label) {
|
|
222
|
+
case 0: return [4 /*yield*/, (0, mockSite_1.buildMockSite)(target())];
|
|
223
|
+
case 1:
|
|
224
|
+
result = _a.sent();
|
|
225
|
+
expect(result.snapshot).toBe(false);
|
|
226
|
+
expect(fs_1.default.existsSync(path_1.default.join(out(), 'host', 'vfs-snapshot.json'))).toBe(false);
|
|
227
|
+
return [2 /*return*/];
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}); });
|
|
231
|
+
it('leaves non-text files off the drive instead of corrupting them', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
232
|
+
var png, result, seed;
|
|
233
|
+
var _a;
|
|
234
|
+
return __generator(this, function (_b) {
|
|
235
|
+
switch (_b.label) {
|
|
236
|
+
case 0:
|
|
237
|
+
png = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
238
|
+
write(path_1.default.join(root, 'sasjsbuild', 'mock-storage', 'fixtures.json'), '{}');
|
|
239
|
+
fs_1.default.writeFileSync(path_1.default.join(root, 'sasjsbuild', 'mock-storage', 'logo.png'), png);
|
|
240
|
+
return [4 /*yield*/, (0, mockSite_1.buildMockSite)(target())];
|
|
241
|
+
case 1:
|
|
242
|
+
result = _b.sent();
|
|
243
|
+
seed = readSeed();
|
|
244
|
+
expect(Object.keys(seed.files).some(function (k) { return k.endsWith('logo.png'); })).toBe(false);
|
|
245
|
+
expect(seed.files["/sasjs/drive/files".concat(appLoc, "/mock-storage/fixtures.json")]).toBe('{}');
|
|
246
|
+
expect(result.driveEntries).toBe(5); // 3 programs + 2 text files
|
|
247
|
+
expect((_a = process.logger) === null || _a === void 0 ? void 0 : _a.warn).toHaveBeenCalledWith(expect.stringContaining('logo.png'));
|
|
248
|
+
return [2 /*return*/];
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
}); });
|
|
252
|
+
it('refuses a target whose services are SAS, and keeps the previous site', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
253
|
+
return __generator(this, function (_a) {
|
|
254
|
+
switch (_a.label) {
|
|
255
|
+
case 0: return [4 /*yield*/, (0, mockSite_1.buildMockSite)(target())];
|
|
256
|
+
case 1:
|
|
257
|
+
_a.sent();
|
|
258
|
+
write(path_1.default.join(out(), 'stale.txt'), 'previous');
|
|
259
|
+
fs_1.default.rmSync(path_1.default.join(root, 'sasjsbuild', 'services'), {
|
|
260
|
+
recursive: true,
|
|
261
|
+
force: true
|
|
262
|
+
});
|
|
263
|
+
write(path_1.default.join(root, 'sasjsbuild', 'services', 'public', 'getdata.sas'), '%put sas;\n');
|
|
264
|
+
return [4 /*yield*/, expect((0, mockSite_1.buildMockSite)(target())).rejects.toThrow(/No \.js programs/)
|
|
265
|
+
// the failure is not allowed to take the last good site with it
|
|
266
|
+
];
|
|
267
|
+
case 2:
|
|
268
|
+
_a.sent();
|
|
269
|
+
// the failure is not allowed to take the last good site with it
|
|
270
|
+
expect(fs_1.default.readFileSync(path_1.default.join(out(), 'stale.txt'), 'utf8')).toBe('previous');
|
|
271
|
+
return [2 /*return*/];
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
}); });
|
|
275
|
+
it('refuses to build without a web app', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
276
|
+
return __generator(this, function (_a) {
|
|
277
|
+
switch (_a.label) {
|
|
278
|
+
case 0: return [4 /*yield*/, expect((0, mockSite_1.buildMockSite)(target({ webSourcePath: './does-not-exist' }))).rejects.toThrow(/Web source folder not found/)];
|
|
279
|
+
case 1:
|
|
280
|
+
_a.sent();
|
|
281
|
+
return [2 /*return*/];
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
}); });
|
|
285
|
+
it('refuses to build without an appLoc', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
286
|
+
return __generator(this, function (_a) {
|
|
287
|
+
switch (_a.label) {
|
|
288
|
+
case 0: return [4 /*yield*/, expect((0, mockSite_1.buildMockSite)({ streamConfig: {} })).rejects.toThrow(/No appLoc/)];
|
|
289
|
+
case 1:
|
|
290
|
+
_a.sent();
|
|
291
|
+
return [2 /*return*/];
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
}); });
|
|
295
|
+
it('replaces an existing output folder rather than merging into it', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
296
|
+
return __generator(this, function (_a) {
|
|
297
|
+
switch (_a.label) {
|
|
298
|
+
case 0:
|
|
299
|
+
write(path_1.default.join(out(), 'stale.txt'), 'old');
|
|
300
|
+
return [4 /*yield*/, (0, mockSite_1.buildMockSite)(target())];
|
|
301
|
+
case 1:
|
|
302
|
+
_a.sent();
|
|
303
|
+
expect(fs_1.default.existsSync(path_1.default.join(out(), 'stale.txt'))).toBe(false);
|
|
304
|
+
return [2 /*return*/];
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}); });
|
|
308
|
+
it('warns instead of failing when the index.html is not the expected shape', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
309
|
+
var result;
|
|
310
|
+
var _a, _b;
|
|
311
|
+
return __generator(this, function (_c) {
|
|
312
|
+
switch (_c.label) {
|
|
313
|
+
case 0:
|
|
314
|
+
write(path_1.default.join(root, 'client', 'dist', 'index.html'), '<!doctype html><html><body><div id="app"></div></body></html>');
|
|
315
|
+
return [4 /*yield*/, (0, mockSite_1.buildMockSite)(target())];
|
|
316
|
+
case 1:
|
|
317
|
+
result = _c.sent();
|
|
318
|
+
expect(result.webFileCount).toBeGreaterThan(0);
|
|
319
|
+
expect((_a = process.logger) === null || _a === void 0 ? void 0 : _a.warn).toHaveBeenCalledWith(expect.stringContaining('no <sasjs> element found'));
|
|
320
|
+
expect((_b = process.logger) === null || _b === void 0 ? void 0 : _b.warn).toHaveBeenCalledWith(expect.stringContaining('no main bundle script tag found'));
|
|
321
|
+
return [2 /*return*/];
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
}); });
|
|
325
|
+
it('leaves a streamed web folder off the drive', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
326
|
+
var keys;
|
|
327
|
+
return __generator(this, function (_a) {
|
|
328
|
+
switch (_a.label) {
|
|
329
|
+
case 0:
|
|
330
|
+
write(path_1.default.join(root, 'sasjsbuild', 'services', 'web', 'index.html'), '<html></html>');
|
|
331
|
+
return [4 /*yield*/, (0, mockSite_1.buildMockSite)(target({ streamWeb: true, streamWebFolder: 'web' }))];
|
|
332
|
+
case 1:
|
|
333
|
+
_a.sent();
|
|
334
|
+
keys = Object.keys(readSeed().files);
|
|
335
|
+
expect(keys.some(function (k) { return k.startsWith("".concat(appLoc, "/services/web/")); })).toBe(false);
|
|
336
|
+
// the same folder is still the site's own content, so it is copied
|
|
337
|
+
expect(fs_1.default.existsSync(path_1.default.join(out(), 'index.html'))).toBe(true);
|
|
338
|
+
return [2 /*return*/];
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
}); });
|
|
342
|
+
it('refuses a mockWebFolder outside the project', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
343
|
+
var outside;
|
|
344
|
+
return __generator(this, function (_a) {
|
|
345
|
+
switch (_a.label) {
|
|
346
|
+
case 0:
|
|
347
|
+
outside = fs_1.default.mkdtempSync(path_1.default.join(require('os').tmpdir(), 'outside-'));
|
|
348
|
+
return [4 /*yield*/, expect((0, mockSite_1.buildMockSite)(target({ mockWebFolder: outside }))).rejects.toThrow(/outside the project/)];
|
|
349
|
+
case 1:
|
|
350
|
+
_a.sent();
|
|
351
|
+
expect(fs_1.default.existsSync(outside)).toBe(true);
|
|
352
|
+
fs_1.default.rmSync(outside, { recursive: true, force: true });
|
|
353
|
+
return [2 /*return*/];
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
}); });
|
|
357
|
+
it('refuses a mockWebFolder that would delete the project or its inputs', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
358
|
+
var _a, _b, mockWebFolder, e_2_1;
|
|
359
|
+
var e_2, _c;
|
|
360
|
+
return __generator(this, function (_d) {
|
|
361
|
+
switch (_d.label) {
|
|
362
|
+
case 0:
|
|
363
|
+
_d.trys.push([0, 5, 6, 7]);
|
|
364
|
+
_a = __values([
|
|
365
|
+
'.',
|
|
366
|
+
'./',
|
|
367
|
+
'..',
|
|
368
|
+
'sasjsbuild',
|
|
369
|
+
'client/dist',
|
|
370
|
+
'client/dist/mock'
|
|
371
|
+
]), _b = _a.next();
|
|
372
|
+
_d.label = 1;
|
|
373
|
+
case 1:
|
|
374
|
+
if (!!_b.done) return [3 /*break*/, 4];
|
|
375
|
+
mockWebFolder = _b.value;
|
|
376
|
+
return [4 /*yield*/, expect((0, mockSite_1.buildMockSite)(target({ mockWebFolder: mockWebFolder }))).rejects.toThrow(/Refusing to write the mock site/)
|
|
377
|
+
// nothing was removed on the way to the refusal
|
|
378
|
+
];
|
|
379
|
+
case 2:
|
|
380
|
+
_d.sent();
|
|
381
|
+
// nothing was removed on the way to the refusal
|
|
382
|
+
expect(fs_1.default.existsSync(path_1.default.join(root, 'client', 'dist', 'index.html'))).toBe(true);
|
|
383
|
+
expect(fs_1.default.existsSync(path_1.default.join(root, 'sasjsbuild', 'services', 'public'))).toBe(true);
|
|
384
|
+
_d.label = 3;
|
|
385
|
+
case 3:
|
|
386
|
+
_b = _a.next();
|
|
387
|
+
return [3 /*break*/, 1];
|
|
388
|
+
case 4: return [3 /*break*/, 7];
|
|
389
|
+
case 5:
|
|
390
|
+
e_2_1 = _d.sent();
|
|
391
|
+
e_2 = { error: e_2_1 };
|
|
392
|
+
return [3 /*break*/, 7];
|
|
393
|
+
case 6:
|
|
394
|
+
try {
|
|
395
|
+
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
396
|
+
}
|
|
397
|
+
finally { if (e_2) throw e_2.error; }
|
|
398
|
+
return [7 /*endfinally*/];
|
|
399
|
+
case 7:
|
|
400
|
+
expect(fs_1.default.existsSync(path_1.default.join(root, 'client', 'dist', 'index.html'))).toBe(true);
|
|
401
|
+
return [2 /*return*/];
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
}); });
|
|
405
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|