Path: blob/main/tests/integration/playwright-tests.test.ts
6433 views
/*1* smoke-all.test.ts2*3* Copyright (C) 2022 Posit Software, PBC4*5*/67import { expandGlobSync } from "../../src/core/deno/expand-glob.ts";8import { initYamlIntelligenceResourcesFromFilesystem } from "../../src/core/schema/utils.ts";9import {10initState,11setInitializer,12} from "../../src/core/lib/yaml-validation/state.ts";13import { cleanoutput } from "../smoke/render/render.ts";14import { execProcess } from "../../src/core/process.ts";15import { quartoDevCmd } from "../utils.ts";16import { fail } from "testing/asserts";17import { isWindows } from "../../src/deno_ral/platform.ts";18import { join, relative } from "../../src/deno_ral/path.ts";19import { existsSync } from "../../src/deno_ral/fs.ts";20import * as gha from "../../src/tools/github.ts";2122async function fullInit() {23await initYamlIntelligenceResourcesFromFilesystem();24}2526const globOutput = Deno.args.length27? expandGlobSync(Deno.args[0])28: expandGlobSync(29"docs/playwright/!(serve|shiny)/**/*.qmd",30);3132setInitializer(fullInit);33await initState();3435// Install multiplex server dependencies if needed36const multiplexServerPath = "integration/playwright/multiplex-server";37const multiplexNodeModules = join(multiplexServerPath, "node_modules");38if (!existsSync(multiplexNodeModules)) {39await execProcess({40cmd: isWindows ? "npm.cmd" : "npm",41args: ["install", "--loglevel=error"],42cwd: multiplexServerPath,43});44console.log("Multiplex server dependencies installed.");45}4647// const promises = [];48const fileNames: string[] = [];4950// To avoid re-rendering, see QUARTO_PLAYWRIGHT_SKIP_RENDER env var51if (Deno.env.get("QUARTO_PLAYWRIGHT_TESTS_SKIP_RENDER") === "true") {52console.log("Skipping render of test documents.");53} else {54const extraOpts = [55{56pathSuffix: "docs/playwright/embed-resources/issue-11860/main.qmd",57options: ["--output-dir=inner"],58}59]6061for (const { path: fileName } of globOutput) {62const input = relative(Deno.cwd(), fileName);63const options: string[] = [];64for (const extraOpt of extraOpts) {65if (fileName.endsWith(extraOpt.pathSuffix)) {66options.push(...extraOpt.options);67}68}6970// sigh, we have a race condition somewhere in71// mediabag inspection if we don't wait all renders72// individually. This is very slow..73console.log(`Rendering ${input}...`);74const result = await execProcess({75cmd: quartoDevCmd(),76args: ["render", input, ...options],77stdout: "piped",78stderr: "piped",79});8081if (!result.success) {82gha.error(`Failed to render ${input}`)83if (result.stdout) console.log(result.stdout);84if (result.stderr) console.error(result.stderr);85throw new Error(`Render failed with code ${result.code}`);86}8788fileNames.push(fileName);89}90}9192Deno.test({93name: "Playwright tests are passing",94// currently we run playwright tests only on Linux95ignore: gha.isGitHubActions() && isWindows,96fn: async () => {97try {98// run playwright99const res = await execProcess({100cmd: isWindows ? "npx.cmd" : "npx",101args: ["playwright", "test", "--ignore-snapshots"],102cwd: "integration/playwright",103},104undefined, // stdin105undefined, // mergeOutput106undefined, // stderrFilter107true // respectStreams - write directly to stderr/stdout108);109if (!res.success) {110if (gha.isGitHubActions() && Deno.env.get("GITHUB_REPOSITORY") && Deno.env.get("GITHUB_RUN_ID")) {111const runUrl = `https://github.com/${Deno.env.get("GITHUB_REPOSITORY")}/actions/runs/${Deno.env.get("GITHUB_RUN_ID")}`;112gha.error(113`Some tests failed. Download report uploaded as artifact at ${runUrl}`,114{115file: "playwright-tests.test.ts",116title: "Playwright tests"117}118);119}120fail("Failed tests with playwright. Look at playwright report for more details.")121}122123} finally {124// skip cleanoutput if requested125if (Deno.env.get("QUARTO_PLAYWRIGHT_TESTS_SKIP_CLEANOUTPUT") === "true" || Deno.env.get("QUARTO_PLAYWRIGHT_TESTS_SKIP_RENDER") === "true") {126console.log("Skipping cleanoutput of test documents.");127} else128for (const fileName of fileNames) {129cleanoutput(fileName, "html");130}131}132}133});134135136