Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
#85 - fixed jasmine configuration; Merged latest juggler changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestas-zekas committed Jan 19, 2021
1 parent 2c1ce1f commit 8a4dba6
Show file tree
Hide file tree
Showing 17 changed files with 969 additions and 1,525 deletions.
11 changes: 8 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ module.exports = {
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
"SharedArrayBuffer": "readonly",
"document": "readonly",
"page": true,
"browser": "readonly",
"window": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018,
Expand Down Expand Up @@ -45,8 +49,9 @@ module.exports = {
"always"
],
"space-infix-ops": [
"error",
"error",
{ "int32Hint": false }
]
],
"no-trailing-spaces": 2
}
};
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,75 @@ That should be enough to trick Jest into running your tests always in parallel.
### Running tests sequentially ###
* Use --runInBand cli command if tests need to be executed serially ([Official Jest documentation](https://jestjs.io/docs/en/cli.html))

### Run tests in different projects ###
There is possibility to add several Jest projects ([Official Jest documentation](https://jestjs.io/docs/en/configuration#projects-arraystring--projectconfig)). In case there is need to have E2E tests and Unit tests in one solution, or one project to run tests sequentially and another project to run tests in parallel. This can be helpful for setuping CI/CD.

Example of parallel and sequential projects run:
```jest.config.js``` example:
```javascript
module.exports = {
projects: [
{
displayName: "default-tests",
globalSetup: "./test-environment/setup.js",
globalTeardown: "./test-environment/teardown.js",
testEnvironment: "./test-environment/environment.js",
setupFilesAfterEnv: ["./test-environment/jest.setup.js"],
transformIgnorePatterns: ["node_modules/(?!(test-juggler)/)"],
verbose: true,
testTimeout: 60000
},
{
displayName: "serial-tests",
testMatch: ["**/?(*.)+(serial-test).[jt]s?(x)"],
globalSetup: "./test-environment/setup.js",
globalTeardown: "./test-environment/teardown.js",
testEnvironment: "./test-environment/environment.js",
setupFilesAfterEnv: ["./test-environment/jest.setup.js"],
transformIgnorePatterns: ["node_modules/(?!(test-juggler)/)"],
verbose: true,
testTimeout: 60000
}
],
reporters: ["default", ["jest-junit", { outputDirectory: "junit-report" }]]
};
```

Add several scripts in ```package.json``` file under "scripts":
```javascript
...
"default-tests": "jest --selectProjects default-tests",
"serial-tests": "jest --selectProjects serial-tests --runInBand",
"all-tests": "npm run default-tests && npm run serial-tests",
...
```
Then:
* Type and run ```npm run default-tests``` to run all default tests
* Type and run ```npm run serial-tests``` to run all serial tests
* Type and run ```npm run all-tests``` to run all projects in one batch (serial tests will run sequentially)
* Type and run ```npm run test``` to run all projects in one batch (all tests in parallel)

__Note 1__:
Parallel and sequantial run can be implemented without projects. Add test files matchers in jest scripts.
Example:
```javascript
...
"serial-tests": "jest --testRegex '.*serial-test*' --runInBand",
"all-tests": "npm run test && npm run serial-tests",
...
```
or
```javascript
...
"all-tests": "jest && jest --testRegex '.*serial-test*' --runInBand",
...
```

__Note 2__: When running two scripts at once then latest test run overrides junit report. So user is unable to find information about first run. To resolve this problem and generate unique report after each test run add setting ```uniqueOutputName``` to jest-junit configuration in ```jest.config.js``` file:
```javascript
reporters: ["default", ["jest-junit", { outputDirectory: "junit-report", uniqueOutputName: "true" }]]
```

### Contribution guidelines ###

* Contribution should be done and tested in feature branch
Expand Down
1 change: 0 additions & 1 deletion example/pages/HomePage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*global page*/
import { Element } from "test-juggler";
import TopBar from "../components/TopBar";

Expand Down
1 change: 0 additions & 1 deletion example/tests/VisualRegression.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*global page document*/
import HomePage from "../pages/HomePage";
import FeedbackPage from "../pages/FeedbackPage";
const { toMatchImageSnapshot } = require("jest-image-snapshot");
Expand Down
6 changes: 3 additions & 3 deletions example/tests/apiHelpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe("Helpers", () => {
//Assert
expect(response.status).toEqual(204);
});

it("should issue arbitrary request", async () => {
//Arrange, Act
const response = await apiHelpers.request({
Expand All @@ -73,7 +73,7 @@ describe("Helpers", () => {
//Assert
expect(response.status).toEqual(200);
});

it("should handle bad response", async () => {
//Arrange, Act
const response = await apiHelpers.get("/api/users/23");
Expand Down Expand Up @@ -103,7 +103,7 @@ describe("Helpers", () => {

it("should issue request with basic auth", async () => {
//Arrange
const authedApiHelpers = new ApiHelpers({
const authedApiHelpers = new ApiHelpers({
baseURL: "https://postman-echo.com",
auth: {
username: "postman",
Expand Down
1 change: 0 additions & 1 deletion example/tests/elementActions.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*global page*/
import { Element } from "test-juggler";

describe("Element Actions", () => {
Expand Down
5 changes: 2 additions & 3 deletions example/tests/helpers.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*global page:true browser*/
import { Element, Helpers } from "test-juggler";
const fs = require("fs");

Expand Down Expand Up @@ -78,7 +77,7 @@ describe("Helpers", () => {
//Arrange
const config = require(process.cwd() + "/framework.config");
const newPage = await browser.newPage();

//Act
await Helpers.pageSetup(newPage);

Expand All @@ -103,7 +102,7 @@ describe("Helpers", () => {

//Act
const text = await Helpers.generateRandomText(8, chars);

//Assert
expect(regex.test(text)).toBeTruthy();
expect(text.length).toEqual(8);
Expand Down
1 change: 0 additions & 1 deletion example/tests/interceptor.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*global page:true browser*/
import { Element, Helpers, Interceptor } from "test-juggler";

const DemoGuruSite = "http://demo.guru99.com/test/radio.html";
Expand Down
8 changes: 4 additions & 4 deletions example/tests/pageObjectModel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ describe("Example", () => {
await HomePage.visit();
console.log("Running test: " + jasmine["currentTest"].fullName);
});

it("should access methods defined in pages and components", async () => {
await expect(HomePage.isNavbarDisplayed()).resolves.toBeTruthy();
await expect(HomePage.TopBar.isTopBarDisplayed()).resolves.toBeTruthy();
});

it("should access an element defined in component defined in page", async () => {
await HomePage.TopBar.LogoButton.waitUntilVisible();
await HomePage.TopBar.LogoButton.waitUntilVisible();
await expect(HomePage.TopBar.LogoButton.exists()).resolves.toBeTruthy();
});

it("should access an element defined directly in page", async () => {
await HomePage.FeedBackLink.click();
console.log("Clicked on feedback link");
Expand Down
1 change: 0 additions & 1 deletion framework/Element.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*global page document window*/
import Helpers from "./helpers";

const config = require(process.cwd() + "/framework.config");
Expand Down
1 change: 0 additions & 1 deletion framework/helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*global page*/
const fs = require("fs");
const retry = require("async-retry");
const config = require(process.cwd() + "/framework.config");
Expand Down
1 change: 0 additions & 1 deletion framework/interceptor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*global page*/
const fs = require("fs");

class Interceptor {
Expand Down
7 changes: 4 additions & 3 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ module.exports = {
//globalTeardown: "./test-environment/teardown.js",
testEnvironment: "./test-environment/environment.js",
preset: "jest-playwright-preset",
//setupFilesAfterEnv: ["./test-environment/jest.setup.js"],
setupFilesAfterEnv: ["./test-environment/jest.setup.js"],
transformIgnorePatterns: ["node_modules/(?!(test-juggler)/)"],
verbose: true,
"reporters": [
reporters: [
"default",
["jest-junit", { outputDirectory: "junit-report" }]
],
testRunner: "jasmine2",
testTimeout: 60000
};
};
Loading

0 comments on commit 8a4dba6

Please sign in to comment.