Skip to content

Commit

Permalink
Merge pull request #1 from ksocha/add-basic-implementation
Browse files Browse the repository at this point in the history
Add basic implementation
  • Loading branch information
ksocha authored Mar 2, 2020
2 parents 1348cab + fcf805f commit 0f5738c
Show file tree
Hide file tree
Showing 25 changed files with 1,263 additions and 146 deletions.
90 changes: 80 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,96 @@
version: 2.1

jobs:
build:
executors:
node:
working_directory: ~/app
docker:
- image: circleci/node:12
- image: circleci/node:12.16
node_cypress:
working_directory: ~/app
parallelism: 1
docker:
- image: cypress/base:12.16.0

jobs:
checkout_code:
executor: node
steps:
- checkout
- persist_to_workspace:
root: ~/
paths:
- app

install_dependencies:
executor: node
steps:
- attach_workspace:
at: ~/
- restore_cache:
keys:
- v1-deps-{{ .Branch }}-{{ checksum "yarn.lock" }}
- v1-deps-{{ .Branch }}
- v1-deps
- v2-deps-{{ .Branch }}-{{ checksum "yarn.lock" }}
- v2-deps-{{ .Branch }}
- v2-deps
- run: yarn install --frozen-lockfile
- save_cache:
key: v1-deps-{{ .Branch }}-{{ checksum "yarn.lock" }}
key: v2-deps-{{ .Branch }}-{{ checksum "yarn.lock" }}
paths:
- ~/.cache
- persist_to_workspace:
root: ~/
paths:
- .cache
- app/node_modules

run_linter:
executor: node
steps:
- attach_workspace:
at: ~/
- run:
name: Running linter
name: Run linter
command: yarn lint

run_unit_tests:
executor: node
steps:
- attach_workspace:
at: ~/
- run:
name: Running unit tests
name: Run unit tests
command: yarn test

run_cypress_tests:
executor: node_cypress
parallelism: 3
steps:
- attach_workspace:
at: ~/
- run:
name: Build app
command: yarn build
- run:
name: Run cypress tests
command: |
yarn cypress run --reporter "./dist/index.js" --spec "$(circleci tests glob "./cypress/integration/**/*.spec.js" | circleci tests split --split-by=timings | paste -sd "," -)"
- store_test_results:
path: test_results
- store_artifacts:
path: test_results

workflows:
version: 2
build:
jobs:
- checkout_code
- install_dependencies:
requires:
- checkout_code
- run_linter:
requires:
- install_dependencies
- run_unit_tests:
requires:
- run_linter
# - run_cypress_tests:
# requires:
# - run_unit_tests
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,9 @@ dist
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test
.vscode-test

test_results

cypress/screenshots
cypress/videos
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,47 @@
# cypress-circleci-reporter
Cypress test reporter for CircleCI

