Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .nx/workflows/dynamic-changesets.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
distribute-on:
small-changeset: 4 linux-medium-js
medium-changeset: 8 linux-medium-js
large-changeset: 14 linux-medium-js
large-changeset: 16 linux-medium-js
9 changes: 9 additions & 0 deletions .nx/workflows/sandboxing-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
exclude-reads:
- e2e/.gitignore
- '**/src/routeTree.gen.ts'
exclude-writes:
- '**/src/routeTree.gen.ts'
task-exclusions:
- target: test:build
exclude-reads:
- LICENSE
12 changes: 7 additions & 5 deletions e2e/react-start/import-protection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
"build": "pnpm build:vite",
"build:vite": "vite build && tsc --noEmit",
"build:rsbuild": "rsbuild build && tsc --noEmit",
"start": "node server.js",
"test:e2e:mockMode": "rm -rf node_modules/.vite; rm -rf port*.txt; playwright test --project=chromium",
"test:e2e:errorMode": "rm -rf node_modules/.vite; rm -rf port*.txt; BEHAVIOR=error playwright test --project=chromium",
"test:e2e": "pnpm run test:e2e:mockMode && pnpm run test:e2e:errorMode"
"start": "node server.js"
},
"dependencies": {
"@tanstack/react-router": "workspace:^",
Expand Down Expand Up @@ -58,6 +55,7 @@
"toolchain": "vite",
"mode": "ssr",
"env": {
"E2E_BUILD_LOG": "webserver-build.vite-ssr.log",
"E2E_VITE_BUNDLED_DEV": "false"
}
},
Expand All @@ -66,12 +64,16 @@
"mode": "ssr",
"name": "bundled-dev",
"env": {
"E2E_BUILD_LOG": "webserver-build.vite-ssr-bundled-dev.log",
"E2E_VITE_BUNDLED_DEV": "true"
}
},
{
"toolchain": "rsbuild",
"mode": "ssr"
"mode": "ssr",
"env": {
"E2E_BUILD_LOG": "webserver-build.rsbuild-ssr.log"
}
}
]
}
Expand Down
11 changes: 8 additions & 3 deletions e2e/react-start/import-protection/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineConfig, devices } from '@playwright/test'
import { getTestServerPort } from '@tanstack/router-e2e-utils'
import { isErrorMode } from './tests/utils/isErrorMode'
import { getViolationArtifactName } from './tests/violations.utils'
import packageJson from './package.json' with { type: 'json' }

const toolchain = process.env.E2E_TOOLCHAIN ?? 'vite'
Expand All @@ -11,8 +12,12 @@ const e2ePortKey =
const distDir = process.env.E2E_DIST_DIR ?? 'dist'
const PORT = await getTestServerPort(e2ePortKey)
const baseURL = `http://localhost:${PORT}`
const buildCommand =
toolchain === 'rsbuild' ? 'pnpm build:rsbuild' : 'pnpm build:vite'
const violationArtifacts = [
getViolationArtifactName('build'),
getViolationArtifactName('dev'),
getViolationArtifactName('dev.cold'),
getViolationArtifactName('dev.warm'),
].join(' ')

console.log('running in error mode:', isErrorMode.toString())

