@salesforce/pwa-kit-dev 3.8.0-preview.0-basepath → 3.8.0-preview.2-basepath
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/configs/babel/babel-config.js +33 -0
- package/configs/eslint/README.md +21 -0
- package/configs/eslint/eslint-config.js +11 -0
- package/configs/eslint/index.js +11 -0
- package/configs/eslint/no-react.js +18 -0
- package/configs/eslint/partials/base.js +38 -0
- package/configs/eslint/partials/jest.js +24 -0
- package/configs/eslint/partials/react.js +29 -0
- package/configs/eslint/partials/typescript-permit-any.js +31 -0
- package/configs/eslint/partials/typescript.js +17 -0
- package/configs/eslint/recommended.js +20 -0
- package/configs/eslint/safe-types.js +20 -0
- package/configs/jest/jest-babel-transform.js +19 -0
- package/configs/jest/jest.config.js +40 -0
- package/configs/jest/mocks/fileMock.js +9 -0
- package/configs/jest/mocks/styleMock.js +9 -0
- package/configs/jest/mocks/svgMock.js +11 -0
- package/configs/webpack/config-names.js +19 -0
- package/configs/webpack/config.js +406 -0
- package/configs/webpack/overrides-plugin.js +168 -0
- package/configs/webpack/overrides-plugin.test.js +388 -0
- package/configs/webpack/plugins.js +86 -0
- package/configs/webpack/test/overrides/exists.js +7 -0
- package/configs/webpack/test/overrides/newExtension.js +7 -0
- package/configs/webpack/test/overrides/path/data.js +7 -0
- package/configs/webpack/test/overrides/path/index.js +7 -0
- package/configs/webpack/test/overrides/path/index.mock.js +7 -0
- package/configs/webpack/test/overrides/path/nested/icon.svg +0 -0
- package/configs/webpack/test/package.json +13 -0
- package/configs/webpack/utils.js +23 -0
- package/package.json +5 -4
- package/ssr/server/build-dev-server.js +468 -0
- package/ssr/server/build-dev-server.test.js +661 -0
- package/ssr/server/loading-screen/css/main.css +272 -0
- package/ssr/server/loading-screen/css/normalize.css +349 -0
- package/ssr/server/loading-screen/img/cloud-1.svg +1 -0
- package/ssr/server/loading-screen/img/cloud-2.svg +1 -0
- package/ssr/server/loading-screen/img/cloud-3.svg +1 -0
- package/ssr/server/loading-screen/img/cloud.svg +1 -0
- package/ssr/server/loading-screen/img/codey-arm.svg +1 -0
- package/ssr/server/loading-screen/img/codey-bear.svg +1 -0
- package/ssr/server/loading-screen/img/codey-bg.svg +1 -0
- package/ssr/server/loading-screen/img/codey-cloud.svg +1 -0
- package/ssr/server/loading-screen/img/codey-search.svg +1 -0
- package/ssr/server/loading-screen/img/codey.svg +1 -0
- package/ssr/server/loading-screen/img/codeyCarry.svg +1 -0
- package/ssr/server/loading-screen/img/devDocumentation.svg +1 -0
- package/ssr/server/loading-screen/img/devGithub.svg +1 -0
- package/ssr/server/loading-screen/img/devTrailhead.svg +1 -0
- package/ssr/server/loading-screen/img/logo.svg +1 -0
- package/ssr/server/loading-screen/img/slds_spinner_brand_9EA9F1.gif +0 -0
- package/ssr/server/loading-screen/index.html +129 -0
- package/ssr/server/test_fixtures/app/main.js +6 -0
- package/ssr/server/test_fixtures/app/static/favicon.ico +0 -0
- package/ssr/server/test_fixtures/localhost.pem +45 -0
- package/utils/mocks/dependency-tree-mock-data.js +127 -0
- package/utils/script-utils.js +497 -0
- package/utils/script-utils.test.js +496 -0
- package/utils/test-fixtures/minimal-built-app/ssr.js +9 -0
- package/utils/test-fixtures/minimal-built-app/static/favicon.ico +0 -0
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _fsExtra = require("fs-extra");
|
|
4
|
+
var _child_process = require("child_process");
|
|
5
|
+
var _path = _interopRequireDefault(require("path"));
|
|
6
|
+
var _os = _interopRequireDefault(require("os"));
|
|
7
|
+
var scriptUtils = _interopRequireWildcard(require("./script-utils"));
|
|
8
|
+
var dependencyTreeMockData = _interopRequireWildcard(require("./mocks/dependency-tree-mock-data"));
|
|
9
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
10
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
13
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
14
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
15
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
16
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
17
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
18
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /*
|
|
19
|
+
* Copyright (c) 2021, salesforce.com, inc.
|
|
20
|
+
* All rights reserved.
|
|
21
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
22
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
23
|
+
*/
|
|
24
|
+
const pkg = (0, _fsExtra.readJsonSync)(_path.default.join(__dirname, '../package.json'));
|
|
25
|
+
let actualReadJson;
|
|
26
|
+
let actualExecSync;
|
|
27
|
+
jest.mock('fs-extra', () => {
|
|
28
|
+
const originalModule = jest.requireActual('fs-extra');
|
|
29
|
+
actualReadJson = originalModule.readJson;
|
|
30
|
+
return _objectSpread(_objectSpread({}, originalModule), {}, {
|
|
31
|
+
readJson: jest.fn()
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
jest.mock('child_process', () => {
|
|
35
|
+
const originalModule = jest.requireActual('child_process');
|
|
36
|
+
actualExecSync = originalModule.execSync;
|
|
37
|
+
return _objectSpread(_objectSpread({}, originalModule), {}, {
|
|
38
|
+
execSync: jest.fn()
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
describe('scriptUtils', () => {
|
|
42
|
+
const originalEnv = process.env;
|
|
43
|
+
let tmpDir;
|
|
44
|
+
beforeEach( /*#__PURE__*/_asyncToGenerator(function* () {
|
|
45
|
+
process.env = _objectSpread({}, originalEnv);
|
|
46
|
+
tmpDir = yield (0, _fsExtra.mkdtemp)(_path.default.join(_os.default.tmpdir(), 'scriptUtils-tests'));
|
|
47
|
+
// This is a workaround for jest.spyOn(), since I guess it doesn't work with our imports?
|
|
48
|
+
// In any case, using the actual implementation by default prevents subtle bugs in tests.
|
|
49
|
+
_fsExtra.readJson.mockReset().mockImplementation(actualReadJson);
|
|
50
|
+
_child_process.execSync.mockReset().mockImplementation(actualExecSync);
|
|
51
|
+
}));
|
|
52
|
+
afterEach( /*#__PURE__*/_asyncToGenerator(function* () {
|
|
53
|
+
process.env = originalEnv;
|
|
54
|
+
tmpDir && (yield (0, _fsExtra.rm)(tmpDir, {
|
|
55
|
+
recursive: true
|
|
56
|
+
}));
|
|
57
|
+
jest.resetAllMocks();
|
|
58
|
+
}));
|
|
59
|
+
test('glob() with no patterns matches nothing', () => {
|
|
60
|
+
const matcher = scriptUtils.glob();
|
|
61
|
+
expect(matcher('')).toBe(false);
|
|
62
|
+
expect(matcher('a.js')).toBe(false);
|
|
63
|
+
expect(matcher()).toBe(false);
|
|
64
|
+
});
|
|
65
|
+
describe('glob() filters correctly', () => {
|
|
66
|
+
const patterns = ['ssr.js', '**/*.jpg', '!**/no.jpg', 'abc.{js,jsx}'];
|
|
67
|
+
const matcher = scriptUtils.glob(patterns);
|
|
68
|
+
|
|
69
|
+
// Paths we expect to match
|
|
70
|
+
const expectToMatch = ['ssr.js', 'test1.jpg', 'static/test2.jpg', 'static/assets/test3.jpg', 'abc.js', 'abc.jsx'];
|
|
71
|
+
expectToMatch.forEach(path => test(`Expect path "${path}" to match`, () => {
|
|
72
|
+
expect(matcher(path)).toBe(true);
|
|
73
|
+
}));
|
|
74
|
+
|
|
75
|
+
// Paths we expect not to match
|
|
76
|
+
const expectNotToMatch = ['ssrxjs', 'subdirectory/ssr.js', 'no.jpg', 'static/no.jpg', 'abc.jsz'];
|
|
77
|
+
expectNotToMatch.forEach(path => test(`Expect path "${path}" to NOT match`, () => {
|
|
78
|
+
expect(matcher(path)).toBe(false);
|
|
79
|
+
}));
|
|
80
|
+
const allPaths = expectToMatch.concat(expectNotToMatch);
|
|
81
|
+
test('glob works with Array.filter', () => {
|
|
82
|
+
const matched = allPaths.filter(matcher);
|
|
83
|
+
expect(matched).toHaveLength(expectToMatch.length);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
describe('CloudAPIClient', () => {
|
|
87
|
+
const username = 'user123';
|
|
88
|
+
const api_key = '123';
|
|
89
|
+
const encoded = Buffer.from(`${username}:${api_key}`, 'binary').toString('base64');
|
|
90
|
+
const expectedAuthHeader = {
|
|
91
|
+
Authorization: `Basic ${encoded}`
|
|
92
|
+
};
|
|
93
|
+
test('getAuthHeader', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
94
|
+
const client = new scriptUtils.CloudAPIClient({
|
|
95
|
+
credentials: {
|
|
96
|
+
username,
|
|
97
|
+
api_key
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
expect(client.getAuthHeader()).toEqual(expectedAuthHeader);
|
|
101
|
+
}));
|
|
102
|
+
test('getHeaders', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
103
|
+
_fsExtra.readJson.mockReturnValue(pkg);
|
|
104
|
+
const client = new scriptUtils.CloudAPIClient({
|
|
105
|
+
credentials: {
|
|
106
|
+
username,
|
|
107
|
+
api_key
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
expect(yield client.getHeaders()).toEqual(_objectSpread({
|
|
111
|
+
'User-Agent': `${pkg.name}@${pkg.version}`
|
|
112
|
+
}, expectedAuthHeader));
|
|
113
|
+
}));
|
|
114
|
+
});
|
|
115
|
+
describe('getPkgJSON', () => {
|
|
116
|
+
test('should work', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
117
|
+
_fsExtra.readJson.mockReturnValue(pkg);
|
|
118
|
+
const pkgJson = yield scriptUtils.getPkgJSON();
|
|
119
|
+
expect(pkgJson.name).toBe('@salesforce/pwa-kit-dev');
|
|
120
|
+
}));
|
|
121
|
+
test('should return default package.json data when no valid file is found', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
122
|
+
_fsExtra.readJson.mockRejectedValue(Error);
|
|
123
|
+
const result = yield scriptUtils.getPkgJSON();
|
|
124
|
+
expect(result).toEqual({
|
|
125
|
+
name: '@salesforce/pwa-kit-dev',
|
|
126
|
+
version: 'unknown'
|
|
127
|
+
});
|
|
128
|
+
}));
|
|
129
|
+
});
|
|
130
|
+
describe('getProjectPkg', () => {
|
|
131
|
+
test('should work', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
132
|
+
_fsExtra.readJson.mockReturnValue(pkg);
|
|
133
|
+
const pkgJson = yield scriptUtils.getProjectPkg();
|
|
134
|
+
expect(pkgJson.name).toBe('@salesforce/pwa-kit-dev');
|
|
135
|
+
}));
|
|
136
|
+
test('should throw', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
137
|
+
_fsExtra.readJson.mockRejectedValue(Error);
|
|
138
|
+
yield expect(scriptUtils.getProjectPkg()).rejects.toThrow(`Could not read project package at "${_path.default.join(process.cwd(), 'package.json')}"`);
|
|
139
|
+
}));
|
|
140
|
+
});
|
|
141
|
+
describe('getLowestPackageVersion', () => {
|
|
142
|
+
test('should work when major version is different', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
143
|
+
const lowestVersion = yield scriptUtils.getLowestPackageVersion('@salesforce/pwa-kit-react-sdk', dependencyTreeMockData.differentMajorVersions);
|
|
144
|
+
expect(lowestVersion).toBe('9.0.0');
|
|
145
|
+
}));
|
|
146
|
+
test('should work when minor version is different', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
147
|
+
const lowestVersion = yield scriptUtils.getLowestPackageVersion('@salesforce/pwa-kit-react-sdk', dependencyTreeMockData.differentMinorVersions);
|
|
148
|
+
expect(lowestVersion).toBe('1.9.0');
|
|
149
|
+
}));
|
|
150
|
+
test('should work when patch version is different', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
151
|
+
const lowestVersion = yield scriptUtils.getLowestPackageVersion('@salesforce/pwa-kit-react-sdk', dependencyTreeMockData.differentPatchVersions);
|
|
152
|
+
expect(lowestVersion).toBe('1.0.9');
|
|
153
|
+
}));
|
|
154
|
+
test('should work when version contains pre-release version', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
155
|
+
const lowestVersion = yield scriptUtils.getLowestPackageVersion('@salesforce/pwa-kit-react-sdk', dependencyTreeMockData.preReleaseVersion);
|
|
156
|
+
expect(lowestVersion).toBe('1.0.0-beta');
|
|
157
|
+
}));
|
|
158
|
+
test('should work when package is deduped', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
159
|
+
const lowestVersion = yield scriptUtils.getLowestPackageVersion('@salesforce/pwa-kit-react-sdk', dependencyTreeMockData.dedupedVersion);
|
|
160
|
+
expect(lowestVersion).toBe('1.0.0');
|
|
161
|
+
}));
|
|
162
|
+
test("should return 'unknown' when package not found", /*#__PURE__*/_asyncToGenerator(function* () {
|
|
163
|
+
const lowestVersion = yield scriptUtils.getLowestPackageVersion('@salesforce/pwa-kit-react-sdk', dependencyTreeMockData.noPwaKitPackages);
|
|
164
|
+
expect(lowestVersion).toBe('unknown');
|
|
165
|
+
}));
|
|
166
|
+
});
|
|
167
|
+
describe('getPwaKitDependencies', () => {
|
|
168
|
+
test('should return pwa-kit packages with unknown version if not in dependency tree', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
169
|
+
const dependencies = yield scriptUtils.getPwaKitDependencies(dependencyTreeMockData.noPwaKitPackages);
|
|
170
|
+
expect(Object.keys(dependencies)).toHaveLength(3);
|
|
171
|
+
expect(dependencies).toHaveProperty('@salesforce/pwa-kit-react-sdk', 'unknown');
|
|
172
|
+
expect(dependencies).toHaveProperty('@salesforce/pwa-kit-runtime', 'unknown');
|
|
173
|
+
expect(dependencies).toHaveProperty('@salesforce/pwa-kit-dev', 'unknown');
|
|
174
|
+
}));
|
|
175
|
+
test('should return pwa-kit packages with version in dependency tree', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
176
|
+
const dependencies = yield scriptUtils.getPwaKitDependencies(dependencyTreeMockData.includesPwaKitPackages);
|
|
177
|
+
expect(Object.keys(dependencies)).toHaveLength(3);
|
|
178
|
+
expect(dependencies).toHaveProperty('@salesforce/pwa-kit-react-sdk', '1.0.0');
|
|
179
|
+
expect(dependencies).toHaveProperty('@salesforce/pwa-kit-runtime', '1.0.0');
|
|
180
|
+
expect(dependencies).toHaveProperty('@salesforce/pwa-kit-dev', '1.0.0');
|
|
181
|
+
}));
|
|
182
|
+
});
|
|
183
|
+
describe('getProjectDependencyTree', () => {
|
|
184
|
+
let originalCwd;
|
|
185
|
+
beforeAll(() => {
|
|
186
|
+
originalCwd = process.cwd();
|
|
187
|
+
});
|
|
188
|
+
afterEach(() => process.chdir(originalCwd));
|
|
189
|
+
test('works in retail-react-app', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
190
|
+
expect(yield scriptUtils.getProjectDependencyTree()).toMatchObject({
|
|
191
|
+
name: '@salesforce/pwa-kit-dev',
|
|
192
|
+
version: pkg.version,
|
|
193
|
+
dependencies: expect.any(Object)
|
|
194
|
+
});
|
|
195
|
+
}), 10_000); // This test can take a while on CI
|
|
196
|
+
test('returns nothing if an error occurs', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
197
|
+
_child_process.execSync.mockImplementation(() => {
|
|
198
|
+
throw new Error('npm ls did not work');
|
|
199
|
+
});
|
|
200
|
+
expect(yield scriptUtils.getProjectDependencyTree()).toBeNull();
|
|
201
|
+
}));
|
|
202
|
+
});
|
|
203
|
+
describe('defaultMessage', () => {
|
|
204
|
+
test('works', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
205
|
+
const mockGit = {
|
|
206
|
+
branch: () => 'branch',
|
|
207
|
+
short: () => 'short'
|
|
208
|
+
};
|
|
209
|
+
expect(scriptUtils.defaultMessage(mockGit)).toBe('branch: short');
|
|
210
|
+
}));
|
|
211
|
+
test('works outside of a git repo', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
212
|
+
const mockGit = {
|
|
213
|
+
branch: () => {
|
|
214
|
+
throw {
|
|
215
|
+
code: 'ENOENT'
|
|
216
|
+
};
|
|
217
|
+
},
|
|
218
|
+
short: () => 'short'
|
|
219
|
+
};
|
|
220
|
+
expect(scriptUtils.defaultMessage(mockGit)).toBe('PWA Kit Bundle');
|
|
221
|
+
}));
|
|
222
|
+
test('works with any other error', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
223
|
+
const mockGit = {
|
|
224
|
+
branch: () => {
|
|
225
|
+
throw new Error();
|
|
226
|
+
},
|
|
227
|
+
short: () => 'short'
|
|
228
|
+
};
|
|
229
|
+
expect(scriptUtils.defaultMessage(mockGit)).toBe('PWA Kit Bundle');
|
|
230
|
+
}));
|
|
231
|
+
});
|
|
232
|
+
test('getCredentialsFile', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
233
|
+
expect(scriptUtils.getCredentialsFile('https://example.com', '/path/to/.mobify')).toBe('/path/to/.mobify');
|
|
234
|
+
expect(scriptUtils.getCredentialsFile('https://example.com', undefined)).toBe(_path.default.join(_os.default.homedir(), '.mobify--example.com'));
|
|
235
|
+
expect(scriptUtils.getCredentialsFile('https://cloud.mobify.com', undefined)).toBe(_path.default.join(_os.default.homedir(), '.mobify'));
|
|
236
|
+
}));
|
|
237
|
+
describe('readCredentials', () => {
|
|
238
|
+
test('should work', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
239
|
+
_fsExtra.readJson.mockReturnValue({
|
|
240
|
+
username: 'alice',
|
|
241
|
+
api_key: 'xyz'
|
|
242
|
+
});
|
|
243
|
+
const creds = {
|
|
244
|
+
username: 'alice',
|
|
245
|
+
api_key: 'xyz'
|
|
246
|
+
};
|
|
247
|
+
const thePath = _path.default.join(tmpDir, '.mobify.test');
|
|
248
|
+
yield (0, _fsExtra.writeFile)(thePath, JSON.stringify(creds), 'utf8');
|
|
249
|
+
expect(yield scriptUtils.readCredentials(thePath)).toEqual(creds);
|
|
250
|
+
}));
|
|
251
|
+
test('should throw', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
252
|
+
const thePath = _path.default.join(tmpDir, '.mobify.test');
|
|
253
|
+
yield expect( /*#__PURE__*/_asyncToGenerator(function* () {
|
|
254
|
+
return yield scriptUtils.readCredentials(thePath);
|
|
255
|
+
})).rejects.toThrow(Error);
|
|
256
|
+
}));
|
|
257
|
+
});
|
|
258
|
+
describe('createBundle', () => {
|
|
259
|
+
test('should throw if ssr_only and ssr_shared is empty', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
260
|
+
yield expect( /*#__PURE__*/_asyncToGenerator(function* () {
|
|
261
|
+
return yield scriptUtils.createBundle({
|
|
262
|
+
message: null,
|
|
263
|
+
ssr_parameters: {},
|
|
264
|
+
ssr_only: [],
|
|
265
|
+
ssr_shared: [],
|
|
266
|
+
buildDirectory: tmpDir,
|
|
267
|
+
projectSlug: 'slug'
|
|
268
|
+
});
|
|
269
|
+
})).rejects.toThrow('no ssrOnly or ssrShared files are defined');
|
|
270
|
+
}));
|
|
271
|
+
test('should throw buildDir does not exist', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
272
|
+
yield expect( /*#__PURE__*/_asyncToGenerator(function* () {
|
|
273
|
+
return yield scriptUtils.createBundle({
|
|
274
|
+
message: null,
|
|
275
|
+
ssr_parameters: {},
|
|
276
|
+
ssr_only: ['*.js'],
|
|
277
|
+
ssr_shared: ['*.js'],
|
|
278
|
+
buildDirectory: _path.default.join(tmpDir, 'does-not-exist'),
|
|
279
|
+
projectSlug: 'slug'
|
|
280
|
+
});
|
|
281
|
+
})).rejects.toThrow('Build directory at path');
|
|
282
|
+
}));
|
|
283
|
+
test('should archive a bundle', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
284
|
+
_fsExtra.readJson.mockReturnValue(pkg);
|
|
285
|
+
_child_process.execSync.mockReturnValue(JSON.stringify(dependencyTreeMockData.noPwaKitPackages));
|
|
286
|
+
const message = 'message';
|
|
287
|
+
const bundle = yield scriptUtils.createBundle({
|
|
288
|
+
message,
|
|
289
|
+
ssr_parameters: {},
|
|
290
|
+
ssr_only: ['*.js'],
|
|
291
|
+
ssr_shared: ['**/*.*'],
|
|
292
|
+
buildDirectory: _path.default.join(__dirname, 'test-fixtures', 'minimal-built-app'),
|
|
293
|
+
projectSlug: 'slug'
|
|
294
|
+
});
|
|
295
|
+
expect(bundle.message).toEqual(message);
|
|
296
|
+
expect(bundle.encoding).toBe('base64');
|
|
297
|
+
expect(bundle.ssr_parameters).toEqual({});
|
|
298
|
+
expect(bundle.ssr_only).toEqual(['ssr.js']);
|
|
299
|
+
expect(bundle.ssr_shared).toEqual(['ssr.js', 'static/favicon.ico']);
|
|
300
|
+
expect(bundle.bundle_metadata).toHaveProperty('dependencies');
|
|
301
|
+
expect(bundle.bundle_metadata).toHaveProperty('cc_overrides');
|
|
302
|
+
|
|
303
|
+
// De-code and re-encode gives the same result, to show that it *is* b64 encoded
|
|
304
|
+
expect(Buffer.from(bundle.data, 'base64').toString('base64')).toEqual(bundle.data);
|
|
305
|
+
}));
|
|
306
|
+
});
|
|
307
|
+
describe('pushBundle', () => {
|
|
308
|
+
test.each([[{
|
|
309
|
+
projectSlug: 'project-slug',
|
|
310
|
+
targetSlug: undefined,
|
|
311
|
+
expectedURL: 'https://cloud.mobify.com/api/projects/project-slug/builds/',
|
|
312
|
+
status: 200
|
|
313
|
+
}], [{
|
|
314
|
+
projectSlug: 'project-slug',
|
|
315
|
+
targetSlug: 'target-slug',
|
|
316
|
+
expectedURL: 'https://cloud.mobify.com/api/projects/project-slug/builds/target-slug/',
|
|
317
|
+
status: 200
|
|
318
|
+
}], [{
|
|
319
|
+
projectSlug: 'project-slug',
|
|
320
|
+
targetSlug: undefined,
|
|
321
|
+
expectedURL: 'https://cloud.mobify.com/api/projects/project-slug/builds/',
|
|
322
|
+
status: 401
|
|
323
|
+
}]])('should push a built bundle and handle status codes (%p)', /*#__PURE__*/function () {
|
|
324
|
+
var _ref31 = _asyncToGenerator(function* ({
|
|
325
|
+
projectSlug,
|
|
326
|
+
targetSlug,
|
|
327
|
+
expectedURL,
|
|
328
|
+
status
|
|
329
|
+
}) {
|
|
330
|
+
_fsExtra.readJson.mockReturnValue(pkg);
|
|
331
|
+
_child_process.execSync.mockReturnValue(JSON.stringify(dependencyTreeMockData.noPwaKitPackages));
|
|
332
|
+
const message = 'message';
|
|
333
|
+
const bundle = yield scriptUtils.createBundle({
|
|
334
|
+
message,
|
|
335
|
+
ssr_parameters: {},
|
|
336
|
+
ssr_only: ['*.js'],
|
|
337
|
+
ssr_shared: ['**/*.*'],
|
|
338
|
+
buildDirectory: _path.default.join(__dirname, 'test-fixtures', 'minimal-built-app'),
|
|
339
|
+
projectSlug
|
|
340
|
+
});
|
|
341
|
+
const username = 'user123';
|
|
342
|
+
const api_key = '123';
|
|
343
|
+
const credentials = {
|
|
344
|
+
username,
|
|
345
|
+
api_key
|
|
346
|
+
};
|
|
347
|
+
const goodResponseBody = {
|
|
348
|
+
anything: 'anything'
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
// Older APIs on Cloud return JSON for good responses and text for errors,
|
|
352
|
+
// hence the strange looking mock response setup.
|
|
353
|
+
const text = () => status === 200 ? Promise.resolve(JSON.stringify(goodResponseBody)) : Promise.resolve('An error occurred');
|
|
354
|
+
const json = () => status === 200 ? Promise.resolve(goodResponseBody) : Promise.reject();
|
|
355
|
+
const responseMock = {
|
|
356
|
+
status,
|
|
357
|
+
text,
|
|
358
|
+
json
|
|
359
|
+
};
|
|
360
|
+
const fetchMock = jest.fn( /*#__PURE__*/_asyncToGenerator(function* () {
|
|
361
|
+
return responseMock;
|
|
362
|
+
}));
|
|
363
|
+
const client = new scriptUtils.CloudAPIClient({
|
|
364
|
+
credentials,
|
|
365
|
+
fetch: fetchMock
|
|
366
|
+
});
|
|
367
|
+
const fn = /*#__PURE__*/function () {
|
|
368
|
+
var _ref33 = _asyncToGenerator(function* () {
|
|
369
|
+
return yield client.push(bundle, projectSlug, targetSlug);
|
|
370
|
+
});
|
|
371
|
+
return function fn() {
|
|
372
|
+
return _ref33.apply(this, arguments);
|
|
373
|
+
};
|
|
374
|
+
}();
|
|
375
|
+
|
|
376
|
+
// TODO: Split up this batch of tests to avoid conditional assertions
|
|
377
|
+
if (status === 200) {
|
|
378
|
+
// eslint-disable-next-line jest/no-conditional-expect
|
|
379
|
+
expect(yield fn()).toBe(goodResponseBody);
|
|
380
|
+
} else {
|
|
381
|
+
// eslint-disable-next-line jest/no-conditional-expect
|
|
382
|
+
yield expect(fn).rejects.toThrow('For more information visit');
|
|
383
|
+
}
|
|
384
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
385
|
+
expect(fetchMock).toHaveBeenCalledWith(expectedURL, expect.objectContaining({
|
|
386
|
+
body: expect.anything(Buffer),
|
|
387
|
+
method: 'POST',
|
|
388
|
+
headers: {
|
|
389
|
+
Authorization: expect.stringMatching(/^Basic /),
|
|
390
|
+
'Content-Length': expect.stringMatching(/^\d+$/),
|
|
391
|
+
'User-Agent': `${pkg.name}@${pkg.version}`
|
|
392
|
+
}
|
|
393
|
+
}));
|
|
394
|
+
});
|
|
395
|
+
return function (_x) {
|
|
396
|
+
return _ref31.apply(this, arguments);
|
|
397
|
+
};
|
|
398
|
+
}());
|
|
399
|
+
});
|
|
400
|
+
describe('createLoggingToken', () => {
|
|
401
|
+
const username = 'user123';
|
|
402
|
+
const api_key = '123';
|
|
403
|
+
test('createLoggingToken passes', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
404
|
+
_fsExtra.readJson.mockReturnValue(pkg);
|
|
405
|
+
const projectSlug = 'project-slug';
|
|
406
|
+
const targetSlug = 'target-slug';
|
|
407
|
+
const text = () => Promise.resolve(JSON.stringify({
|
|
408
|
+
token: 'token-value'
|
|
409
|
+
}));
|
|
410
|
+
const json = () => Promise.resolve({
|
|
411
|
+
token: 'token-value'
|
|
412
|
+
});
|
|
413
|
+
const fetchMock = jest.fn( /*#__PURE__*/_asyncToGenerator(function* () {
|
|
414
|
+
return {
|
|
415
|
+
status: 200,
|
|
416
|
+
text,
|
|
417
|
+
json
|
|
418
|
+
};
|
|
419
|
+
}));
|
|
420
|
+
const client = new scriptUtils.CloudAPIClient({
|
|
421
|
+
credentials: {
|
|
422
|
+
username,
|
|
423
|
+
api_key
|
|
424
|
+
},
|
|
425
|
+
fetch: fetchMock
|
|
426
|
+
});
|
|
427
|
+
const fn = /*#__PURE__*/function () {
|
|
428
|
+
var _ref36 = _asyncToGenerator(function* () {
|
|
429
|
+
return yield client.createLoggingToken(projectSlug, targetSlug);
|
|
430
|
+
});
|
|
431
|
+
return function fn() {
|
|
432
|
+
return _ref36.apply(this, arguments);
|
|
433
|
+
};
|
|
434
|
+
}();
|
|
435
|
+
expect(yield fn()).toBe('token-value');
|
|
436
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
437
|
+
expect(fetchMock).toHaveBeenCalledWith('https://cloud.mobify.com/api/projects/project-slug/target/target-slug/jwt/', expect.objectContaining({
|
|
438
|
+
method: 'POST',
|
|
439
|
+
headers: {
|
|
440
|
+
Authorization: expect.stringMatching(/^Bearer /),
|
|
441
|
+
'User-Agent': `${pkg.name}@${pkg.version}`
|
|
442
|
+
}
|
|
443
|
+
}));
|
|
444
|
+
}));
|
|
445
|
+
});
|
|
446
|
+
describe('parseLog', () => {
|
|
447
|
+
it('correctly parses an application log', () => {
|
|
448
|
+
const log = '2023-07-15T10:00:00Z\t550e8400-e29b-41d4-a716-446655440000\tINFO\tThis is a test log message';
|
|
449
|
+
const result = scriptUtils.parseLog(log);
|
|
450
|
+
expect(result).toEqual({
|
|
451
|
+
level: 'INFO',
|
|
452
|
+
message: 'This is a test log message',
|
|
453
|
+
shortRequestId: '550e8400'
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
it('correctly parses a platform log', () => {
|
|
457
|
+
const log = 'WARN\tThis is a test log message';
|
|
458
|
+
const result = scriptUtils.parseLog(log);
|
|
459
|
+
expect(result).toEqual({
|
|
460
|
+
level: 'WARN',
|
|
461
|
+
message: '\tThis is a test log message',
|
|
462
|
+
shortRequestId: undefined
|
|
463
|
+
});
|
|
464
|
+
});
|
|
465
|
+
it('finds the shortRequestId in the message if not present in the request id', () => {
|
|
466
|
+
const log = 'INFO\tThis is a test log message 550e8400';
|
|
467
|
+
const result = scriptUtils.parseLog(log);
|
|
468
|
+
expect(result).toEqual({
|
|
469
|
+
level: 'INFO',
|
|
470
|
+
message: '\tThis is a test log message 550e8400',
|
|
471
|
+
shortRequestId: '550e8400'
|
|
472
|
+
});
|
|
473
|
+
});
|
|
474
|
+
});
|
|
475
|
+
describe('walkDir', () => {
|
|
476
|
+
const files = ['a', 'b/1', 'b/2', 'c/d/e'].map(_path.default.normalize);
|
|
477
|
+
beforeEach( /*#__PURE__*/_asyncToGenerator(function* () {
|
|
478
|
+
yield Promise.all(files.map( /*#__PURE__*/function () {
|
|
479
|
+
var _ref38 = _asyncToGenerator(function* (file) {
|
|
480
|
+
return yield (0, _fsExtra.createFile)(_path.default.join(tmpDir, file));
|
|
481
|
+
});
|
|
482
|
+
return function (_x2) {
|
|
483
|
+
return _ref38.apply(this, arguments);
|
|
484
|
+
};
|
|
485
|
+
}()));
|
|
486
|
+
}));
|
|
487
|
+
test('finds all files in a directory', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
488
|
+
const result = yield scriptUtils.walkDir(tmpDir, tmpDir);
|
|
489
|
+
expect([...result]).toEqual(files);
|
|
490
|
+
}));
|
|
491
|
+
test('returns file relative to specified path', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
492
|
+
const result = yield scriptUtils.walkDir(tmpDir, '/');
|
|
493
|
+
expect([...result]).toEqual(files.map(f => _path.default.join(tmpDir, f)));
|
|
494
|
+
}));
|
|
495
|
+
});
|
|
496
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2021, Salesforce, Inc.
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// This file needs to exist as a text fixture, but doesn't need content!
|
|
9
|
+
"use strict";
|
|
Binary file
|