Merged in chore/partner-sas-test-setup (pull request #2484)
chore: Test setup in partner-web * Add playwright * Add vitest setup Approved-by: Linus Flood
This commit is contained in:
9
apps/partner-sas/.gitignore
vendored
9
apps/partner-sas/.gitignore
vendored
@@ -46,4 +46,11 @@ next-env.d.ts
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
.yarn/releases
|
||||
.yarn/releases
|
||||
|
||||
# Playwright
|
||||
node_modules/
|
||||
/test-results/
|
||||
/playwright-report/
|
||||
/blob-report/
|
||||
/playwright/.cache/
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
[build]
|
||||
command = "yarn build:sas"
|
||||
command = "yarn test && yarn build:sas"
|
||||
publish = "apps/partner-sas/.next"
|
||||
ignore = "git diff --quiet $CACHED_COMMIT_REF $COMMIT_REF apps/partner-sas packages/common packages/trpc packages/design-system packages/typescript-config"
|
||||
|
||||
[context.branch-deploy]
|
||||
command = "yarn build:sas"
|
||||
command = "yarn test && yarn build:sas"
|
||||
|
||||
[context.deploy-preview]
|
||||
command = "yarn build:sas"
|
||||
command = "yarn test && yarn build:sas"
|
||||
|
||||
[build.environment]
|
||||
# set TERM variable for terminal output
|
||||
|
||||
@@ -9,7 +9,10 @@
|
||||
"start": "node .next/standalone/server.js",
|
||||
"lint": "next lint --max-warnings 0 && tsc --noEmit",
|
||||
"lint:fix": "next lint --fix && tsc --noEmit",
|
||||
"check-types": "tsc --noEmit"
|
||||
"check-types": "tsc --noEmit",
|
||||
"test": "vitest run --passWithNoTests",
|
||||
"test:watch": "vitest",
|
||||
"test:e2e": "playwright test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@netlify/plugin-nextjs": "^5.11.2",
|
||||
@@ -22,6 +25,7 @@
|
||||
"devDependencies": {
|
||||
"@eslint/eslintrc": "^3.3.1",
|
||||
"@eslint/js": "^9.26.0",
|
||||
"@playwright/test": "^1.53.1",
|
||||
"@scandic-hotels/common": "workspace:*",
|
||||
"@scandic-hotels/typescript-config": "workspace:*",
|
||||
"@types/node": "^20",
|
||||
@@ -36,7 +40,8 @@
|
||||
"eslint-plugin-simple-import-sort": "^12.1.1",
|
||||
"graphql-tag": "^2.12.6",
|
||||
"typescript": "5.8.3",
|
||||
"typescript-plugin-css-modules": "^5.1.0"
|
||||
"typescript-plugin-css-modules": "^5.1.0",
|
||||
"vitest": "^3.2.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": "22"
|
||||
|
||||
79
apps/partner-sas/playwright.config.ts
Normal file
79
apps/partner-sas/playwright.config.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
import { defineConfig, devices } from "@playwright/test"
|
||||
|
||||
/**
|
||||
* Read environment variables from file.
|
||||
* https://github.com/motdotla/dotenv
|
||||
*/
|
||||
// import dotenv from 'dotenv';
|
||||
// import path from 'path';
|
||||
// dotenv.config({ path: path.resolve(__dirname, '.env') });
|
||||
|
||||
/**
|
||||
* See https://playwright.dev/docs/test-configuration.
|
||||
*/
|
||||
export default defineConfig({
|
||||
testDir: "./tests",
|
||||
/* 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: {
|
||||
/* Base URL to use in actions like `await page.goto('/')`. */
|
||||
baseURL: "http://localhost:3001",
|
||||
|
||||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
||||
trace: "on-first-retry",
|
||||
},
|
||||
|
||||
/* Configure projects for major browsers */
|
||||
projects: [
|
||||
{
|
||||
name: "chromium",
|
||||
use: { ...devices["Desktop Chrome"] },
|
||||
},
|
||||
|
||||
{
|
||||
name: "firefox",
|
||||
use: { ...devices["Desktop Firefox"] },
|
||||
},
|
||||
|
||||
{
|
||||
name: "webkit",
|
||||
use: { ...devices["Desktop Safari"] },
|
||||
},
|
||||
|
||||
/* Test against mobile viewports. */
|
||||
// {
|
||||
// name: 'Mobile Chrome',
|
||||
// use: { ...devices['Pixel 5'] },
|
||||
// },
|
||||
// {
|
||||
// name: 'Mobile Safari',
|
||||
// use: { ...devices['iPhone 12'] },
|
||||
// },
|
||||
|
||||
/* Test against branded browsers. */
|
||||
// {
|
||||
// name: 'Microsoft Edge',
|
||||
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
|
||||
// },
|
||||
// {
|
||||
// name: 'Google Chrome',
|
||||
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
|
||||
// },
|
||||
],
|
||||
|
||||
/* Run your local dev server before starting the tests */
|
||||
webServer: {
|
||||
command: "yarn dev",
|
||||
url: "http://localhost:3001",
|
||||
reuseExistingServer: !process.env.CI,
|
||||
},
|
||||
})
|
||||
7
apps/partner-sas/tests/dummy.spec.ts
Normal file
7
apps/partner-sas/tests/dummy.spec.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { expect, test } from "@playwright/test"
|
||||
|
||||
test("has text", async ({ page }) => {
|
||||
await page.goto("/")
|
||||
|
||||
await expect(page.getByText(/hello world/i)).toBeVisible()
|
||||
})
|
||||
30
apps/partner-sas/vitest-setup.ts
Normal file
30
apps/partner-sas/vitest-setup.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { vi } from "vitest"
|
||||
|
||||
process.env.TZ = "UTC"
|
||||
|
||||
vi.mock("next/navigation", () => ({
|
||||
useRouter: vi.fn(),
|
||||
usePathname: vi.fn().mockReturnValue("/"),
|
||||
useParams: vi.fn().mockReturnValue({ lang: "en" }),
|
||||
}))
|
||||
|
||||
Object.defineProperty(window, "matchMedia", {
|
||||
writable: true,
|
||||
value: vi.fn().mockImplementation((query) => ({
|
||||
matches: false,
|
||||
media: query,
|
||||
onchange: null,
|
||||
addListener: vi.fn(), // deprecated
|
||||
removeListener: vi.fn(), // deprecated
|
||||
addEventListener: vi.fn(),
|
||||
removeEventListener: vi.fn(),
|
||||
dispatchEvent: vi.fn(),
|
||||
})),
|
||||
})
|
||||
|
||||
Object.defineProperty(window, "CSS", {
|
||||
writable: true,
|
||||
value: {
|
||||
escape: vi.fn(),
|
||||
},
|
||||
})
|
||||
26
apps/partner-sas/vitest.config.ts
Normal file
26
apps/partner-sas/vitest.config.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import react from "@vitejs/plugin-react"
|
||||
import tsconfigPaths from "vite-tsconfig-paths"
|
||||
import { defineConfig } from "vitest/config"
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
tsconfigPaths(),
|
||||
react({
|
||||
babel: {
|
||||
plugins: [
|
||||
[
|
||||
"formatjs",
|
||||
{
|
||||
idInterpolationPattern: "[sha512:contenthash:base64:6]",
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
}),
|
||||
],
|
||||
test: {
|
||||
environment: "jsdom",
|
||||
setupFiles: ["./vitest-setup.ts"],
|
||||
include: ["**/*.{test}.?(c|m)[jt]s?(x)"],
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user