-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathbasic-test.js
189 lines (165 loc) · 4.77 KB
/
basic-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
"use strict";
const expect = require("chai").expect;
const fs = require("fs");
const path = require("path");
const FastBoot = require("fastboot");
const buildDist = require("../helpers/build-dist");
function dummyRequest() {
return {
protocol: "http",
url: "/foo",
headers: {
host: "localhost:4200",
cookie: "",
},
method: "GET",
};
}
function dummyResponse() {
return { _headers: {} };
}
describe("FastBoot", function() {
this.timeout(100000);
it("can render HTML", async function() {
const distPath = await buildDist("basic-app");
const fastboot = new FastBoot({
distPath,
});
// TODO: fastboot doesn't actually accept *only* distPath, it must receives request and response
const html = await fastboot
.visit("/", {
request: dummyRequest(),
response: dummyResponse(),
})
.then((r) => r.html());
expect(html).to.match(/Basic fastboot ember app/);
});
it("can run multiple visits", async function() {
const fastboot = new FastBoot({
distPath: await buildDist("basic-app"),
});
let html = await fastboot
.visit("/", {
request: dummyRequest(),
response: dummyResponse(),
})
.then((r) => r.html());
expect(html).to.match(/Basic fastboot ember app/);
html = await fastboot
.visit("/", {
request: dummyRequest(),
response: dummyResponse(),
})
.then((r) => r.html());
expect(html).to.match(/Basic fastboot ember app/);
html = await fastboot
.visit("/", {
request: dummyRequest(),
response: dummyResponse(),
})
.then((r) => r.html());
expect(html).to.match(/Basic fastboot ember app/);
});
it("cannot not render app HTML with shouldRender set as false", async function() {
const fastboot = new FastBoot({
distPath: await buildDist("basic-app"),
});
return fastboot
.visit("/", {
shouldRender: false,
request: dummyRequest(),
response: dummyResponse(),
})
.then((r) => r.html())
.then((html) => {
expect(html).to.not.match(/Basic fastboot ember app/);
});
});
it("can serialize the head and body", async function() {
const fastboot = new FastBoot({
distPath: await buildDist("basic-app"),
});
return fastboot
.visit("/", {
request: dummyRequest(),
response: dummyResponse(),
})
.then((r) => {
let contents = r.domContents();
expect(contents.head.trim()).to.equal(
`<meta name="ember-cli-head-start" content><meta property="og:title">\n<meta name="ember-cli-head-end" content>`
);
expect(contents.body).to.match(/Basic fastboot ember app/);
});
});
it("can forcefully destroy the app instance using destroyAppInstanceInMs", async function() {
const fastboot = new FastBoot({
distPath: await buildDist("basic-app"),
});
return fastboot
.visit("/", {
destroyAppInstanceInMs: 5,
request: dummyRequest(),
response: dummyResponse(),
})
.catch((e) => {
expect(e.message).to.equal(
"App instance was forcefully destroyed in 5ms"
);
});
});
it("can reload the distPath", async function() {
const distPath = await buildDist("basic-app");
const hotSwapAppPath = await buildDist("hot-swap-app");
let fastboot = new FastBoot({
distPath,
});
let html = await fastboot
.visit("/", {
request: dummyRequest(),
response: dummyResponse(),
})
.then((r) => r.html());
expect(html).to.match(/Basic fastboot ember app/);
fastboot.reload({
distPath: hotSwapAppPath,
});
html = await fastboot
.visit("/", {
request: dummyRequest(),
response: dummyResponse(),
})
.then((r) => r.html());
expect(html).to.match(/Hot swap ember app/);
});
it("can reload the app using the same buildSandboxGlobals", async function() {
const basicApp = await buildDist("basic-app");
const customSandbox = await buildDist("custom-sandbox-app");
const fastboot = new FastBoot({
distPath: basicApp,
buildSandboxGlobals(globals) {
return Object.assign({}, globals, {
foo: 5,
myVar: "undefined",
});
},
});
let html = await fastboot
.visit("/", {
request: dummyRequest(),
response: dummyResponse(),
})
.then((r) => r.html());
expect(html).to.match(/Basic fastboot ember app/);
fastboot.reload({
distPath: customSandbox,
});
html = await fastboot
.visit("/", {
request: dummyRequest(),
response: dummyResponse(),
})
.then((r) => r.html());
expect(html).to.match(/foo from sandbox: 5/);
});
});