Skip to content

Commit

Permalink
Add prettier formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
sockmaster27 committed Oct 27, 2024
1 parent b4b9de7 commit 0c022d9
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 89 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.frag
12 changes: 12 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"plugins": ["prettier-plugin-svelte"],
"printWidth": 80,
"tabWidth": 4,
"semi": true,
"singleQuote": false,
"quoteProps": "consistent",
"trailingComma": "all",
"bracketSpacing": true,
"arrowParens": "avoid",
"endOfLine": "auto"
}
31 changes: 30 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"devDependencies": {
"@playwright/test": "^1.48.1",
"@types/node": "^22.7.9"
"@types/node": "^22.7.9",
"prettier-plugin-svelte": "^3.2.7"
}
}
145 changes: 72 additions & 73 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,89 +1,88 @@
import { defineConfig, devices } from '@playwright/test';
import { defineConfig, devices } from "@playwright/test";

// Apparently, Chromium browsers need to be explicitly told to use GPU acceleration in headless mode,
// and software rendering creates slightly different results for WebGL in noise and such,
// while WebGPU has no software fallback at all.
const chromiumHardware = {
args: [
"--enable-gpu",
],
args: ["--enable-gpu"],
};

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests',
snapshotPathTemplate: '{testDir}/.generated-screenshots/{testFilePath}/{arg}{ext}',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
testDir: "./tests",
snapshotPathTemplate:
"{testDir}/.generated-screenshots/{testFilePath}/{arg}{ext}",
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: "html",
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: "on-first-retry",

contextOptions: {
// Disable animations so screenshots are comparable
reducedMotion: 'reduce',
contextOptions: {
// Disable animations so screenshots are comparable
reducedMotion: "reduce",
},
},
},

projects: [
{
name: 'Firefox',
use: {
...devices['Desktop Firefox'],
},
},
{
name: 'Microsoft Edge',
use: {
...devices['Desktop Edge'],
channel: 'msedge',
launchOptions: chromiumHardware,
},
},
{
name: 'Google Chrome',
use: {
...devices['Desktop Chrome'],
channel: 'chrome',
launchOptions: chromiumHardware,
},
},
/* TODO: Test these as well */
// {
// name: 'Chromium',
// use: {
// ...devices['Desktop Chrome'],
// launchOptions: chromiumHardware,
// },
// },
// {
// name: 'WebKit',
// use: { ...devices['Desktop Safari'] },
// },
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },
],
projects: [
{
name: "Firefox",
use: {
...devices["Desktop Firefox"],
},
},
{
name: "Microsoft Edge",
use: {
...devices["Desktop Edge"],
channel: "msedge",
launchOptions: chromiumHardware,
},
},
{
name: "Google Chrome",
use: {
...devices["Desktop Chrome"],
channel: "chrome",
launchOptions: chromiumHardware,
},
},
/* TODO: Test these as well */
// {
// name: 'Chromium',
// use: {
// ...devices['Desktop Chrome'],
// launchOptions: chromiumHardware,
// },
// },
// {
// name: 'WebKit',
// use: { ...devices['Desktop Safari'] },
// },
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },
],

webServer: {
command: 'npm run preview:v4',
port: 4173,
reuseExistingServer: !process.env.CI,
},
webServer: {
command: "npm run preview:v4",
port: 4173,
reuseExistingServer: !process.env.CI,
},
});
32 changes: 20 additions & 12 deletions tests/svelte4.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,31 @@ import { test, expect, TestInfo, Page } from "@playwright/test";

// No output on the console is desired
test.beforeEach(async ({ page }) => {
page.on("console", (msg) => {
page.on("console", msg => {
throw new Error(`Output printed to console:\n${msg.text()}`);
});
});

/** Project names (as defined in playwright.config.ts) that are not expected to support WebGPU. */
const webGpuUnsupported = [
"Firefox",
]
const webGpuUnsupported = ["Firefox"];

/**
* Takes a screenshot of the current page and compares it to a reference, as indexed by the given arguments.
* If a reference screenshot does not exist, it will be created and used for future assertions.
*
* If a reference screenshot does not exist, it will be created and used for future assertions.
*
* @param page
* @param info
* @param name A name that identifies this test.
* @param api The API used in the test, either `"webgl"` or `"webgpu"`.
* @param number A number identifying the specific screeenshot within the test, if multiple are included.
*/
async function assertScreenshot(page: Page, info: TestInfo, name: string, api: "webgl" | "webgpu", number?: number) {
async function assertScreenshot(
page: Page,
info: TestInfo,
name: string,
api: "webgl" | "webgpu",
number?: number,
) {
const projectName = info.project.name;
const isMobile = info.project.use.isMobile ?? false;

Expand All @@ -31,7 +35,8 @@ async function assertScreenshot(page: Page, info: TestInfo, name: string, api: "

const isWebGpu = api === "webgpu";
const isWebGpuUnsupported = webGpuUnsupported.includes(projectName);
const unsupportedString = (isWebGpu && isWebGpuUnsupported) ? "-unsupported" : "";
const unsupportedString =
isWebGpu && isWebGpuUnsupported ? "-unsupported" : "";

const fileName = `${name}-${api}${unsupportedString}${mobileString}${numberString}.png`;

Expand All @@ -44,7 +49,6 @@ async function assertScreenshot(page: Page, info: TestInfo, name: string, api: "

const apis = ["webgl", "webgpu"] as const;
apis.forEach(api => {

test(`Hello world [${api}]`, async ({ page }, info) => {
const pageName = "hello-world";

Expand All @@ -56,7 +60,7 @@ apis.forEach(api => {
const pageName = "remount";

await page.goto(`/${pageName}/${api}`);
let show = page.getByLabel("Show")
let show = page.getByLabel("Show");
await show.uncheck();
await assertScreenshot(page, info, pageName, api, 1);
for (let i = 0; i < 10; i++) {
Expand All @@ -73,7 +77,12 @@ apis.forEach(api => {
await page.goto(`/${pageName}/${api}`);
await assertScreenshot(page, info, pageName, api, 1);
// Scroll to bottom-right corner
await page.evaluate(() => window.scrollBy(document.body.scrollWidth, document.body.scrollHeight));
await page.evaluate(() =>
window.scrollBy(
document.body.scrollWidth,
document.body.scrollHeight,
),
);
await assertScreenshot(page, info, pageName, api, 2);
});

Expand Down Expand Up @@ -109,5 +118,4 @@ apis.forEach(api => {
slider.fill("0");
await assertScreenshot(page, info, pageName, api, 3);
});

});
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"types": ["node"],
"strict": true,
"strict": true
}
}
}

0 comments on commit 0c022d9

Please sign in to comment.