tests: use env file for e2e tests (#2457)
This commit is contained in:
parent
3a3a4a7ae6
commit
44f7dc9ba9
2 changed files with 52 additions and 18 deletions
31
README.md
31
README.md
|
@ -1,6 +1,5 @@
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
<div align="center">
|
<div align="center">
|
||||||
<h1>Saleor Dashboard</h1>
|
<h1>Saleor Dashboard</h1>
|
||||||
</div>
|
</div>
|
||||||
|
@ -54,7 +53,6 @@ $ cd saleor-dashboard
|
||||||
|
|
||||||
Check [release log](https://github.com/saleor/saleor-dashboard/releases/) for the latest release
|
Check [release log](https://github.com/saleor/saleor-dashboard/releases/) for the latest release
|
||||||
|
|
||||||
|
|
||||||
#### Using development version
|
#### Using development version
|
||||||
|
|
||||||
If you want to use the latest development version, checkout to the `main` branch:
|
If you want to use the latest development version, checkout to the `main` branch:
|
||||||
|
@ -71,7 +69,7 @@ $ npm i
|
||||||
|
|
||||||
### Configuration
|
### Configuration
|
||||||
|
|
||||||
Create ```.env``` file in a root directory or set environment variables with following values:
|
Create `.env` file in a root directory or set environment variables with following values:
|
||||||
|
|
||||||
- `API_URI` (required) - URI of a running instance of Saleor GraphQL API.
|
- `API_URI` (required) - URI of a running instance of Saleor GraphQL API.
|
||||||
If you are running Saleor locally with the default settings, set `API_URI` to: `http://localhost:8000/graphql/`.
|
If you are running Saleor locally with the default settings, set `API_URI` to: `http://localhost:8000/graphql/`.
|
||||||
|
@ -90,6 +88,7 @@ To start the development server run:
|
||||||
```
|
```
|
||||||
$ npm start
|
$ npm start
|
||||||
```
|
```
|
||||||
|
|
||||||
In case you see CORS errors make sure to check [CORS configuration](https://docs.saleor.io/docs/3.x/developer/running-saleor/configuration#allowed_client_hosts) of your Saleor instance or CORS settings in the Cloud Console.
|
In case you see CORS errors make sure to check [CORS configuration](https://docs.saleor.io/docs/3.x/developer/running-saleor/configuration#allowed_client_hosts) of your Saleor instance or CORS settings in the Cloud Console.
|
||||||
|
|
||||||
### Production
|
### Production
|
||||||
|
@ -120,6 +119,32 @@ import { CustomAdapter } from "./adapters/";
|
||||||
const errorTracker = ErrorTrackerFactory(CustomAdapter(config));
|
const errorTracker = ErrorTrackerFactory(CustomAdapter(config));
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Running e2e tests
|
||||||
|
|
||||||
|
Add Cypress specific env variables to `.env` file (created in configuration section above):
|
||||||
|
|
||||||
|
```
|
||||||
|
CYPRESS_USER_NAME=
|
||||||
|
CYPRESS_USER_PASSWORD=
|
||||||
|
CYPRESS_SECOND_USER_NAME=
|
||||||
|
CYPRESS_PERMISSIONS_USERS_PASSWORD=
|
||||||
|
|
||||||
|
CYPRESS_mailHogUrl=
|
||||||
|
STRIPE_SECRET_KEY=
|
||||||
|
STRIPE_PUBLIC_KEY=
|
||||||
|
|
||||||
|
// not required
|
||||||
|
CYPRESS_RECORD_KEY= // if you want your local runs recorded
|
||||||
|
```
|
||||||
|
|
||||||
|
For values of those variables refer to our internal documentation.
|
||||||
|
|
||||||
|
You are ready to run cypress commands like:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
npm run cy:open
|
||||||
|
```
|
||||||
|
|
||||||
##### Usage with Sentry adapter:
|
##### Usage with Sentry adapter:
|
||||||
|
|
||||||
Sentry is used as the default tracker so no changes in code are necessary and the configuration is done via environment variables.
|
Sentry is used as the default tracker so no changes in code are necessary and the configuration is done via environment variables.
|
||||||
|
|
|
@ -21,28 +21,31 @@
|
||||||
const graphql = require("graphql-request");
|
const graphql = require("graphql-request");
|
||||||
|
|
||||||
module.exports = async (on, config) => {
|
module.exports = async (on, config) => {
|
||||||
// make env variables visible for cypress
|
|
||||||
// require("cypress-mochawesome-reporter/plugin")(on); - uncomment to run reports
|
// require("cypress-mochawesome-reporter/plugin")(on); - uncomment to run reports
|
||||||
|
|
||||||
|
require("dotenv").config();
|
||||||
|
|
||||||
config.env.API_URI = process.env.API_URI;
|
config.env.API_URI = process.env.API_URI;
|
||||||
config.env.APP_MOUNT_URI = process.env.APP_MOUNT_URI;
|
config.env.APP_MOUNT_URI = process.env.APP_MOUNT_URI;
|
||||||
config.env.SHOP = await getShopInfo(process.env);
|
config.env.SHOP = await getShopInfo(process.env);
|
||||||
config.env.STRIPE_SECRET_KEY = process.env.STRIPE_SECRET_KEY;
|
config.env.STRIPE_SECRET_KEY = process.env.STRIPE_SECRET_KEY;
|
||||||
config.env.STRIPE_PUBLIC_KEY = process.env.STRIPE_PUBLIC_KEY;
|
config.env.STRIPE_PUBLIC_KEY = process.env.STRIPE_PUBLIC_KEY;
|
||||||
|
config.env.USER_NAME = process.env.CYPRESS_USER_NAME;
|
||||||
|
config.env.USER_PASSWORD = process.env.CYPRESS_USER_PASSWORD;
|
||||||
|
config.env.SECOND_USER_NAME = process.env.CYPRESS_SECOND_USER_NAME;
|
||||||
|
config.env.PERMISSIONS_USERS_PASSWORD =
|
||||||
|
process.env.CYPRESS_PERMISSIONS_USERS_PASSWORD;
|
||||||
|
config.env.grepTags = process.env.CYPRESS_grepTags;
|
||||||
|
|
||||||
on("before:browser:launch", (browser = {}, launchOptions) => {
|
on("before:browser:launch", ({}, launchOptions) => {
|
||||||
launchOptions.args.push("--proxy-bypass-list=<-loopback>");
|
launchOptions.args.push("--proxy-bypass-list=<-loopback>");
|
||||||
return launchOptions;
|
return launchOptions;
|
||||||
});
|
});
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
};
|
};
|
||||||
|
|
||||||
function getShopInfo(envVariables) {
|
function getShopInfo(envVariables) {
|
||||||
// envVariables.CYPRESS_USER_NAME
|
|
||||||
const variables = {
|
|
||||||
email: envVariables.CYPRESS_USER_NAME,
|
|
||||||
password: envVariables.CYPRESS_USER_PASSWORD,
|
|
||||||
};
|
|
||||||
|
|
||||||
const createTokenMutation = graphql.gql`mutation tokenCreate($email: String!, $password: String!){
|
const createTokenMutation = graphql.gql`mutation tokenCreate($email: String!, $password: String!){
|
||||||
tokenCreate(email:$email, password:$password){
|
tokenCreate(email:$email, password:$password){
|
||||||
token
|
token
|
||||||
|
@ -58,11 +61,17 @@ function getShopInfo(envVariables) {
|
||||||
const client = new graphql.GraphQLClient(envVariables.API_URI, {
|
const client = new graphql.GraphQLClient(envVariables.API_URI, {
|
||||||
headers: {},
|
headers: {},
|
||||||
});
|
});
|
||||||
return client.request(createTokenMutation, variables).then(data => {
|
|
||||||
const token = data.tokenCreate.token;
|
return client
|
||||||
client.setHeader("Authorization", `JWT ${token}`);
|
.request(createTokenMutation, {
|
||||||
return client
|
email: envVariables.CYPRESS_USER_NAME,
|
||||||
.request(getShopInfoQuery)
|
password: envVariables.CYPRESS_USER_PASSWORD,
|
||||||
.then(shopInfo => shopInfo.shop.version);
|
})
|
||||||
});
|
.then(data => {
|
||||||
|
const token = data.tokenCreate.token;
|
||||||
|
client.setHeader("Authorization", `JWT ${token}`);
|
||||||
|
return client
|
||||||
|
.request(getShopInfoQuery)
|
||||||
|
.then(shopInfo => shopInfo.shop.version);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue