2022-06-13 10:08:13 +00:00
|
|
|
import { defineConfig } from "cypress";
|
2022-07-23 15:21:16 +00:00
|
|
|
import { deleteAsync } from "del";
|
2022-07-12 09:46:48 +00:00
|
|
|
import path from "node:path";
|
|
|
|
import { build, InlineConfig } from "vite";
|
2022-06-13 10:08:13 +00:00
|
|
|
|
|
|
|
export default defineConfig({
|
|
|
|
projectId: "j4yhox",
|
|
|
|
screenshotsFolder: "assets/screenshots",
|
|
|
|
videosFolder: "assets/videos",
|
|
|
|
chromeWebSecurity: false,
|
|
|
|
viewportWidth: 1360,
|
|
|
|
viewportHeight: 768,
|
|
|
|
defaultCommandTimeout: 30000,
|
|
|
|
videoCompression: false,
|
|
|
|
numTestsKeptInMemory: 30,
|
|
|
|
videoUploadOnPasses: false,
|
|
|
|
retries: {
|
|
|
|
runMode: 3,
|
|
|
|
},
|
|
|
|
e2e: {
|
|
|
|
setupNodeEvents(on) {
|
2022-07-12 09:46:48 +00:00
|
|
|
on("file:preprocessor", vitePreprocessor);
|
2022-06-13 10:08:13 +00:00
|
|
|
on("after:spec", async (spec, results) => {
|
|
|
|
if (!results.video) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do we have failures for any retry attempts?
|
|
|
|
const failures = results.tests.some(({ attempts }) =>
|
|
|
|
attempts.some(({ state }) => state === "failed")
|
|
|
|
);
|
|
|
|
|
|
|
|
// Delete the video if the spec passed and no tests were retried.
|
|
|
|
if (!failures) {
|
2022-07-23 15:21:16 +00:00
|
|
|
await deleteAsync(results.video);
|
2022-06-13 10:08:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
baseUrl: "http://localhost:8080",
|
|
|
|
slowTestThreshold: 30000,
|
|
|
|
specPattern: "cypress/e2e/**/*.{js,jsx,ts,tsx}",
|
|
|
|
},
|
|
|
|
});
|
2022-07-12 09:46:48 +00:00
|
|
|
|
|
|
|
const cache: Record<string, string> = {};
|
|
|
|
|
|
|
|
// See https://adamlynch.com/preprocess-cypress-tests-with-vite/
|
|
|
|
async function vitePreprocessor(file: Cypress.FileObject) {
|
|
|
|
const { filePath, outputPath, shouldWatch } = file;
|
|
|
|
|
|
|
|
if (cache[filePath]) {
|
|
|
|
return cache[filePath];
|
|
|
|
}
|
|
|
|
|
|
|
|
const filename = path.basename(outputPath);
|
|
|
|
const filenameWithoutExtension = path.basename(
|
|
|
|
outputPath,
|
|
|
|
path.extname(outputPath)
|
|
|
|
);
|
|
|
|
|
|
|
|
const viteConfig: InlineConfig = {
|
|
|
|
build: {
|
|
|
|
emptyOutDir: false,
|
|
|
|
minify: false,
|
|
|
|
outDir: path.dirname(outputPath),
|
|
|
|
sourcemap: true,
|
|
|
|
write: true,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
if (filename.endsWith(".html")) {
|
|
|
|
viteConfig.build!.rollupOptions = {
|
|
|
|
input: {
|
|
|
|
[filenameWithoutExtension]: filePath,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
viteConfig.build!.lib = {
|
|
|
|
entry: filePath,
|
|
|
|
fileName: () => filename,
|
|
|
|
formats: ["es"],
|
|
|
|
name: filenameWithoutExtension,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shouldWatch) {
|
|
|
|
// @ts-ignore
|
|
|
|
viteConfig.build.watch = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
const watcher = await build(viteConfig);
|
|
|
|
|
|
|
|
if ("on" in watcher) {
|
|
|
|
watcher.on("event", (event) => {
|
|
|
|
if (event.code === "END") {
|
|
|
|
file.emit("rerun");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
file.on("close", () => {
|
|
|
|
delete cache[filePath];
|
|
|
|
watcher.close();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return (cache[filePath] = outputPath);
|
|
|
|
}
|