Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/integration/playwright-tests.test.ts
6433 views
1
/*
2
* smoke-all.test.ts
3
*
4
* Copyright (C) 2022 Posit Software, PBC
5
*
6
*/
7
8
import { expandGlobSync } from "../../src/core/deno/expand-glob.ts";
9
import { initYamlIntelligenceResourcesFromFilesystem } from "../../src/core/schema/utils.ts";
10
import {
11
initState,
12
setInitializer,
13
} from "../../src/core/lib/yaml-validation/state.ts";
14
import { cleanoutput } from "../smoke/render/render.ts";
15
import { execProcess } from "../../src/core/process.ts";
16
import { quartoDevCmd } from "../utils.ts";
17
import { fail } from "testing/asserts";
18
import { isWindows } from "../../src/deno_ral/platform.ts";
19
import { join, relative } from "../../src/deno_ral/path.ts";
20
import { existsSync } from "../../src/deno_ral/fs.ts";
21
import * as gha from "../../src/tools/github.ts";
22
23
async function fullInit() {
24
await initYamlIntelligenceResourcesFromFilesystem();
25
}
26
27
const globOutput = Deno.args.length
28
? expandGlobSync(Deno.args[0])
29
: expandGlobSync(
30
"docs/playwright/!(serve|shiny)/**/*.qmd",
31
);
32
33
setInitializer(fullInit);
34
await initState();
35
36
// Install multiplex server dependencies if needed
37
const multiplexServerPath = "integration/playwright/multiplex-server";
38
const multiplexNodeModules = join(multiplexServerPath, "node_modules");
39
if (!existsSync(multiplexNodeModules)) {
40
await execProcess({
41
cmd: isWindows ? "npm.cmd" : "npm",
42
args: ["install", "--loglevel=error"],
43
cwd: multiplexServerPath,
44
});
45
console.log("Multiplex server dependencies installed.");
46
}
47
48
// const promises = [];
49
const fileNames: string[] = [];
50
51
// To avoid re-rendering, see QUARTO_PLAYWRIGHT_SKIP_RENDER env var
52
if (Deno.env.get("QUARTO_PLAYWRIGHT_TESTS_SKIP_RENDER") === "true") {
53
console.log("Skipping render of test documents.");
54
} else {
55
const extraOpts = [
56
{
57
pathSuffix: "docs/playwright/embed-resources/issue-11860/main.qmd",
58
options: ["--output-dir=inner"],
59
}
60
]
61
62
for (const { path: fileName } of globOutput) {
63
const input = relative(Deno.cwd(), fileName);
64
const options: string[] = [];
65
for (const extraOpt of extraOpts) {
66
if (fileName.endsWith(extraOpt.pathSuffix)) {
67
options.push(...extraOpt.options);
68
}
69
}
70
71
// sigh, we have a race condition somewhere in
72
// mediabag inspection if we don't wait all renders
73
// individually. This is very slow..
74
console.log(`Rendering ${input}...`);
75
const result = await execProcess({
76
cmd: quartoDevCmd(),
77
args: ["render", input, ...options],
78
stdout: "piped",
79
stderr: "piped",
80
});
81
82
if (!result.success) {
83
gha.error(`Failed to render ${input}`)
84
if (result.stdout) console.log(result.stdout);
85
if (result.stderr) console.error(result.stderr);
86
throw new Error(`Render failed with code ${result.code}`);
87
}
88
89
fileNames.push(fileName);
90
}
91
}
92
93
Deno.test({
94
name: "Playwright tests are passing",
95
// currently we run playwright tests only on Linux
96
ignore: gha.isGitHubActions() && isWindows,
97
fn: async () => {
98
try {
99
// run playwright
100
const res = await execProcess({
101
cmd: isWindows ? "npx.cmd" : "npx",
102
args: ["playwright", "test", "--ignore-snapshots"],
103
cwd: "integration/playwright",
104
},
105
undefined, // stdin
106
undefined, // mergeOutput
107
undefined, // stderrFilter
108
true // respectStreams - write directly to stderr/stdout
109
);
110
if (!res.success) {
111
if (gha.isGitHubActions() && Deno.env.get("GITHUB_REPOSITORY") && Deno.env.get("GITHUB_RUN_ID")) {
112
const runUrl = `https://github.com/${Deno.env.get("GITHUB_REPOSITORY")}/actions/runs/${Deno.env.get("GITHUB_RUN_ID")}`;
113
gha.error(
114
`Some tests failed. Download report uploaded as artifact at ${runUrl}`,
115
{
116
file: "playwright-tests.test.ts",
117
title: "Playwright tests"
118
}
119
);
120
}
121
fail("Failed tests with playwright. Look at playwright report for more details.")
122
}
123
124
} finally {
125
// skip cleanoutput if requested
126
if (Deno.env.get("QUARTO_PLAYWRIGHT_TESTS_SKIP_CLEANOUTPUT") === "true" || Deno.env.get("QUARTO_PLAYWRIGHT_TESTS_SKIP_RENDER") === "true") {
127
console.log("Skipping cleanoutput of test documents.");
128
} else
129
for (const fileName of fileNames) {
130
cleanoutput(fileName, "html");
131
}
132
}
133
}
134
});
135
136