-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy paththeme-pack.develop.spec.js
More file actions
170 lines (141 loc) · 5.05 KB
/
Copy paththeme-pack.develop.spec.js
File metadata and controls
170 lines (141 loc) · 5.05 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
/*
* Use Case
* A theme pack _author_ creating a theme pack and using Greenwood for development and testing
* following the guide published on the Greenwood website. (https://www.greenwoodjs.dev/guides/theme-packs/)
*
* User Result
* Should correctly validate the develop and build / serve commands work correctly using tge expected layouts
* being resolved correctly per the known work around needs as documented in the FAQ and tracked in a discussion.
* https://github.com/ProjectEvergreen/greenwood/discussions/682
*
* User Command
* greenwood develop
*
* User Config
* Mock Theme Pack Plugin (from fixtures)
*
* Plugin Author Workspace
* src/
* components/
* header.js
* layouts/
* blog-post.html
* pages/
* index.html
* styles/
* theme.css
*/
import chai from "chai";
import fs from "node:fs";
import { JSDOM } from "jsdom";
import path from "node:path";
import { Runner } from "gallinago";
import { runSmokeTest } from "../../../../../test/smoke-test.js";
import { fileURLToPath } from "node:url";
const expect = chai.expect;
const packageJson = JSON.parse(
await fs.promises.readFile(new URL("./package.json", import.meta.url), "utf-8"),
);
describe("Develop Greenwood With: ", function () {
const LABEL = "Development environment for a Theme Pack";
const cliPath = path.join(process.cwd(), "packages/cli/src/bin.js");
const outputPath = fileURLToPath(new URL(".", import.meta.url));
const hostname = "http://localhost";
const port = 1984;
let runner;
before(function () {
this.context = {
hostname: `${hostname}:${port}`,
};
runner = new Runner();
});
describe(LABEL, function () {
before(async function () {
runner.setup(outputPath);
return new Promise((resolve) => {
setTimeout(() => {
resolve();
}, 5000);
runner.runCommand(cliPath, "develop", { async: true });
});
});
runSmokeTest(["serve"], LABEL);
describe("Develop command specific HTML behaviors", function () {
let response = {};
let dom;
before(async function () {
response = await fetch(`${hostname}:${port}`);
const body = await response.clone().text();
dom = new JSDOM(body);
});
it("should return a 200", function (done) {
expect(response.status).to.equal(200);
done();
});
it("should have expected text from from a mock package layouts/blog-post.html in the users workspace", function (done) {
const pageLayoutHeading = dom.window.document.querySelectorAll("body h1")[0];
expect(pageLayoutHeading.textContent).to.be.equal(
"This is the blog post layout called from the layouts directory.",
);
done();
});
it("should have expected text from user workspace pages/index.md", function (done) {
const heading = dom.window.document.querySelectorAll("body h2")[0];
const paragraph = dom.window.document.querySelectorAll("body p")[0];
expect(heading.textContent).to.be.equal("Title of blog post");
expect(paragraph.textContent).to.be.equal("Lorum Ipsum, this is a test.");
done();
});
});
describe("Custom Theme Pack internal logic for resolving theme.css for local development", function () {
let response = {};
let body;
before(async function () {
response = await fetch(
`${hostname}:${port}/node_modules/${packageJson.name}/dist/styles/theme.css`,
);
body = await response.clone().text();
});
it("should return a 200", 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 correctly return CSS from the developers local files", function (done) {
expect(body).to.equal(
':root{--color-primary:#135;--color-secondary:#74b238;--font-family:"Optima", sans-serif;}',
);
done();
});
});
describe("Custom Theme Pack internal logic for resolving header.js for local development", function () {
let response = {};
let body;
before(async function () {
response = await fetch(
`${hostname}:${port}/node_modules/${packageJson.name}/dist/components/header.js`,
);
body = await response.clone().text();
});
it("should return a 200", 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/javascript");
done();
});
it("should correctly return JavaScript from the developers local files", function (done) {
expect(body).to.contain('customElements.define("x-header", HeaderComponent);');
done();
});
});
});
after(function () {
runner.stopCommand();
runner.teardown([path.join(outputPath, ".greenwood")]);
});
});