Cypress test reporter for CircleCI based on [mocha-junit-reporter](https://github.com/michaelleeallen/mocha-junit-reporter). Helps with test parallelization.

## Installation

```shell
$ npm install cypress-circleci-reporter --save-dev
```

```shell
$ yarn add cypress-circleci-reporter --dev
```

## Usage

After installing the reporter, you'll need to modify your config to use it:

### CircleCI config example

```
run_cypress_tests:
parallelism: 3 # or any other number that suits your needs
steps:
# some previous steps
- run:
name: Run cypress tests
command: yarn cypress run --spec "$(circleci tests glob "./cypress/integration/**/*.spec.js" | circleci tests split --split-by=timings | paste -sd "," -)" --reporter cypress-circleci-reporter
- store_test_results:
path: test_results
- store_artifacts:
path: test_results
```

First test run with this config should create and store reports for each test file. These will be used during next runs to determine timings of each test. CircleCI will then split the test files between available containers to speed up the process.

### Configuration options

Options can be passed to the reported by adding `--reporter-options` parameter to the CLI command.

| Parameter | Default | Effect |
| -------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| project | `undefined` | If you use Cypress' `project` parameter, this should be set to the same value. |
| resultsDir | `./test_results/cypress` | Name of the directory that reports will be saved into. report |
| resultFileName | `cypress-[hash]` | Name of the file that will be created for each test run. Must include `[hash]` string as each spec file is processed completely separately during each `cypress run` execution. |
1 change: 1 addition & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
15 changes: 15 additions & 0 deletions cypress/integration/examples/test1.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// <reference types="cypress" />

context('test1', () => {
it('waits for 1s', () => {
cy.wait(1000);
});

it.skip('should be skipped', () => {
cy.wait(1000);
});

it('should fail', () => {
cy.click();
});
});
7 changes: 7 additions & 0 deletions cypress/integration/examples/test2.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// <reference types="cypress" />

context('test2', () => {
it('waits for 2s', () => {
cy.wait(2000);
});
});
7 changes: 7 additions & 0 deletions cypress/integration/examples/test3.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// <reference types="cypress" />

context('test3', () => {
it('waits for 3s', () => {
cy.wait(3000);
});
});
7 changes: 7 additions & 0 deletions cypress/integration/examples/test4.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// <reference types="cypress" />

context('test4', () => {
it('waits for 4s', () => {
cy.wait(4000);
});
});
7 changes: 7 additions & 0 deletions cypress/integration/examples/test5.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// <reference types="cypress" />

context('test5', () => {
it('waits for 5s', () => {
cy.wait(5000);
});
});
7 changes: 7 additions & 0 deletions cypress/integration/examples/test6.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// <reference types="cypress" />

context('test6', () => {
it('waits for 6s', () => {
cy.wait(6000);
});
});
7 changes: 7 additions & 0 deletions cypress/integration/examples/test7.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// <reference types="cypress" />

context('test7', () => {
it('waits for 7s', () => {
cy.wait(7000);
});
});
7 changes: 7 additions & 0 deletions cypress/integration/examples/test8.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// <reference types="cypress" />

context('test8', () => {
it('waits for 8s', () => {
cy.wait(8000);
});
});
7 changes: 7 additions & 0 deletions cypress/integration/examples/test9.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/// <reference types="cypress" />

context('test9', () => {
it('waits for 9s', () => {
cy.wait(9000);
});
});
21 changes: 21 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
25 changes: 25 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
34 changes: 16 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"keywords": [
"circleci",
"reporter",
"cypress"
"cypress",
"parallelization",
"testing"
],
"bugs": {
"url": "https://github.com/ksocha/cypress-circleci-reporter/issues"
Expand All @@ -22,11 +24,12 @@
"dist"
],
"scripts": {
"start": "tsdx watch",
"build": "tsdx build",
"start": "tsdx watch --target node",
"build": "tsdx build --target node",
"test": "tsdx test",
"lint": "tsdx lint",
"prepare": "tsdx build"
"prepare": "tsdx build --target node",
"cypress": "cypress"
},
"husky": {
"hooks": {
Expand All @@ -41,25 +44,20 @@
},
"module": "dist/cypress-circleci-reporter.esm.js",
"devDependencies": {
"@types/jest": "^25.1.1",
"@types/md5": "^2.1.33",
"@types/mkdirp": "^0.5.2",
"@types/jest": "^25.1.3",
"@types/mocha": "^7.0.1",
"@types/xml": "^1.0.4",
"husky": "^4.2.1",
"mocha": "^7.0.1",
"cypress": "^4.0.2",
"husky": "^4.2.3",
"jest-date-mock": "^1.0.8",
"jest-xml-matcher": "^1.2.0",
"tsdx": "^0.12.3",
"tslib": "^1.10.0",
"typescript": "^3.7.5"
"tslib": "^1.11.1",
"typescript": "^3.8.3"
},
"dependencies": {
"md5": "^2.2.1",
"mkdirp": "^1.0.3",
"mocha": "^7.1.0",
"strip-ansi": "^6.0.0",
"xml": "^1.0.1",
"xmlbuilder": "^13.0.2"
},
"peerDependencies": {
"mocha": ">=7.0.0"
"xmlbuilder2": "^1.4.2"
}
}
Loading

0 comments on commit 0f5738c

Please sign in to comment.