Merge pull request #8960 from umbraco/v8/feature/configure-cypress-through-nodejs-install

create enviroment configuration through install script
This commit is contained in:
Bjarke Berg
2020-09-28 11:01:56 +02:00
committed by GitHub
5 changed files with 110 additions and 35 deletions

View File

@@ -1,34 +1,36 @@
# Umbraco Acceptance Tests
### Prerequisites
- NodeJS 12+
- A running installed Umbraco on url: [https://localhost:44331](https://localhost:44331) (Default development port)
- Install using a `SqlServer`/`LocalDb` as the tests execute too fast for `SqlCE` to handle.
- User information in `cypress.env.json` (See [Getting started](#getting-started))
### Getting started
The tests are located in the project/folder as `Umbraco.Tests.AcceptanceTests`. Make sure you run `npm install` in that folder, or let your IDE do that.
Next, it is important that you create a new file in the root of the project called `cypress.env.json`.
This file is already added to `.gitignore` and can contain values that are different for each developer machine.
The file needs the following content:
```
{
"username": "<email for superadmin>",
"password": "<password for superadmin>"
}
```
Replace the `<email for superadmin>` and `<password for superadmin>` placeholders with correct info.
### Executing tests
There are two npm scripts that can be used to execute the test:
1. `npm run test`
- Executes the tests headless.
1. `npm run ui`
- Executes the tests in a browser handled by a cypress application.
In case of errors it is recommended to use the UI to debug.
# Umbraco Acceptance Tests
### Prerequisites
- NodeJS 12+
- A running installed Umbraco on url: [https://localhost:44331](https://localhost:44331) (Default development port)
- Install using a `SqlServer`/`LocalDb` as the tests execute too fast for `SqlCE` to handle.
### Getting started
The tests are located in the project/folder as `Umbraco.Tests.AcceptanceTests`. Make sure you run `npm install` in that folder, or let your IDE do that.
The script will ask you to enter the username and password for a superadmin user of your Umbraco CMS.
### Executing tests
There are two npm scripts that can be used to execute the test:
1. `npm run test`
- Executes the tests headless.
1. `npm run ui`
- Executes the tests in a browser handled by a cypress application.
In case of errors it is recommended to use the UI to debug.
### Enviroment Configuration
The enviroment configuration is begin setup by the npm installation script.
This results in the creation of this file: `cypress.env.json`.
This file is already added to `.gitignore` and can contain values that are different for each developer machine.
The file has the following content:
```
{
"username": "<email for superadmin>",
"password": "<password for superadmin>"
}
```
You can change this if you like or run the config script to reset the values, type "npm run config" in your terminal.

View File

@@ -0,0 +1,49 @@
const prompt = require('prompt');
const fs = require('fs');
const properties = [
{
description: 'Enter your superadmin username/email',
name: 'username',
required: true
},
{
description: 'Enter your superadmin password',
name: 'password',
hidden: true,
required: true
},
{
description: 'Enter CMS URL, or leave empty for default(https://localhost:44331)',
name: 'baseUrl'
}
];
const configPath = './cypress.env.json'
console.log("Configure your test enviroment")
prompt.start();
prompt.get(properties, function (error, result) {
if (error) { return onError(error); }
var fileContent = `{
"username": "${result.username}",
"password": "${result.password}"${
result.baseUrl && `,
"baseUrl": "${result.baseUrl}"`
}
}`;
fs.writeFile(configPath, fileContent, function (error) {
if (error) return console.error(error);
console.log('Configuration saved');
});
});
function onError(error) {
console.error(error);
return true;
}

View File

@@ -18,4 +18,11 @@
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
const baseUrl = config.env.baseUrl || null;
if (baseUrl) {
config.baseUrl = baseUrl;
}
return config;
}

View File

@@ -1,5 +1,7 @@
{
"scripts": {
"postinstall": "node postinstall.js",
"config": "node config.js",
"test": "npx cypress run",
"ui": "npx cypress open"
},
@@ -7,7 +9,8 @@
"cross-env": "^7.0.2",
"cypress": "^5.1.0",
"ncp": "^2.0.0",
"umbraco-cypress-testhelpers": "^1.0.0-beta-50"
"umbraco-cypress-testhelpers": "^1.0.0-beta-50",
"prompt": "^1.0.0"
},
"dependencies": {
"typescript": "^3.9.2"

View File

@@ -0,0 +1,14 @@
const fs = require('fs');
const configPath = './cypress.env.json';
try {
if (fs.existsSync(configPath)) {
//file exists
console.log("Skips configuration as file already exists, run 'npm run config' to change your configuration.");
} else {
require('./config.js');
}
} catch(err) {
console.error(err)
}