-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
cypress.config.ts
132 lines (118 loc) · 3.98 KB
/
cypress.config.ts
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import path from "path";
import _ from "lodash";
import axios from "axios";
import dotenv from "dotenv";
import Promise from "bluebird";
import codeCoverageTask from "@cypress/code-coverage/task";
import { devServer } from "@cypress/vite-dev-server";
import { defineConfig } from "cypress";
import { mergeConfig, loadEnv } from "vite";
dotenv.config({ path: ".env.local" });
dotenv.config();
let awsConfig = {
default: undefined,
};
try {
awsConfig = require(path.join(__dirname, "./aws-exports-es5.js"));
} catch (e) {}
module.exports = defineConfig({
projectId: "7s5okt",
retries: {
runMode: 2,
},
env: {
apiUrl: "http://localhost:3001",
mobileViewportWidthBreakpoint: 414,
coverage: false,
codeCoverage: {
url: "http://localhost:3001/__coverage__",
exclude: "cypress/**/*.*",
},
defaultPassword: process.env.SEED_DEFAULT_USER_PASSWORD,
paginationPageSize: process.env.PAGINATION_PAGE_SIZE,
// Auth0
auth0_username: process.env.AUTH0_USERNAME,
auth0_password: process.env.AUTH0_PASSWORD,
auth0_domain: process.env.VITE_AUTH0_DOMAIN,
// Okta
okta_username: process.env.OKTA_USERNAME,
okta_password: process.env.OKTA_PASSWORD,
okta_domain: process.env.VITE_OKTA_DOMAIN,
okta_client_id: process.env.VITE_OKTA_CLIENTID,
okta_programmatic_login: process.env.OKTA_PROGRAMMATIC_LOGIN || false,
// Amazon Cognito
cognito_username: process.env.AWS_COGNITO_USERNAME,
cognito_password: process.env.AWS_COGNITO_PASSWORD,
cognito_domain: process.env.AWS_COGNITO_DOMAIN,
cognito_programmatic_login: false,
awsConfig: awsConfig.default,
// Google
googleRefreshToken: process.env.GOOGLE_REFRESH_TOKEN,
googleClientId: process.env.VITE_GOOGLE_CLIENTID,
googleClientSecret: process.env.VITE_GOOGLE_CLIENT_SECRET,
},
component: {
devServer(devServerConfig) {
const viteConfig = require("./vite.config.ts");
const conf = {
define: {
"process.env": loadEnv("development", process.cwd(), "VITE"),
},
server: {
/**
* start the CT dev server on a different port than the full RWA
* so users can switch between CT and E2E testing without having to
* stop/start the RWA dev server.
*/
port: 3002,
},
};
const resolvedViteConfig = mergeConfig(viteConfig, conf);
return devServer({
...devServerConfig,
framework: "react",
viteConfig: resolvedViteConfig,
});
},
specPattern: "src/**/*.cy.{js,jsx,ts,tsx}",
supportFile: "cypress/support/component.ts",
setupNodeEvents(on, config) {
codeCoverageTask(on, config);
return config;
},
},
e2e: {
baseUrl: "http://localhost:3000",
specPattern: "cypress/tests/**/*.spec.{js,jsx,ts,tsx}",
supportFile: "cypress/support/e2e.ts",
viewportHeight: 1000,
viewportWidth: 1280,
experimentalRunAllSpecs: true,
setupNodeEvents(on, config) {
const testDataApiEndpoint = `${config.env.apiUrl}/testData`;
const queryDatabase = ({ entity, query }, callback) => {
const fetchData = async (attrs) => {
const { data } = await axios.get(`${testDataApiEndpoint}/${entity}`);
return callback(data, attrs);
};
return Array.isArray(query) ? Promise.map(query, fetchData) : fetchData(query);
};
on("task", {
async "db:seed"() {
// seed database with test data
const { data } = await axios.post(`${testDataApiEndpoint}/seed`);
return data;
},
// fetch test data from a database (MySQL, PostgreSQL, etc...)
"filter:database"(queryPayload) {
return queryDatabase(queryPayload, (data, attrs) => _.filter(data.results, attrs));
},
"find:database"(queryPayload) {
return queryDatabase(queryPayload, (data, attrs) => _.find(data.results, attrs));
},
});
codeCoverageTask(on, config);
return config;
},
},
});