Skip to content

Commit 3583438

Browse files
committed
test(project): Add case for BuildServer which requests application and library resources
`+` Adjust FixtureTester(BuildServer.integration.js)
1 parent 28944c2 commit 3583438

1 file changed

Lines changed: 140 additions & 34 deletions

File tree

packages/project/test/lib/build/BuildServer.integration.js

Lines changed: 140 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ test.serial("Serve application.a, initial file changes", async (t) => {
5050
await fs.appendFile(changedFilePath, `\ntest("initial change");\n`);
5151

5252
// Request the changed resource immediately
53-
const resourceRequestPromise = fixtureTester.requestResource("/test.js", {
54-
projects: {
55-
"application.a": {}
53+
const resourceRequestPromise = fixtureTester.requestResource({
54+
resource: "/test.js",
55+
assertions: {
56+
projects: {
57+
"application.a": {}
58+
}
5659
}
5760
});
5861
// Directly change the source file again, which should abort the current build and trigger a new one
@@ -74,15 +77,21 @@ test.serial("Serve application.a, request application resource", async (t) => {
7477

7578
// #1 request with empty cache
7679
await fixtureTester.serveProject();
77-
await fixtureTester.requestResource("/test.js", {
78-
projects: {
79-
"application.a": {}
80+
await fixtureTester.requestResource({
81+
resource: "/test.js",
82+
assertions: {
83+
projects: {
84+
"application.a": {}
85+
}
8086
}
8187
});
8288

8389
// #2 request with cache
84-
await fixtureTester.requestResource("/test.js", {
85-
projects: {}
90+
await fixtureTester.requestResource({
91+
resource: "/test.js",
92+
assertions: {
93+
projects: {}
94+
}
8695
});
8796

8897
// Change a source file in application.a
@@ -92,16 +101,19 @@ test.serial("Serve application.a, request application resource", async (t) => {
92101
await setTimeout(500); // Wait for the file watcher to detect and propagate the change
93102

94103
// #3 request with cache and changes
95-
const res = await fixtureTester.requestResource("/test.js", {
96-
projects: {
97-
"application.a": {
98-
skippedTasks: [
99-
"escapeNonAsciiCharacters",
100-
// Note: replaceCopyright is skipped because no copyright is configured in the project
101-
"replaceCopyright",
102-
"enhanceManifest",
103-
"generateFlexChangesBundle",
104-
]
104+
const res = await fixtureTester.requestResource({
105+
resource: "/test.js",
106+
assertions: {
107+
projects: {
108+
"application.a": {
109+
skippedTasks: [
110+
"escapeNonAsciiCharacters",
111+
// Note: replaceCopyright is skipped because no copyright is configured in the project
112+
"replaceCopyright",
113+
"enhanceManifest",
114+
"generateFlexChangesBundle",
115+
]
116+
}
105117
}
106118
}
107119
});
@@ -116,15 +128,21 @@ test.serial("Serve application.a, request library resource", async (t) => {
116128

117129
// #1 request with empty cache
118130
await fixtureTester.serveProject();
119-
await fixtureTester.requestResource("/resources/library/a/.library", {
120-
projects: {
121-
"library.a": {}
131+
await fixtureTester.requestResource({
132+
resource: "/resources/library/a/.library",
133+
assertions: {
134+
projects: {
135+
"library.a": {}
136+
}
122137
}
123138
});
124139

125140
// #2 request with cache
126-
await fixtureTester.requestResource("/resources/library/a/.library", {
127-
projects: {}
141+
await fixtureTester.requestResource({
142+
resource: "/resources/library/a/.library",
143+
assertions: {
144+
projects: {}
145+
}
128146
});
129147

130148
// Change a source file in library.a
@@ -140,14 +158,17 @@ test.serial("Serve application.a, request library resource", async (t) => {
140158
await setTimeout(500); // Wait for the file watcher to detect and propagate the change
141159

142160
// #3 request with cache and changes
143-
const dotLibraryResource = await fixtureTester.requestResource("/resources/library/a/.library", {
144-
projects: {
145-
"library.a": {
146-
skippedTasks: [
147-
"escapeNonAsciiCharacters",
148-
"minify",
149-
"replaceBuildtime",
150-
]
161+
const dotLibraryResource = await fixtureTester.requestResource({
162+
resource: "/resources/library/a/.library",
163+
assertions: {
164+
projects: {
165+
"library.a": {
166+
skippedTasks: [
167+
"escapeNonAsciiCharacters",
168+
"minify",
169+
"replaceBuildtime",
170+
]
171+
}
151172
}
152173
}
153174
});
@@ -160,8 +181,11 @@ test.serial("Serve application.a, request library resource", async (t) => {
160181
);
161182

162183
// #4 request with cache (no changes)
163-
const manifestResource = await fixtureTester.requestResource("/resources/library/a/manifest.json", {
164-
projects: {}
184+
const manifestResource = await fixtureTester.requestResource({
185+
resource: "/resources/library/a/manifest.json",
186+
assertions: {
187+
projects: {}
188+
}
165189
});
166190

167191
// Check whether the manifest is served correctly with changed .library content reflected
@@ -172,6 +196,78 @@ test.serial("Serve application.a, request library resource", async (t) => {
172196
);
173197
});
174198

199+
test.serial("Serve application.a, request application resource AND library resource", async (t) => {
200+
const fixtureTester = t.context.fixtureTester = new FixtureTester(t, "application.a");
201+
202+
// #1 request with empty cache
203+
await fixtureTester.serveProject();
204+
await fixtureTester.requestResources({
205+
resources: ["/test.js", "/resources/library/a/.library"],
206+
assertions: {
207+
projects: {
208+
"library.a": {},
209+
"application.a": {}
210+
}
211+
}
212+
});
213+
214+
// #2 request with cache
215+
await fixtureTester.requestResources({
216+
resources: ["/test.js", "/resources/library/a/.library"],
217+
assertions: {
218+
projects: {}
219+
}
220+
});
221+
222+
// Change a source file in application.a and library.a
223+
const changedFilePath = `${fixtureTester.fixturePath}/webapp/test.js`;
224+
await fs.appendFile(changedFilePath, `\ntest("line added");\n`);
225+
const changedFilePath2 = `${fixtureTester.fixturePath}/node_modules/collection/library.a/src/library/a/.library`;
226+
await fs.writeFile(
227+
changedFilePath2,
228+
(await fs.readFile(changedFilePath2, {encoding: "utf8"})).replace(
229+
`<documentation>Library A</documentation>`,
230+
`<documentation>Library A (updated #1)</documentation>`
231+
)
232+
);
233+
234+
await setTimeout(500); // Wait for the file watcher to detect and propagate the changes
235+
236+
// #3 request with cache and changes
237+
const [resource1, resource2] = await fixtureTester.requestResources({
238+
resources: ["/test.js", "/resources/library/a/.library"],
239+
assertions: {
240+
projects: {
241+
"library.a": {
242+
skippedTasks: [
243+
"escapeNonAsciiCharacters",
244+
"minify",
245+
"replaceBuildtime",
246+
]
247+
},
248+
"application.a": {
249+
skippedTasks: [
250+
"escapeNonAsciiCharacters",
251+
// Note: replaceCopyright is skipped because no copyright is configured in the project
252+
"replaceCopyright",
253+
"enhanceManifest",
254+
"generateFlexChangesBundle",
255+
]
256+
}
257+
}
258+
}
259+
});
260+
261+
// Check whether the changed files contain the correct contents
262+
const resource1FileContent = await resource1.getString();
263+
const resource2FileContent = await resource2.getString();
264+
t.true(resource1FileContent.includes(`test("line added");`), "Resource contains changed file content");
265+
t.true(
266+
resource2FileContent.includes(`<documentation>Library A (updated #1)</documentation>`),
267+
"Resource contains changed file content"
268+
);
269+
});
270+
175271
function getFixturePath(fixtureName) {
176272
return fileURLToPath(new URL(`../../fixtures/${fixtureName}`, import.meta.url));
177273
}
@@ -229,7 +325,7 @@ class FixtureTester {
229325
this._reader = this.buildServer.getReader();
230326
}
231327

232-
async requestResource(resource, assertions = {}) {
328+
async requestResource({resource, assertions = {}}) {
233329
this._sinon.resetHistory();
234330
const res = await this._reader.byPath(resource);
235331
// Apply assertions if provided
@@ -239,6 +335,16 @@ class FixtureTester {
239335
return res;
240336
}
241337

338+
async requestResources({resources, assertions = {}}) {
339+
this._sinon.resetHistory();
340+
const returnedResources = await Promise.all(resources.map((resource) => this._reader.byPath(resource)));
341+
// Apply assertions if provided
342+
if (assertions) {
343+
this._assertBuild(assertions);
344+
}
345+
return returnedResources;
346+
}
347+
242348
_assertBuild(assertions) {
243349
const {projects = {}} = assertions;
244350
const eventArgs = this._t.context.projectBuildStatusEventStub.args.map((args) => args[0]);

0 commit comments

Comments
 (0)