-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcypress.config.js
More file actions
110 lines (94 loc) · 4.3 KB
/
cypress.config.js
File metadata and controls
110 lines (94 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// See here for the documentation on configuring Cypress:
// https://docs.cypress.io/guides/references/configuration
/* eslint-disable import/no-extraneous-dependencies */
const { defineConfig } = require("cypress");
const { existsSync } = require("fs");
const path = require("path");
const util = require("util");
const execFile = util.promisify(require("child_process").execFile);
const tmp = require("tmp");
const prettier = require("prettier");
const vnu = require("vnu-jar");
// This is the default timeout for DOM-based commands. Any time a test queries for something
// in the DOM, Cypress will wait this number of milliseconds before timing out.
// If these tests are being run on the autograder, wait a longer amount of time, since the
// autograder is slow.
const defaultCommandTimeout = existsSync("/home/autograder/working_dir")
? 8000
: 4000;
// Configure the tmp module to gracefully remove temporary files and directories when the
// process exits.
tmp.setGracefulCleanup();
// Wrapping the config object in defineConfig helps code editors with automatic code completion.
module.exports = defineConfig({
// Set the default command timeout value based on whether the machine running tests is
// the autograder or not.
defaultCommandTimeout,
// Set the folders that Cypress uses to store fixtures, screenshots, videos, and downloads
fixturesFolder: "tests/cypress/fixtures",
screenshotsFolder: "tests/cypress/screenshots",
videosFolder: "tests/cypress/videos",
downloadsFolder: "tests/cypress/downloads",
// Enable video recordings when tests are run in headless mode.
video: true,
// Configure end-to-end tests.
e2e: {
// The baseUrl is used as a global prefix for the cy.request() and cy.visit() commands.
// This way, cy.visit("/") will navigate to http://localhost:8000/.
baseUrl: "http://localhost:8000/",
// Set the patterns that Cypress uses to identify the support file and spec files.
supportFile: "tests/cypress/support/e2e.{js,jsx,ts,tsx}",
specPattern: "tests/cypress/e2e/**/*.cy.{js,jsx,ts,tsx}",
// setupNodeEvents() allows us to modify Cypress's behavior. It registers listeners on
// different "events" and dynamically modifies this configuration.
setupNodeEvents(on, config) {
// Set up the @cypress/grep plugin. This will modify the config object.
require("@cypress/grep/src/plugin")(config);
// The object methods passed into on("task", {}) are functions we can call using
// cy.task() that execute arbitrary Node.js code.
on("task", {
// When a test runs cy.task("createTmpfile"), create a temporary file and return an object
// with information about it to the test.
createTmpfile() {
return tmp.fileSync();
},
// When a test runs cy.task("prettify", "html_code_here"), autoformat the HTML code and
// return it.
prettify(source) {
return prettier.format(source, { parser: "html" });
},
// Run the Nu Html Checker on an HTML file.
validateHtml(filename) {
return execFile("java", [
"-jar",
vnu,
"--filterpattern",
"^Trailing slash on void elements.*|.*JAVA_TOOL_OPTIONS.*",
filename,
]);
},
// When a test runs cy.task("seedDb"), run `./bin/insta485db` from the directory
// Cypress was initially run in, which should be the solution directory.
seedDb() {
const executable = path.join(process.env.PWD, "bin/insta485db");
return execFile(executable, ["reset"], {
cwd: process.env.PWD,
});
},
});
// Return the new config object so that Cypress knows we dynamically modified the original.
return config;
},
},
// Set environment variables every time Cypress runs.
env: {
// When we use `cypress run` on the CLI, if we filter tests with pattern matching, tell
// Cypress to completely ignore tests that don't match the pattern. By default they
// would appear to be "skipped."
grepOmitFiltered: true,
// When we use `cypress run` on the CLI, if we filter tests with pattern matching, tell
// Cypress to ignore spec files that don't have any tests which match the pattern. By
// default, every spec would execute.
grepFilterSpecs: true,
},
});