Skip to content

Commit

Permalink
Add integration tests / fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
matz3 committed Feb 11, 2020
1 parent ae7b50e commit 882d0c2
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/middleware/serveThemes.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function createMiddleware({resources}) {
// Pick requested file resource
const resource = createdResources.find((res) => res.getPath().endsWith(filename));
if (!resource) {
next(new Error(`Theme Build did not return request file "${pathname}"`));
next(new Error(`Theme Build did not return requested file "${pathname}"`));
return;
}

Expand Down
63 changes: 63 additions & 0 deletions test/lib/server/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,69 @@ test("Get library-parameters.json from theme middleware (/resources/library/a/th
});
});

test("Get css-variables.source.less from theme middleware (/resources/library/a/themes/base/css-variables.source.less)", (t) => {
return request.get("/resources/library/a/themes/base/css-variables.source.less").then((res) => {
if (res.error) {
t.fail(res.error.text);
}
t.deepEqual(res.statusCode, 200, "Correct HTTP status code");
t.regex(res.headers["content-type"], /less/, "Correct content type");
t.deepEqual(res.text, `@libraryAColor1: #fafad2;
:root {
--libraryAColor1: @libraryAColor1;
}
`, "Correct response");
});
});

test("Get css-variables.css from theme middleware (/resources/library/a/themes/base/css-variables.css)", (t) => {
return request.get("/resources/library/a/themes/base/css-variables.css").then((res) => {
if (res.error) {
t.fail(res.error.text);
}
t.deepEqual(res.statusCode, 200, "Correct HTTP status code");
t.regex(res.headers["content-type"], /css/, "Correct content type");
t.deepEqual(res.text, `:root {
--libraryAColor1: #fafad2;
}
/* Inline theming parameters */
#sap-ui-theme-library\\.a{background-image:url('data:text/plain;utf-8,%7B%22libraryAColor1%22%3A%22%23fafad2%22%7D')}
`, "Correct response");
});
});

test("Get library-skeleton.css from theme middleware (/resources/library/a/themes/base/library-skeleton.css)", (t) => {
return request.get("/resources/library/a/themes/base/library-skeleton.css").then((res) => {
if (res.error) {
t.fail(res.error.text);
}
t.deepEqual(res.statusCode, 200, "Correct HTTP status code");
t.regex(res.headers["content-type"], /css/, "Correct content type");
t.deepEqual(res.text, `.library-a-foo {
color: var(--libraryAColor1);
padding: 1px 2px 3px 4px;
}
`, "Correct response");
});
});

test("Get library-skeleton-RTL.css from theme middleware (/resources/library/a/themes/base/library-skeleton-RTL.css)", (t) => {
return request.get("/resources/library/a/themes/base/library-skeleton-RTL.css").then((res) => {
if (res.error) {
t.fail(res.error.text);
}
t.deepEqual(res.statusCode, 200, "Correct HTTP status code");
t.regex(res.headers["content-type"], /css/, "Correct content type");
t.deepEqual(res.text, `.library-a-foo {
color: var(--libraryAColor1);
padding: 1px 4px 3px 2px;
}
`, "Correct response");
});
});

test("Stop server", (t) => {
const port = 3350;
const request = supertest(`http://localhost:${port}`);
Expand Down
2 changes: 1 addition & 1 deletion test/lib/server/middleware/serveThemes.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ test.serial.cb("Error handling: Request resource that ThemeBuild doesn't return"
const res = {};

middleware(req, res, function(err) {
t.is(err.message, `Theme Build did not return request file "/resources/sap/ui/test/themes/base/library.css"`);
t.is(err.message, `Theme Build did not return requested file "/resources/sap/ui/test/themes/base/library.css"`);
t.end();
});
});
Expand Down

0 comments on commit 882d0c2

Please sign in to comment.