Skip to content

Commit aed8148

Browse files
committed
Initial commit
1 parent 269a0e5 commit aed8148

18 files changed

+3225
-1
lines changed

.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true

.env

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Project-based Percy tokens
2+
ATLANTIC_BT=web_7af2c478b20f981e6605b7c311391a61dd3d3d77f4e9db5fb9e42fc7654fc461
3+
RED_HAT=web_10b725cfd38fa4ef2089ace87d0d4f7e52d04220b94f9f4e6091fd00c5328950
4+
TRAINING_INDUSTRY=web_f4c9b86cf84361f4bd2de925638fb3ea85624ff5d95c264676255bf1e0f50ecd
5+
6+
# Where you're running the tests from
7+
PERCY_BRANCH=local

.gitignore

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
## Custom
2+
*.sublime-*
3+
.vagrant/
4+
.vscode/
5+
_design/
6+
# /dev/
7+
# /dist/
8+
docs/
9+
images/
10+
img/
11+
public/
12+
temp/
13+
video/
14+
/index.html
15+
16+
17+
## NodeJS
18+
*.log
19+
*.pid
20+
*.seed
21+
.lock-wscript
22+
build/Release
23+
coverage
24+
lib-cov
25+
logs
26+
node_modules
27+
npm-debug.log
28+
pids
29+
30+
31+
## Bower
32+
bower
33+
bower_components
34+
35+
36+
## CSS/Sass
37+
*.css.map
38+
.sass-cache
39+
40+
41+
## macOS
42+
._*
43+
.apdisk
44+
.AppleDB
45+
.AppleDesktop
46+
.AppleDouble
47+
.DS_Store
48+
.LSOverride
49+
.Spotlight-V100
50+
.Trashes
51+
Icon
52+
Network Trash Folder
53+
Temporary Items
54+
55+
56+
## Windows
57+
*.cab
58+
*.msi
59+
*.msm
60+
*.msp
61+
*.lnk
62+
$RECYCLE.BIN/
63+
Desktop.ini
64+
ehthumbs.db
65+
Thumbs.db

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v20.4.0

.prettierrc.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"tabWidth": 4,
3+
"trailingComma": "none"
4+
}

README.md