Expand All @@ -36,7 +41,7 @@ export default defineConfig({
? {}
: {
webServer: {
command: `rm -f webserver-build.log webserver-dev.log violations.build.json violations.dev.json && VITE_SERVER_PORT=${PORT} PORT=${PORT} ${buildCommand} > webserver-build.log 2>&1 && PORT=${PORT} VITE_SERVER_PORT=${PORT} pnpm start`,
command: `rm -f webserver-dev.log ${violationArtifacts} && PORT=${PORT} VITE_SERVER_PORT=${PORT} pnpm start`,
url: baseURL,
reuseExistingServer: !process.env.CI,
stdout: 'pipe',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path from 'node:path'
import fs from 'node:fs'
import { expect } from '@playwright/test'
import { test } from '@tanstack/router-e2e-utils'
import { getViolationArtifactName } from './violations.utils'
import type { Violation } from './violations.utils'
import type { Page } from '@playwright/test'

Expand Down Expand Up @@ -37,7 +38,7 @@ function normalizeKeyPath(value: string): string {
async function readViolations(
type: 'build' | 'dev' | 'dev.cold' | 'dev.warm',
): Promise<Array<Violation>> {
const filename = `violations.${type}.json`
const filename = getViolationArtifactName(type)
const violationsPath = path.resolve(import.meta.dirname, '..', filename)
const mod = await import(violationsPath, {
with: { type: 'json' },
Expand Down Expand Up @@ -161,7 +162,8 @@ test('client-only violations route loads in mock mode', async ({ page }) => {
})

for (const mode of ['build', 'dev'] as const) {
test(`violations.${mode}.json is written during ${mode}`, async () => {
const artifactName = getViolationArtifactName(mode)
test(`${artifactName} is written during ${mode}`, async () => {
const violations = await readViolations(mode)
expect(violations.length).toBeGreaterThan(0)
})
Expand Down Expand Up @@ -204,7 +206,7 @@ test('build log does not contain mock-edge missing export warnings', () => {
const buildLogPath = path.resolve(
import.meta.dirname,
'..',
'webserver-build.log',
process.env.E2E_BUILD_LOG ?? 'webserver-build.log',
)

if (!fs.existsSync(buildLogPath)) {
Expand Down
22 changes: 14 additions & 8 deletions e2e/react-start/import-protection/tests/violations.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { chromium } from '@playwright/test'
import { getTestServerPort } from '@tanstack/router-e2e-utils'
import packageJson from '../package.json' with { type: 'json' }

import { extractViolationsFromLog } from './violations.utils'
import {
extractViolationsFromLog,
getViolationArtifactName,
} from './violations.utils'
import type { FullConfig } from '@playwright/test'
import type { Violation } from './violations.utils'

Expand Down Expand Up @@ -250,11 +253,11 @@ async function captureDevViolations(cwd: string): Promise<void> {
)

fs.writeFileSync(
path.resolve(cwd, 'violations.dev.json'),
path.resolve(cwd, getViolationArtifactName('dev')),
JSON.stringify(coldViolations, null, 2),
)
fs.writeFileSync(
path.resolve(cwd, 'violations.dev.cold.json'),
path.resolve(cwd, getViolationArtifactName('dev.cold')),
JSON.stringify(coldViolations, null, 2),
)

Expand All @@ -265,7 +268,7 @@ async function captureDevViolations(cwd: string): Promise<void> {
)

fs.writeFileSync(
path.resolve(cwd, 'violations.dev.warm.json'),
path.resolve(cwd, getViolationArtifactName('dev.warm')),
JSON.stringify(warmViolations, null, 2),
)
}
Expand All @@ -275,19 +278,22 @@ export default async function globalSetup(config: FullConfig) {
// This file lives in ./tests; fixture root is one directory up.
const cwd = path.resolve(import.meta.dirname, '..')

// webServer.command writes build output to this file.
const logFile = path.resolve(cwd, 'webserver-build.log')
// The Nx build dependency writes build output to this file.
const logFile = path.resolve(
cwd,
process.env.E2E_BUILD_LOG ?? 'webserver-build.log',
)

if (!fs.existsSync(logFile)) {
// If the log doesn't exist, leave an empty violations file.
fs.writeFileSync(path.resolve(cwd, 'violations.build.json'), '[]')
fs.writeFileSync(path.resolve(cwd, getViolationArtifactName('build')), '[]')
return
}

const text = fs.readFileSync(logFile, 'utf-8')
const violations = extractViolationsFromLog(text)
fs.writeFileSync(
path.resolve(cwd, 'violations.build.json'),
path.resolve(cwd, getViolationArtifactName('build')),
JSON.stringify(violations, null, 2),
)

Expand Down
9 changes: 9 additions & 0 deletions e2e/react-start/import-protection/tests/violations.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ export type Violation = {
message?: string
}

export type ViolationArtifact = 'build' | 'dev' | 'dev.cold' | 'dev.warm'

export function getViolationArtifactName(artifact: ViolationArtifact): string {
const modeKey = process.env.E2E_MODE_KEY
return modeKey
? `violations.${modeKey}.${artifact}.json`
: `violations.${artifact}.json`
}

export function stripAnsi(input: string): string {
// eslint-disable-next-line no-control-regex
return input.replace(/\u001b\[[0-9;]*m/g, '')
Expand Down
64 changes: 52 additions & 12 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,18 @@
},
"namedInputs": {
"sharedGlobals": [
"{workspaceRoot}/.npmrc",
"{workspaceRoot}/.nx/workflows/sandboxing-config.yaml",
"{workspaceRoot}/.nvmrc",
"{workspaceRoot}/package.json",
"{workspaceRoot}/tsconfig.json"
],
"dependentTaskOutputs": [
{
"dependentTasksOutputFiles": "**/*",
"transitive": true
}
],
"default": [
"sharedGlobals",
"{projectRoot}/**/*",
Expand All @@ -22,7 +30,8 @@
"default",
"!{projectRoot}/tests/**/*",
"!{projectRoot}/eslint.config.js"
]
],
"buildProduction": ["sharedGlobals", "{projectRoot}/**/*"]
},
"targetDefaults": {
"test:docs": {
Expand All @@ -31,19 +40,34 @@
},
"test:eslint": {
"cache": true,
"dependsOn": ["^build"],
"inputs": ["default", "^production", "{workspaceRoot}/eslint.config.js"]
"dependsOn": ["^build", "build"],
"inputs": [
"default",
"^production",
"{workspaceRoot}/eslint.config.js",
"dependentTaskOutputs"
]
},
"test:unit": {
"cache": true,
"dependsOn": ["^build"],
"inputs": ["default", "^production"],
"inputs": [
"default",
"^production",
"{workspaceRoot}/eslint.config.js",
"dependentTaskOutputs"
],
"outputs": ["{projectRoot}/coverage"]
},
"test:e2e": {
"cache": true,
"dependsOn": ["^build", "test:e2e--*"],
"inputs": ["default", "^production"]
"inputs": ["default", "^production", "dependentTaskOutputs"],
"outputs": [
"{projectRoot}/dist",
"{projectRoot}/port-*.txt",
"{projectRoot}/test-results"
]
},
"test:e2e:nitro": {
"cache": true,
Expand All @@ -62,24 +86,40 @@
},
"test:types": {
"cache": true,
"dependsOn": ["^build"],
"inputs": ["default", "^production"]
"dependsOn": ["^build", "build"],
"inputs": [
"default",
"^production",
"{workspaceRoot}/eslint.config.js",
"dependentTaskOutputs"
]
},
"test:types:ssr": {
"cache": true,
"dependsOn": ["^build"],
"inputs": ["default", "^production"]
"dependsOn": ["^build", "build"],
"inputs": [
"default",
"^production",
"{workspaceRoot}/benchmarks/ssr/bench-utils.ts",
"dependentTaskOutputs"
]
},
"build": {
"cache": true,
"dependsOn": ["^build"],
"inputs": ["production", "^production"],
"outputs": ["{projectRoot}/build", "{projectRoot}/dist"]
"inputs": ["buildProduction", "^buildProduction", "dependentTaskOutputs"],
"outputs": [
"{projectRoot}/.netlify",
"{projectRoot}/.wrangler",
"{projectRoot}/.output",
"{projectRoot}/build",
"{projectRoot}/dist"
]
},
"test:build": {
"cache": true,
"dependsOn": ["build"],
"inputs": ["production"]
"inputs": ["buildProduction", "dependentTaskOutputs"]
}
},
"plugins": [
Expand Down
Loading
Loading