Skip to content

Commit 432b6d1

Browse files
Fix multiline styles for CSP and fix add to ignore @vueuse (#34)
1 parent 80d8326 commit 432b6d1

12 files changed

+72
-44
lines changed

e2e/vue.spec.ts

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,56 @@ let errorMessagesCount = 0;
66

77
const ignoreErrors = [
88
"ResizeObserver loop completed with undelivered notifications.",
9+
// Blocked by AdBlocker
10+
"api-gateway.umami.dev",
11+
];
12+
const ignoreConsoleErrors = [
13+
// Blocked by AdBlocker
14+
"api-gateway.umami.dev",
15+
"Failed to load resource: net::ERR_FAILED",
916
];
1017

1118
// Register a global error listener
12-
test.beforeEach(async ({ page }) => {
19+
test.beforeEach(async ({ page, browserName }) => {
1320
errorMessagesCount = 0;
1421

15-
page.on("pageerror", (error) => {
16-
if (ignoreErrors.includes(error.message)) {
22+
page.on("console", (consoleMessage) => {
23+
if (consoleMessage.type() !== "error") {
24+
return;
25+
}
26+
27+
// Webkit again have strange behavior.
28+
// It doesn't provide location for CSP error.
29+
// And not reproducible in Safari browser.
30+
if (browserName === "webkit") {
1731
return;
1832
}
19-
console.log(">> Console error: ", error);
33+
34+
for (const ignoreError of ignoreConsoleErrors) {
35+
if (consoleMessage.text().includes(ignoreError)) {
36+
return;
37+
}
38+
}
39+
console.log(
40+
">> Console log (error): ",
41+
consoleMessage.text(),
42+
consoleMessage.location(),
43+
);
44+
++errorMessagesCount;
45+
});
46+
47+
page.on("pageerror", (error) => {
48+
for (const ignoreError of ignoreErrors) {
49+
if (error.message.includes(ignoreError)) {
50+
return;
51+
}
52+
}
53+
console.log(">> Console error: ", error, error.stack);
2054
++errorMessagesCount;
2155
});
2256
});
2357

24-
test.afterEach(() => {
58+
test.afterEach(async () => {
2559
expect(errorMessagesCount).toBe(0);
2660
});
2761

@@ -51,18 +85,40 @@ test("visits the app root url, sitemap.txt and robots.txt", async ({
5185
expect(await page.locator("pre").innerText()).toMatchSnapshot("robots.txt");
5286
});
5387

54-
test("check menu items", async ({ page }) => {
88+
test("check menu items and each page", async ({ page }) => {
5589
await page.goto("/");
5690
const $menu = page.locator('[data-test-id="page-header-menu"]');
5791
const menuItems = $menu.getByRole("menuitem");
5892
const $$menuItems = await menuItems.all();
5993
await page.waitForTimeout(500);
6094
await expect(menuItems).toHaveCount(4);
6195

62-
await expect($$menuItems[0]).toHaveText("Home");
63-
await expect($$menuItems[1]).toHaveText("Create Crypto Address");
64-
await expect($$menuItems[2]).toHaveText("Create Paper Wallet");
65-
await expect($$menuItems[3]).toHaveText("Paper Wallet Editor");
96+
const pages = [
97+
{ index: 0, url: "/", title: "Home" },
98+
{ index: 1, url: "/create-wallets/", title: "Create Crypto Address" },
99+
{ index: 2, url: "/paper-wallets/", title: "Create Paper Wallet" },
100+
{ index: 3, url: "/paper-wallet-editor/", title: "Paper Wallet Editor" },
101+
];
102+
103+
for (const { index, title } of pages) {
104+
await expect($$menuItems[index]).toHaveText(title);
105+
}
106+
107+
// Check Content-Security-Policy.
108+
// Need to refresh the page to check the CSP for each page separately.
109+
if (process.env.PLAYWRIGHT_USE_BUILD) {
110+
for (const { index, url } of pages) {
111+
if (index === 0) {
112+
continue;
113+
}
114+
const $item = $$menuItems[index];
115+
await $item.click();
116+
await page.waitForURL(url, { timeout: 5000 });
117+
await page.waitForTimeout(500);
118+
await page.reload();
119+
await page.waitForTimeout(1000);
120+
}
121+
}
66122
});
67123

68124
test("General flow", async ({ page, context, browserName }) => {

e2e/vue.spec.ts-snapshots/robots-firefox-darwin.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

e2e/vue.spec.ts-snapshots/robots-firefox-linux.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

e2e/vue.spec.ts-snapshots/robots-webkit-darwin.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

e2e/vue.spec.ts-snapshots/robots-webkit-linux.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

e2e/vue.spec.ts-snapshots/sitemap-firefox-darwin.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

e2e/vue.spec.ts-snapshots/sitemap-firefox-linux.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

e2e/vue.spec.ts-snapshots/sitemap-webkit-darwin.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

e2e/vue.spec.ts-snapshots/sitemap-webkit-linux.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

node/csp/getInlineStylesHashes.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function calculateStyleHash(styleContent) {
3030
function getInlineStyles(appHtml) {
3131
return (
3232
appHtml
33-
.match(/ style=".*?"/g)
33+
.match(/ style="([\s\S]*?)"/g)
3434
?.map((line) => line.replace(/^ style="/, "").replace(/"$/, "")) || []
3535
);
3636
}

src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// [tag-nonce]
1515
// Some libs doesn't support nonce, part of logic with workaround
1616
// Search by tag in the code
17-
const chunksWithoutNonce = ["naive-ui"];
17+
const chunksWithoutNonce = ["naive-ui", "@vueuse"];
1818
addNonceToStyles(import.meta.env.VITE_NONCE, chunksWithoutNonce);
1919
2020
const isDark = useDark() as Ref<boolean>;

vite.config.mts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ export default defineConfig({
4545
if (id.startsWith(nativeUiPath)) {
4646
return "naive-ui"; // https://github.com/tusen-ai/naive-ui/issues/6356
4747
}
48+
const vueUsePath = process.cwd() + "/node_modules/@vueuse/";
49+
if (id.startsWith(vueUsePath)) {
50+
return "@vueuse"; // only locale files, but any way
51+
}
4852
},
4953
},
5054
},

0 commit comments

Comments
 (0)