@squiz/edge-dev-render-runtime-lib 2.5.4 → 2.5.5
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/lib/index.js +59 -35
- package/lib/index.js.map +3 -3
- package/lib/public/docs.json +1 -1
- package/package.json +1 -2
package/lib/index.js
CHANGED
|
@@ -3375,24 +3375,26 @@ function generateRandomName() {
|
|
|
3375
3375
|
}
|
|
3376
3376
|
|
|
3377
3377
|
// src/webserver/controllers/test/render-route-tests.ts
|
|
3378
|
-
var import_dxp_session_lib = require("@squiz/dxp-session-lib");
|
|
3379
|
-
var mockedSession = (0, import_dxp_session_lib.buildDevelopmentSession)({
|
|
3380
|
-
version: import_dxp_session_lib.DxpSessionVersion.version1
|
|
3381
|
-
});
|
|
3382
3378
|
function renderRouteTests(request, _rootUrl) {
|
|
3383
3379
|
describe("GET /dev/render/unit-test-components__test-component__1.0.10/?_componentSet=set", () => {
|
|
3384
3380
|
it("should render the test component with html endpoint", async () => {
|
|
3385
|
-
const response = await request().get(
|
|
3381
|
+
const response = await request().get(
|
|
3382
|
+
"/dev/render/unit-test-components__test-component__1.0.10?_componentSet=set&something=unused"
|
|
3383
|
+
);
|
|
3386
3384
|
expect(response.text).toEqual("<div>hello - {}</div>");
|
|
3387
3385
|
expect(response.statusCode).toEqual(200);
|
|
3388
3386
|
}, 2e4);
|
|
3389
3387
|
it("should render the test component promise endpoint with html endpoint", async () => {
|
|
3390
|
-
const response = await request().get(
|
|
3388
|
+
const response = await request().get(
|
|
3389
|
+
"/dev/render/unit-test-components__test-component__1.0.10/promise?_componentSet=set&something=unused"
|
|
3390
|
+
);
|
|
3391
3391
|
expect(response.statusCode).toEqual(200);
|
|
3392
3392
|
expect(response.text).toEqual("<h1>hello</h1>");
|
|
3393
3393
|
}, 2e4);
|
|
3394
3394
|
it("should fail validation if input contract is not met and helpful message returned", async () => {
|
|
3395
|
-
const response = await request().get(
|
|
3395
|
+
const response = await request().get(
|
|
3396
|
+
"/dev/render/unit-test-components__test-component__1.0.0?_componentSet=set&something=unused"
|
|
3397
|
+
);
|
|
3396
3398
|
expect(response.statusCode).toEqual(400);
|
|
3397
3399
|
expect(response.body).toMatchInlineSnapshot(`
|
|
3398
3400
|
{
|
|
@@ -3403,7 +3405,7 @@ function renderRouteTests(request, _rootUrl) {
|
|
|
3403
3405
|
it("should 404 if requesting a non-existent function on an otherwise valid component", async () => {
|
|
3404
3406
|
const response = await request().get(
|
|
3405
3407
|
"/dev/render/unit-test-components__test-component__1.0.0/non-existent-entry-file?_componentSet=set&something=not-used"
|
|
3406
|
-
)
|
|
3408
|
+
);
|
|
3407
3409
|
expect(response.statusCode).toEqual(404);
|
|
3408
3410
|
expect(response.body).toMatchInlineSnapshot(`
|
|
3409
3411
|
{
|
|
@@ -3414,7 +3416,9 @@ function renderRouteTests(request, _rootUrl) {
|
|
|
3414
3416
|
});
|
|
3415
3417
|
describe("GET /dev/render/unit-test-components__test-component__1.0.3/main?_componentSet=set", () => {
|
|
3416
3418
|
it("should fail validation when requesting a function with a missing entry file", async () => {
|
|
3417
|
-
const response = await request().get(
|
|
3419
|
+
const response = await request().get(
|
|
3420
|
+
"/dev/render/unit-test-components__test-component__1.0.3/main?_componentSet=set&something=not-used"
|
|
3421
|
+
);
|
|
3418
3422
|
expect(response.body).toEqual({
|
|
3419
3423
|
message: `"main's" entry file "missing-entry-file.js" is inaccessible`
|
|
3420
3424
|
});
|
|
@@ -3423,7 +3427,7 @@ function renderRouteTests(request, _rootUrl) {
|
|
|
3423
3427
|
});
|
|
3424
3428
|
describe("GET /dev/render/unit-test-components__test-component__1.0.4?_componentSet=set", () => {
|
|
3425
3429
|
it("should render a simple json endpoint", async () => {
|
|
3426
|
-
const response = await request().get("/dev/render/unit-test-components__test-component__1.0.4?_componentSet=set")
|
|
3430
|
+
const response = await request().get("/dev/render/unit-test-components__test-component__1.0.4?_componentSet=set");
|
|
3427
3431
|
expect(response.headers["content-type"]).toContain("application/json");
|
|
3428
3432
|
expect(response.body).toEqual({
|
|
3429
3433
|
"my-prop": "test value for my-prop",
|
|
@@ -3436,7 +3440,9 @@ function renderRouteTests(request, _rootUrl) {
|
|
|
3436
3440
|
});
|
|
3437
3441
|
}, 2e4);
|
|
3438
3442
|
it("should report error if response does not match with the schema", async () => {
|
|
3439
|
-
const response = await request().get(
|
|
3443
|
+
const response = await request().get(
|
|
3444
|
+
"/dev/render/unit-test-components__test-component__1.0.4/render_json_invalid?_componentSet=set"
|
|
3445
|
+
);
|
|
3440
3446
|
expect(response.statusCode).toEqual(500);
|
|
3441
3447
|
expect(response.headers["content-type"]).toEqual("application/json; charset=utf-8");
|
|
3442
3448
|
expect(response.body).toEqual({
|
|
@@ -3446,7 +3452,7 @@ function renderRouteTests(request, _rootUrl) {
|
|
|
3446
3452
|
it("should validate a complex json against a schema", async () => {
|
|
3447
3453
|
const response = await request().get(
|
|
3448
3454
|
"/dev/render/unit-test-components__test-component__1.0.4/render_json_nested_object_valid?_componentSet=set"
|
|
3449
|
-
)
|
|
3455
|
+
);
|
|
3450
3456
|
const myObject = {
|
|
3451
3457
|
"my-object": {
|
|
3452
3458
|
"a-string": "this is a string",
|
|
@@ -3462,7 +3468,7 @@ function renderRouteTests(request, _rootUrl) {
|
|
|
3462
3468
|
it("should report errors if nested object json schema fails", async () => {
|
|
3463
3469
|
const response = await request().get(
|
|
3464
3470
|
"/dev/render/unit-test-components__test-component__1.0.4/render_json_nested_object_invalid?_componentSet=set"
|
|
3465
|
-
)
|
|
3471
|
+
);
|
|
3466
3472
|
expect(response.statusCode).toEqual(500);
|
|
3467
3473
|
expect(response.headers["content-type"]).toEqual("application/json; charset=utf-8");
|
|
3468
3474
|
expect(response.body).toEqual({
|
|
@@ -3475,7 +3481,7 @@ Expected given value \`N\` in #/my-object/a-nested-object/an-enum\` to be one of
|
|
|
3475
3481
|
it('should return input and info object with "query parameters"', async () => {
|
|
3476
3482
|
const response = await request().get(
|
|
3477
3483
|
"/dev/render/unit-test-components__test-component__1.0.7?_componentSet=set&something=hello-test&foo=foo-val&foo2=foo2-val"
|
|
3478
|
-
)
|
|
3484
|
+
);
|
|
3479
3485
|
expect(response.headers["content-type"]).toContain("application/json");
|
|
3480
3486
|
const result = response.body;
|
|
3481
3487
|
expect(result).toEqual([
|
|
@@ -3553,14 +3559,18 @@ Expected given value \`N\` in #/my-object/a-nested-object/an-enum\` to be one of
|
|
|
3553
3559
|
});
|
|
3554
3560
|
});
|
|
3555
3561
|
it("should throw error if required query parameter is missing", async () => {
|
|
3556
|
-
const response = await request().get(
|
|
3562
|
+
const response = await request().get(
|
|
3563
|
+
"/dev/render/unit-test-components__test-component__1.0.7?_componentSet=set&foo2=foo2-val"
|
|
3564
|
+
);
|
|
3557
3565
|
expect(response.body).toEqual({
|
|
3558
3566
|
message: "Required query parameter 'foo' is missing"
|
|
3559
3567
|
});
|
|
3560
3568
|
expect(response.statusCode).toEqual(400);
|
|
3561
3569
|
});
|
|
3562
3570
|
it("should throw error if query parameter is not a string", async () => {
|
|
3563
|
-
const response = await request().get(
|
|
3571
|
+
const response = await request().get(
|
|
3572
|
+
"/dev/render/unit-test-components__test-component__1.0.7?_componentSet=set&foo=123&foo2[]=array-val"
|
|
3573
|
+
);
|
|
3564
3574
|
expect(response.body).toEqual({
|
|
3565
3575
|
message: "Value for query parameter 'foo2' must be a string"
|
|
3566
3576
|
});
|
|
@@ -3568,48 +3578,60 @@ Expected given value \`N\` in #/my-object/a-nested-object/an-enum\` to be one of
|
|
|
3568
3578
|
});
|
|
3569
3579
|
describe("GET /dev/render/unit-test-components__test-headers__1.0.3?_componentSet=set", () => {
|
|
3570
3580
|
it("should make sure max-age header is clamped between max value", async () => {
|
|
3571
|
-
const response = await request().get("/dev/render/unit-test-components__test-headers__1.0.3/max_value?_componentSet=set").
|
|
3581
|
+
const response = await request().get("/dev/render/unit-test-components__test-headers__1.0.3/max_value?_componentSet=set").send().expect(200, "rendered");
|
|
3572
3582
|
expect(response.headers["cache-control"]).toEqual("max-age=1800, immutable");
|
|
3573
3583
|
});
|
|
3574
3584
|
it("should make sure max-age header is clamped between min value", async () => {
|
|
3575
|
-
const response = await request().get("/dev/render/unit-test-components__test-headers__1.0.3/min_value?_componentSet=set").
|
|
3585
|
+
const response = await request().get("/dev/render/unit-test-components__test-headers__1.0.3/min_value?_componentSet=set").send().expect(200, "rendered");
|
|
3576
3586
|
expect(response.headers["cache-control"]).toEqual("max-age=30, public");
|
|
3577
3587
|
});
|
|
3578
3588
|
});
|
|
3579
3589
|
describe("should be able to load external dependencies", () => {
|
|
3580
3590
|
it("should be able to make web requests out", async () => {
|
|
3581
|
-
const response = await request().get(
|
|
3591
|
+
const response = await request().get(
|
|
3592
|
+
"/dev/render/unit-test-components__test-npm-modules__3.0.0?_componentSet=set"
|
|
3593
|
+
);
|
|
3582
3594
|
expect(response.statusCode).toEqual(200);
|
|
3583
3595
|
expect(response.text).toContain(`<h1>Example Domain</h1>`);
|
|
3584
3596
|
});
|
|
3585
3597
|
});
|
|
3586
3598
|
describe("GET /dev/render/unit-test-components__test-formatted-text__1.0.0", () => {
|
|
3587
3599
|
it("should render a component formattedText in preview inline", async () => {
|
|
3588
|
-
const response = await request().get(
|
|
3600
|
+
const response = await request().get(
|
|
3601
|
+
"/dev/render/unit-test-components__test-formatted-text__1.0.0?_previewKey=valid-inline-preview"
|
|
3602
|
+
);
|
|
3589
3603
|
expect(response.statusCode).toEqual(200);
|
|
3590
3604
|
expect(response.text).toMatchInlineSnapshot(`"This is a test"`);
|
|
3591
3605
|
});
|
|
3592
3606
|
});
|
|
3593
3607
|
describe("GET /dev/render/unit-test-components__test-npm-modules__3.1.0", () => {
|
|
3594
3608
|
it("should render a component with uuid", async () => {
|
|
3595
|
-
const response = await request().get(
|
|
3609
|
+
const response = await request().get(
|
|
3610
|
+
"/dev/render/unit-test-components__test-npm-modules__3.1.0/uuid?_componentSet=set"
|
|
3611
|
+
);
|
|
3596
3612
|
expect(response.statusCode).toEqual(200);
|
|
3597
3613
|
});
|
|
3598
3614
|
it("should render a component with Buffer", async () => {
|
|
3599
|
-
const response = await request().get(
|
|
3615
|
+
const response = await request().get(
|
|
3616
|
+
"/dev/render/unit-test-components__test-npm-modules__3.1.0/buffer?_componentSet=set"
|
|
3617
|
+
);
|
|
3600
3618
|
expect(response.statusCode).toEqual(200);
|
|
3601
3619
|
});
|
|
3602
3620
|
});
|
|
3603
3621
|
describe("GET /dev/render/unit-test-components__test-squiz-image__1.0.0", () => {
|
|
3604
3622
|
it("should render the preview", async () => {
|
|
3605
|
-
const response = await request().get(
|
|
3623
|
+
const response = await request().get(
|
|
3624
|
+
"/dev/render/unit-test-components__test-squiz-image__1.0.0?_previewKey=valid-inline-preview"
|
|
3625
|
+
);
|
|
3606
3626
|
expect(response.statusCode).toEqual(200);
|
|
3607
3627
|
expect(response.text).toMatchInlineSnapshot(`"My Image Component"`);
|
|
3608
3628
|
});
|
|
3609
3629
|
});
|
|
3610
3630
|
describe("GET /dev/render/unit-test-components__test-squiz-link__1.0.0", () => {
|
|
3611
3631
|
it("should render the preview", async () => {
|
|
3612
|
-
const response = await request().get(
|
|
3632
|
+
const response = await request().get(
|
|
3633
|
+
"/dev/render/unit-test-components__test-squiz-link__1.0.0?_previewKey=valid-inline-preview"
|
|
3634
|
+
);
|
|
3613
3635
|
expect(response.statusCode).toEqual(200);
|
|
3614
3636
|
expect(response.text).toMatchInlineSnapshot(`"{"link":{"text":"My Link","url":"https://some.link/foo"}}"`);
|
|
3615
3637
|
});
|
|
@@ -3617,20 +3639,16 @@ Expected given value \`N\` in #/my-object/a-nested-object/an-enum\` to be one of
|
|
|
3617
3639
|
}
|
|
3618
3640
|
|
|
3619
3641
|
// src/webserver/controllers/test/preview-route-tests.ts
|
|
3620
|
-
var import_dxp_session_lib2 = require("@squiz/dxp-session-lib");
|
|
3621
|
-
var mockedSession2 = (0, import_dxp_session_lib2.buildDevelopmentSession)({
|
|
3622
|
-
version: import_dxp_session_lib2.DxpSessionVersion.version1
|
|
3623
|
-
});
|
|
3624
3642
|
function previewRouteTests(request, _rootUrl = "${rootUrl}") {
|
|
3625
3643
|
describe("preview routes", () => {
|
|
3626
3644
|
it("should render a preview of a component with no wrapper file", async () => {
|
|
3627
|
-
await request().get("/dev/render/unit-test-components__test-preview-component__1.2.4?_previewKey=test-preview").
|
|
3645
|
+
await request().get("/dev/render/unit-test-components__test-preview-component__1.2.4?_previewKey=test-preview").expect(200).expect("content-type", "text/html; charset=utf-8").expect("800 | this is nested content");
|
|
3628
3646
|
});
|
|
3629
3647
|
it("should render a preview of a component with a different preset", async () => {
|
|
3630
|
-
await request().get("/dev/render/unit-test-components__test-preview-component__1.2.4?_previewKey=another-preview").
|
|
3648
|
+
await request().get("/dev/render/unit-test-components__test-preview-component__1.2.4?_previewKey=another-preview").expect(200).expect("content-type", "text/html; charset=utf-8").expect("12300 | this is also nested content");
|
|
3631
3649
|
});
|
|
3632
3650
|
it("should render a preview of a component non-main function with a wrapper html file", async () => {
|
|
3633
|
-
await request().get("/dev/render/unit-test-components__test-preview-component__1.2.4/other?_previewKey=another-preview").
|
|
3651
|
+
await request().get("/dev/render/unit-test-components__test-preview-component__1.2.4/other?_previewKey=another-preview").expect(200).expect("content-type", "text/html; charset=utf-8").expect((a) => {
|
|
3634
3652
|
expect(a.text).toMatchInlineSnapshot(`
|
|
3635
3653
|
"<!DOCTYPE html>
|
|
3636
3654
|
<html lang="en">
|
|
@@ -3649,24 +3667,30 @@ function previewRouteTests(request, _rootUrl = "${rootUrl}") {
|
|
|
3649
3667
|
});
|
|
3650
3668
|
});
|
|
3651
3669
|
it("should load the defined preview for a given preview key", async () => {
|
|
3652
|
-
const response = await request().get(
|
|
3670
|
+
const response = await request().get(
|
|
3671
|
+
"/dev/render/unit-test-components__test-preview-component__1.0.3?_previewKey=second-preview"
|
|
3672
|
+
);
|
|
3653
3673
|
expect(response.text).toContain(`<p>Second Preview</p>`);
|
|
3654
3674
|
expect(response.statusCode).toEqual(200);
|
|
3655
3675
|
});
|
|
3656
3676
|
it("should give meaningful error when preview key is invalid", async () => {
|
|
3657
|
-
const response = await request().get(
|
|
3677
|
+
const response = await request().get(
|
|
3678
|
+
"/dev/render/unit-test-components__test-preview-component__1.0.3?_previewKey=invalid"
|
|
3679
|
+
);
|
|
3658
3680
|
expect(response.text).toEqual(
|
|
3659
3681
|
`{"message":"Component has not defined preview with key \\"invalid\\", the defined preview keys for this component are \\"first-preview, second-preview, test-preview\\""}`
|
|
3660
3682
|
);
|
|
3661
3683
|
expect(response.statusCode).toEqual(404);
|
|
3662
3684
|
});
|
|
3663
3685
|
it("should render inline preview data through to component", async () => {
|
|
3664
|
-
const response = await request().get(
|
|
3686
|
+
const response = await request().get(
|
|
3687
|
+
"/dev/render/unit-test-components__test-preview-component__1.0.4?_previewKey=test-preview"
|
|
3688
|
+
);
|
|
3665
3689
|
expect(response.text).toContain(`this is a result | 123`);
|
|
3666
3690
|
expect(response.statusCode).toEqual(200);
|
|
3667
3691
|
}, 1e4);
|
|
3668
3692
|
it("should resolve URIs to mocked URI object in preview route", async () => {
|
|
3669
|
-
await request().get("/dev/render/unit-test-components__test-preview-component__1.1.1?_previewKey=test-preview").
|
|
3693
|
+
await request().get("/dev/render/unit-test-components__test-preview-component__1.1.1?_previewKey=test-preview").expect(200).expect((a) => {
|
|
3670
3694
|
expect(a.text).toMatchInlineSnapshot(`
|
|
3671
3695
|
"
|
|
3672
3696
|
inline:{"id":"id-inline","type":"root_folder","type_name":"Root Folder","version":"0.0.1","name":"Root Folder","short_name":"/","status":{"id":2,"code":"under_construction"},"created":{"date":"2020-02-27T09:47:27+11:00","user_id":null},"updated":{"date":"2020-02-27T09:47:27+11:00","user_id":""},"published":{"date":"2020-02-27T09:47:27+11:00","user_id":"null"},"status_changed":{"date":"2020-02-27T09:47:27+11:00","user_id":"null"},"url":"xxx","urls":[],"attributes":{"test":"test"},"additional":{}}
|