-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathloaders-develop.ssr-import-attributes.spec.js
More file actions
193 lines (164 loc) · 5.46 KB
/
Copy pathloaders-develop.ssr-import-attributes.spec.js
File metadata and controls
193 lines (164 loc) · 5.46 KB
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
190
191
192
193
/*
* Use Case
* Run Greenwood develop command with no config.
*
* User Result
* Should start the development server and render a bare bones Greenwood build.
*
* User Command
* greenwood develop
*
* User Config
* {}
*
* User Workspace
* src/
* components/
* card/
* card.css
* card.js
* card.json
* pages/
* api/
* fragment.js
* greeting.js
* package.json
*/
import { expect } from "chai";
import { JSDOM } from "jsdom";
import path from "node:path";
import { Runner } from "gallinago";
import { fileURLToPath } from "node:url";
describe("Develop Greenwood With: ", function () {
const LABEL = "Import Attributes used in API Routes and SSR Pages";
const cliPath = path.join(process.cwd(), "packages/cli/src/bin.js");
const outputPath = fileURLToPath(new URL(".", import.meta.url));
const hostname = "http://127.0.0.1:1984";
let runner;
before(function () {
this.context = {
publicDir: path.join(outputPath, "public"),
};
runner = new Runner(false, true);
});
describe(LABEL, function () {
before(async function () {
await runner.setup(outputPath);
await new Promise((resolve, reject) => {
runner
.runCommand(cliPath, "develop", {
onStdOut: (message) => {
if (message.includes("Started local development server at http://localhost:1984")) {
resolve();
}
},
})
.catch(reject);
});
});
describe("CSS file is returned as CSS (text/css)", function () {
let response = {};
let body;
before(async function () {
response = await fetch(`${hostname}/components/card/card.css`);
body = await response.clone().text();
});
it("should return a 200 status", function (done) {
expect(response.status).to.equal(200);
done();
});
it("should return the correct content type", function (done) {
expect(response.headers.get("content-type")).to.equal("text/css");
done();
});
it("should return the correct response body", function (done) {
expect(body).to.equal(":host{color:red}");
done();
});
});
describe("JSON file is returned as JSON (application/json)", function () {
let response = {};
let data;
before(async function () {
response = await fetch(`${hostname}/components/card/card.json`);
data = await response.clone().json();
});
it("should return a 200 status", function (done) {
expect(response.status).to.equal(200);
done();
});
it("should return the correct content type", function (done) {
expect(response.headers.get("content-type")).to.equal("application/json");
done();
});
it("should return the correct response body data", function (done) {
expect(data.image.url).to.equal("/path/to/image.webp");
done();
});
});
describe('API Route specific behaviors for an HTML ("fragment") API', function () {
const name = "Greenwood";
let response = {};
let body;
before(async function () {
response = await fetch(`${hostname}/api/fragment?name=${name}`);
body = await response.clone().text();
});
it("should return a 200 status", function (done) {
expect(response.status).to.equal(200);
done();
});
it("should return the correct content type", function (done) {
expect(response.headers.get("content-type")).to.equal("text/html");
done();
});
it("should return the correct response body", function (done) {
const dom = new JSDOM(body);
const card = new JSDOM(
dom.window.document.querySelectorAll('app-card template[shadowrootmode="open"]')[0]
.innerHTML,
);
const heading = card.window.document.querySelector("h2");
const image = card.window.document.querySelector("img");
expect(heading.textContent).to.equal(`Hello, ${name}!`);
expect(image.getAttribute("href")).to.equal("/path/to/image.webp");
done();
});
});
describe("SSR route specific behaviors when using a custom element as the page", function () {
let response = {};
let body;
before(async function () {
response = await fetch(`${hostname}/greeting/`);
body = await response.clone().text();
});
it("should return a 200 status", function (done) {
expect(response.status).to.equal(200);
done();
});
it("should return the correct content type", function (done) {
expect(response.headers.get("content-type")).to.equal("text/html");
done();
});
it("should return the correct response body", function (done) {
const dom = new JSDOM(body);
const card = new JSDOM(
dom.window.document.querySelectorAll('app-card template[shadowrootmode="open"]')[0]
.innerHTML,
);
const heading = card.window.document.querySelector("h2");
const image = card.window.document.querySelector("img");
expect(heading.textContent).to.equal("Hello, World!");
expect(image.getAttribute("href")).to.equal("/path/to/image.webp");
done();
});
});
});
after(async function () {
await runner.stopCommand();
await runner.teardown([
path.join(outputPath, ".greenwood"),
path.join(outputPath, "node_modules"),
]);
});
});