Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: [NO-JIRA] update lib to latest from upstream #2

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* text=auto

*.* text eol=lf
57 changes: 30 additions & 27 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: ci
on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
workflow_dispatch:
permissions:
actions: none
checks: none
Expand All @@ -19,28 +19,31 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v2
with:
node-version: '14.20'
- name: Checkout
uses: actions/checkout@v2
- name: Prepare demo-app
run: |
cd pizza-demo
npm ci
- name: Prepare lib
run: |
cd lib
npm ci
- name: Prepare root
run: |
npm ci
- name: Execute tests with defaults
run: |
npm run serve-and-test:parallel
- name: Execute tests with spec reporter
run: |
npm run serve-and-test:parallel:spec
- name: Execute tests with junit reporter
run: |
npm run serve-and-test:parallel:junit
- uses: actions/setup-node@v2
with:
node-version: '20.14'
- name: Checkout
uses: actions/checkout@v2
- name: Prepare demo-app
run: |
cd pizza-demo
npm ci
- name: Prepare lib
run: |
cd lib
npm ci
- name: Prepare root
run: |
npm ci
- name: Execute tests with defaults
run: |
npm run serve-and-test:parallel
- name: Execute only some tests
run: |
npm run serve-and-test:parallel:some
- name: Execute tests with spec reporter
run: |
npm run serve-and-test:parallel:spec
- name: Execute tests with junit reporter
run: |
npm run serve-and-test:parallel:junit
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ vendor/*-manifest.json

# Docs
gh-pages
#others
demo-app/db.json
demo-app/reporting/*
cypress/parallel-weights.json
cypress/screenshots/*
runner-results/
multi-reporter-config.json
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Nicola Tommasi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
50 changes: 34 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

Reduce up to 40% your Cypress suite execution time parallelizing the test run on the same machine.

| cypress | cypress-parallel |
| cypress | cypress-parallel-openx |
| :-----------------------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------: |
| ![cy-serial-small](https://user-images.githubusercontent.com/38537547/114301114-92600a80-9ac3-11eb-9166-e95ae9cd5178.gif) | ![cy-parallel_small](https://user-images.githubusercontent.com/38537547/114301127-9db33600-9ac3-11eb-9bfc-c2096023bba7.gif) |

Expand All @@ -22,25 +22,25 @@ Reduce up to 40% your Cypress suite execution time parallelizing the test run on

## Install

```
npm i cypress-parallel
```sh
npm i cypress-parallel-openx -D
```

or

```
yarn add cypress-parallel
yarn add cypress-parallel-openx -D
```

## Add a new script

In your `package.json` add a new script:

```typescript
```json
"scripts" :{
...
"cy:run": "cypress run", // It can be any cypress command with any argument
"cy:parallel" : "cypress-parallel -s cy:run -t 2 -d <your-cypress-specs-folder> -a '\"<your-cypress-cmd-args>\"'"
"cy:parallel" : "cypress-parallel-openx -s cy:run -t 2 -d '<your-cypress-specs-folder>' -a '\"<your-cypress-cmd-args>\"'"
...
}
```
Expand All @@ -49,34 +49,41 @@ In your `package.json` add a new script:

Sample:

```
```sh
-a '\"--config baseUrl=http://localhost:3000\"'
```

## Launch the new script

```
```sh
npm run cy:parallel
```

or
or

Run with npx (no package installation needed)

```sh
npx cy:parallel -s cy:run -t 2 -d '<your-cypress-specs-folder>' -a '"<your-cypress-cmd-args>"'
```
npx cy:parallel -s cy:run -t 2 -d <your-cypress-specs-folder> -a '\"<your-cypress-cmd-args>\"'

## Passing Specs

```sh
cypress-parallel-openx -s cy:run -t 2 -a '\"<your-cypress-cmd-args>\"' --spec path/to/spec1.spec.js path/to/spec2.spec.js
```

### Scripts options

| Option | Alias | Description | Type |
|----------------------|-------|---------------------------------------------|---------|
| -------------------- | ----- | ------------------------------------------- | ------- |
| --help | | Show help | |
| --version | | Show version number | |
| --script | -s | Your npm Cypress command | string |
| --args | -a | Your npm Cypress command arguments | string |
| --threads | -t | Number of threads | number |
| --specsDir | -d | Cypress specs directory | string |
| --spec | | Cypress spec file paths | string |
| --weightsJson | -w | Parallel weights json file | string |
| --reporter | -r | Reporter to pass to Cypress. | string |
| --reporterOptions | -o | Reporter options | string |
Expand All @@ -88,28 +95,39 @@ npx cy:parallel -s cy:run -t 2 -d <your-cypress-specs-folder> -a '\"<your-cypres

**NB**: If you use *cypress-cucumber-preprocesor*, please **disable** the *strictMode* to avoid possible errors:

```typescript
```json
"scripts" :{
...
"cy:parallel" : "cypress-parallel -s cy:run -t 4 -m false"
"cy:parallel" : "cypress-parallel-openx -s cy:run -t 4 -m false"
...
}
```

**NB**: If your *cypress-multi-reporters* module is not found on the same level as your Cypress suite (e.g. in a mono-repo) then you can specify the module directory for Cypress to search within.

```typescript
```json
"scripts" :{
...
"cy:parallel" : "cypress-parallel -s cy:run -t 4 -n .../../../node_modules/cypress-multi-reporters"
"cy:parallel" : "cypress-parallel-openx -s cy:run -t 4 -n .../../../node_modules/cypress-multi-reporters"
...
}
```

## Env variables

### CYPRESS_THREAD

You can get the current thread index by reading the `CYPRESS_THREAD` variable.

```javascript
const threadIndex = process.env.CYPRESS_THREAD;
// return 1, 2, 3, 4, ...
```

# Contributors

Looking for contributors.

# License

MIT
This project is licensed under the MIT license. See [LICENSE](LICENSE).
13 changes: 13 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { defineConfig } = require('cypress')

module.exports = defineConfig({
video: false,
e2e: {
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
return require('./cypress/plugins/index.js')(on, config)
},
baseUrl: 'http://localhost:3000',
},
})
3 changes: 3 additions & 0 deletions cypress/e2e/1/[foo].cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
describe('Spec filename contains glob characters', () => {
it('should run', () => { cy.wrap(true).should('eq', true) })
})
35 changes: 35 additions & 0 deletions cypress/e2e/1/delete-pizza.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
describe('Delete pizza', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need all that example tests?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used for local test validation of cypress plugin. It is not supposed to be included in the published distribution of the package.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, but if we decide to keep tests then we need to setup ci/cd for it and also add tests for customisation

beforeEach(() => {

cy.fixture('pizzas').then((pizzas) => {
cy.intercept({
method: 'DELETE',
url: '/api/pizzas/*'
}, pizzas).as('deletePizza');

cy.intercept({
method: 'GET',
url: '/api/pizzas'
}, pizzas).as('getPizzas');
});
cy.fixture('addTopping').as('addToppingAPI');

cy.visit('');
});

it('should delete a pizza', () => {
cy.wait(5000);

cy.get('.pizza-item')
.contains(`Seaside Surfin'`)
.within(() => {
cy.get('.btn.btn__ok').click();
});

cy.get('.btn.btn__warning')
.contains('Delete Pizza')
.click();

cy.wait('@deletePizza').its('response.statusCode').should('eq', 200)
});
});
97 changes: 97 additions & 0 deletions cypress/e2e/1/modify-pizza.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
describe('Modify pizza', () => {
beforeEach(() => {
cy.fixture('pizzas').then((pizzas) => {
cy.intercept({
method: 'GET',
url: '/api/pizzas'}, pizzas).as('getPizzas');
});

cy.fixture('addTopping').as('addToppingAPI');

cy.intercept({
method: 'PUT',
url: '/api/pizzas/*'
}).as('addTopping');

cy.visit('');
});

it('should remove a topping', () => {
cy.wait(5000);

cy.get('.pizza-item')
.contains(`Seaside Surfin'`)
.within(() => {
cy.get('.btn.btn__ok').click();
});
cy.get('.pizza-toppings-item')
.contains('bacon')
.click();
cy.get('.btn.btn__ok')
.contains('Save changes')
.click();

cy.wait('@addTopping')
.its('request.body')
.then(res => {
expect(res.toppings).to.deep.equal([
{ id: 6, name: 'mushroom' },
{ id: 7, name: 'olive' },
{ id: 3, name: 'basil' },
{ id: 1, name: 'anchovy' },
{ id: 8, name: 'onion' },
{ id: 11, name: 'sweetcorn' },
{ id: 9, name: 'pepper' },
{ id: 5, name: 'mozzarella' }
]);
});
});

it('should add a topping', () => {
cy.get('.pizza-item')
.contains(`Plain Ol' Pepperoni`)
.within(() => {
cy.get('.btn.btn__ok').click();
});
cy.get('.pizza-toppings-item')
.contains('mushroom')
.click();
cy.get('.btn.btn__ok')
.contains('Save changes')
.click();

cy.wait('@addTopping')
.its('request.body')
.then(res => {
expect(res.toppings).to.deep.equal([
{ id: 10, name: 'pepperoni' },
{ id: 6, name: 'mushroom' }
]);
});
});

it('can remove and add the same topping', () => {
cy.get('.pizza-item')
.contains(`Plain Ol' Pepperoni`)
.within(() => {
cy.get('.btn.btn__ok').click();
});
cy.get('.pizza-toppings-item')
.contains('pepperoni')
.click();
cy.get('.pizza-toppings-item')
.contains('pepperoni')
.click();
cy.get('.btn.btn__ok')
.contains('Save changes')
.click();

cy.wait('@addTopping')
.its('response.body')
.then(res => {
expect(res.toppings).to.deep.equal([
{ id: 10, name: 'pepperoni' },
]);
});
});
});
Loading
Loading