+110-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,110 @@
1-
# percypress
1+
```
2+
________ ___ ___ ___ ___ _________ ___ ___ ___ _________ ___ _______ ________
3+
|\ ___ \ |\ \ / /| |\ \|\ \|\___ ___\\ \|\ \ |\ \|\___ ___\\ \|\ ___ \ |\ ____\
4+
\ \ \_|\ \ \ \ \/ / / \ \ \\\ \|___ \ \_\ \ \ \ \ \ \ \|___ \ \_\ \ \ \ \__/ | \ \___|_
5+
\ \ \ \\ \ \ \ / / \ \ \\\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \_\ \ \_____ \
6+
\ \ \_\\ \ / \/ \ \ \\\ \ \ \ \ \ \ \ \ \____\ \ \ \ \ \ \ \ \ \ \_/\ \|____|\ \
7+
\ \_______\/ /\ \ \ \_______\ \ \__\ \ \__\ \_______\ \__\ \ \__\ \ \__\ \______\ ____\_\ \
8+
\|_______/__/ /\ __\ \|_______| \|__| \|__|\|_______|\|__| \|__| \|__|\|_______|\_________\
9+
|__|/ \|__| \|_________|
10+
```
11+
12+
[[_TOC_]]
13+
14+
# 🧳 Introduction
15+
16+
Insert description here.
17+
18+
# 🛠 Installation
19+
20+
## Current versions
21+
22+
- **NVM:** _0.39.3_
23+
- **Node:** _20.4.0_
24+
- **NPM:** _9.7.2_
25+
26+
## Clone the repository
27+
28+
```bash
29+
30+
```
31+
32+
## Install Node Version Manager ([NVM](https://github.com/nvm-sh/nvm#about))
33+
34+
```bash
35+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh
36+
```
37+
38+
- `nvm` allows the installation and use of different versions of Node, via the command line.
39+
40+
## Install [Node](https://nodejs.org/en/about)
41+
42+
First, navigate to the repo's root directory.
43+
44+
```bash
45+
cd path/to/repo
46+
```
47+
48+
Then, install Node.
49+
50+
```bash
51+
nvm install
52+
```
53+
54+
- Uses the version of Node that's specified in the `.nvmrc` file.
55+
56+
## Install [dependencies](https://docs.npmjs.com/about-packages-and-modules)
57+
58+
```bash
59+
npm ci
60+
```
61+
62+
- [`ci`](https://blog.npmjs.org/post/171556855892/introducing-npm-ci-for-faster-more-reliable) stands for clean install, and is used to install exact versions of all dependencies from a `package-lock.json` file.
63+
- `npm i` (or `npm install`) is used to install all dependencies from a `package.json` file.
64+
65+
# 👟 Commands
66+
67+
## Run a project's tests
68+
69+
```bash
70+
npm test -- project-name
71+
```
72+
73+
---
74+
75+
- Insert description here.
76+
77+
# 🗒 Notes
78+
79+
## `.env`
80+
81+
- A collection of environment variables that are used by Percy.
82+
- When setting up a new project of tests, add the associated Percy token to this file.
83+
- Ensure that the token name matches the project name, to avoid errors.
84+
- The difference between hyphens and underscores for spacing in the project name is handled dynamically.
85+
- Refer to the chart below, for proper naming.
86+
87+
| | Project | Token |
88+
|-----------|----------------|----------------|
89+
| Correct | `project-name` | `PROJECT_NAME` |
90+
| Correct | `project_name` | `PROJECT_NAME` |
91+
| Correct | `projectname` | `PROJECTNAME` |
92+
| Correct | `pn` | `PN` |
93+
| Incorrect | `projectname` | `PROJECT_NAME` |
94+
| Incorrect | `projectname` | `PROJECT_NAME` |
95+
| Incorrect | `project` | `NAME` |
96+
| Incorrect | `pn` | `PROJECTNAME` |
97+
98+
99+
## `cypress.config.js`
100+
101+
- The configuration file for Cypress that allows you to customize various settings and behaviors for your test suite.
102+
- For more information, refer to the [Cypress configuration documentation](https://docs.cypress.io/guides/references/configuration).
103+
104+
## `cypress.js`
105+
106+
- The file for Cypress that dynamically sets environment variables and executes tests based on the provided project name.
107+
108+
# 🔗 Additional links
109+
110+
1. [Run `nvm use` automatically every time there's a `.nvmrc` file in the directory](https://stackoverflow.com/questions/23556330/run-nvm-use-automatically-every-time-theres-a-nvmrc-file-on-the-directory)

cypress.config.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
e2e: {
3+
specPattern: `tests/${process.env.CYPRESS_SPEC_FOLDER}/*.spec.js`
4+
},
5+
video: false,
6+
viewportWidth: 1280,
7+
viewportHeight: 720
8+
};

cypress.js

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { execSync } from "child_process";
2+
import chalk from "chalk";
3+
import fs from "fs";
4+
5+
// Parse the command-line arguments to find the project name
6+
const args = process.argv.slice(2);
7+
8+
// Grab the first argument after "npm test --", used as the project name
9+
const projectName = args[0];
10+
11+
// If no project name is provided, exit with an error
12+
if (!projectName) {
13+
console.error(
14+
chalk.red(
15+
"Error: No " +
16+
chalk.blue("project-name") +
17+
" provided." +
18+
"\n" +
19+
"Please add a valid project name to the command."
20+
) + chalk.blue(" npm test -- project-name")
21+
);
22+
23+
process.exit(1);
24+
}
25+
26+
// Load the environment variables from the .env file
27+
const dotenvPath = `${process.cwd()}/.env`;
28+
29+
try {
30+
const envConfig = fs.readFileSync(dotenvPath);
31+
const envVars = envConfig.toString().split("\n");
32+
33+
envVars.forEach((envVar) => {
34+
const [key, value] = envVar.split("=");
35+
36+
if (key && value) {
37+
process.env[key] = value;
38+
}
39+
});
40+
} catch (err) {
41+
// If the .env file fails to be read, exit with an error message
42+
console.error(err.message);
43+
process.exit(1);
44+
}
45+
46+
// Load the Percy token from the environment variables based on the project name
47+
const percyToken =
48+
process.env[`${projectName.replace(/[-_]/g, "_").toUpperCase()}`];
49+
50+
// If no Percy token is found, exit with an error
51+
if (!percyToken) {
52+
console.error(
53+
chalk.red(
54+
"Error: No Percy token found for " +
55+
chalk.blue(`${projectName}`) +
56+
"." +
57+
"\n" +
58+
"Please check the project name's spelling, or add a new token to the " +
59+
chalk.blue(".env") +
60+
chalk.red(" file.")
61+
)
62+
);
63+
64+
process.exit(1);
65+
}
66+
67+
try {
68+
// Dynamically set the appropriate PERCY_TOKEN environment variable
69+
process.env.PERCY_TOKEN = percyToken;
70+
71+
// Run the Cypress tests using the custom project name
72+
execSync(
73+
`percy exec -- cross-env CYPRESS_SPEC_FOLDER=${projectName} cypress run`,
74+
{
75+
stdio: "inherit"
76+
}
77+
);
78+
} catch (err) {
79+
// If the tests fail, exit with an error message
80+
console.error(err.message);
81+
process.exit(1);
82+
}

cypress/fixtures/example.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "[email protected]",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}

cypress/support/commands.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// ***********************************************
2+
// This example commands.js shows you how to
3+
// create various custom commands and overwrite
4+
// existing commands.
5+
//
6+
// For more comprehensive examples of custom
7+
// commands please read more here:
8+
// https://on.cypress.io/custom-commands
9+
// ***********************************************
10+
//
11+
//
12+
// -- This is a parent command --
13+
// Cypress.Commands.add('login', (email, password) => { ... })
14+
//
15+
//
16+
// -- This is a child command --
17+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
18+
//
19+
//
20+
// -- This is a dual command --
21+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
22+
//
23+
//
24+
// -- This will overwrite an existing command --
25+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
26+
27+
import "@percy/cypress";

cypress/support/e2e.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ***********************************************************
2+
// This example support/e2e.js is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import "./commands";
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')

0 commit comments

Comments
 (0)